2023-08-28 09:13:53 +02:00
|
|
|
import { env } from '@typebot.io/env'
|
2024-09-02 11:23:01 +02:00
|
|
|
import { initClient } from './initClient'
|
2022-06-24 14:06:06 +02:00
|
|
|
|
2023-08-29 10:01:28 +02:00
|
|
|
type Props = {
|
2023-11-20 10:32:38 +01:00
|
|
|
key: string
|
2023-08-29 10:01:28 +02:00
|
|
|
file: Buffer
|
|
|
|
|
mimeType: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const uploadFileToBucket = async ({
|
2023-11-20 10:32:38 +01:00
|
|
|
key,
|
2023-08-29 10:01:28 +02:00
|
|
|
file,
|
|
|
|
|
mimeType,
|
|
|
|
|
}: Props): Promise<string> => {
|
2024-09-02 11:23:01 +02:00
|
|
|
const minioClient = initClient()
|
2022-06-24 14:06:06 +02:00
|
|
|
|
2023-11-20 10:32:38 +01:00
|
|
|
await minioClient.putObject(env.S3_BUCKET, 'public/' + key, file, {
|
2023-08-29 10:01:28 +02:00
|
|
|
'Content-Type': mimeType,
|
2023-11-20 10:32:38 +01:00
|
|
|
'Cache-Control': 'public, max-age=86400',
|
2023-08-29 10:01:28 +02:00
|
|
|
})
|
2022-06-26 18:17:50 +02:00
|
|
|
|
2023-11-20 10:32:38 +01:00
|
|
|
return env.S3_PUBLIC_CUSTOM_DOMAIN
|
|
|
|
|
? `${env.S3_PUBLIC_CUSTOM_DOMAIN}/public/${key}`
|
|
|
|
|
: `http${env.S3_SSL ? 's' : ''}://${env.S3_ENDPOINT}${
|
|
|
|
|
env.S3_PORT ? `:${env.S3_PORT}` : ''
|
|
|
|
|
}/${env.S3_BUCKET}/public/${key}`
|
2022-06-24 14:06:06 +02:00
|
|
|
}
|