<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced file visibility options for uploaded files, allowing users to set files as public or private. - Added a new API endpoint for retrieving temporary URLs for files, enhancing file accessibility. - Expanded file upload documentation to include information on file visibility settings. - Updated URL validation to support URLs with port numbers and "http://localhost". - **Enhancements** - Improved media download functionality by replacing the `got` library with a custom `downloadMedia` function. - Enhanced bot flow continuation and session start logic to support a wider range of reply types, including WhatsApp media messages. - **Bug Fixes** - Adjusted file path and URL construction in the `generateUploadUrl` function to correctly reflect file visibility settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
28 lines
708 B
TypeScript
28 lines
708 B
TypeScript
import { env } from '@typebot.io/env'
|
|
import { Client } from 'minio'
|
|
|
|
type Props = {
|
|
key: string
|
|
expires?: number
|
|
}
|
|
export const getFileTempUrl = async ({
|
|
key,
|
|
expires,
|
|
}: Props): 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.presignedGetObject(env.S3_BUCKET, key, expires ?? 3600)
|
|
}
|