feat(bot): ⚡️ Add custom file upload size limit
This commit is contained in:
@ -3,14 +3,16 @@ import { config, Endpoint, S3 } from 'aws-sdk'
|
||||
type GeneratePresignedUrlProps = {
|
||||
filePath: string
|
||||
fileType: string
|
||||
sizeLimit?: number
|
||||
}
|
||||
|
||||
const tenMB = 10485760
|
||||
const tenMB = 10 * 1024 * 1024
|
||||
const oneHundredAndTwentySeconds = 120
|
||||
|
||||
export const generatePresignedUrl = ({
|
||||
filePath,
|
||||
fileType,
|
||||
sizeLimit = tenMB,
|
||||
}: GeneratePresignedUrlProps): S3.PresignedPost => {
|
||||
if (
|
||||
!process.env.S3_ENDPOINT ||
|
||||
@ -45,7 +47,7 @@ export const generatePresignedUrl = ({
|
||||
'Content-Type': fileType,
|
||||
},
|
||||
Expires: oneHundredAndTwentySeconds,
|
||||
Conditions: [['content-length-range', 0, tenMB]],
|
||||
Conditions: [['content-length-range', 0, sizeLimit]],
|
||||
})
|
||||
return presignedUrl
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ export const generateId = (idDesiredLength: number): string => {
|
||||
}
|
||||
|
||||
type UploadFileProps = {
|
||||
basePath?: string
|
||||
files: {
|
||||
file: File
|
||||
path: string
|
||||
@ -202,6 +203,7 @@ type UploadFileProps = {
|
||||
type UrlList = string[]
|
||||
|
||||
export const uploadFiles = async ({
|
||||
basePath = '/api',
|
||||
files,
|
||||
onUploadProgress,
|
||||
}: UploadFileProps): Promise<UrlList> => {
|
||||
@ -209,9 +211,9 @@ export const uploadFiles = async ({
|
||||
const { data } = await sendRequest<{
|
||||
presignedUrl: { url: string; fields: any }
|
||||
}>(
|
||||
`/api/storage/upload-url?filePath=${encodeURIComponent(path)}&fileType=${
|
||||
file.type
|
||||
}`
|
||||
`${basePath}/storage/upload-url?filePath=${encodeURIComponent(
|
||||
path
|
||||
)}&fileType=${file.type}`
|
||||
)
|
||||
|
||||
if (!data?.presignedUrl) return null
|
||||
|
Reference in New Issue
Block a user