2
0
Files
bot/packages/lib/s3/deprecated/generatePresignedUrl.ts
2023-09-21 19:08:43 +02:00

33 lines
833 B
TypeScript

import { env } from '@typebot.io/env'
import { Client } from 'minio'
type GeneratePresignedUrlProps = {
filePath: string
fileType?: string
}
const tenMinutes = 10 * 60
export const generatePresignedUrl = async ({
filePath,
fileType,
}: GeneratePresignedUrlProps): Promise<string> => {
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
throw new Error(
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
)
const minioClient = new Client({
endPoint: env.S3_ENDPOINT,
port: env.S3_PORT,
useSSL: env.S3_SSL,
accessKey: env.S3_ACCESS_KEY,
secretKey: env.S3_SECRET_KEY,
region: env.S3_REGION,
})
return minioClient.presignedUrl('PUT', env.S3_BUCKET, filePath, tenMinutes, {
'Content-Type': fileType,
})
}