🐛 (fileUpload) Fix files deletion on result delete
This commit is contained in:
@ -172,7 +172,7 @@ export const generateUploadUrl = publicProcedure
|
|||||||
filePath,
|
filePath,
|
||||||
maxFileSize:
|
maxFileSize:
|
||||||
fileUploadBlock.options && 'sizeLimit' in fileUploadBlock.options
|
fileUploadBlock.options && 'sizeLimit' in fileUploadBlock.options
|
||||||
? fileUploadBlock.options.sizeLimit
|
? (fileUploadBlock.options.sizeLimit as string)
|
||||||
: env.NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE,
|
: env.NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -22,10 +22,22 @@ export const deleteFilesFromBucket = async ({
|
|||||||
|
|
||||||
const bucket = env.S3_BUCKET
|
const bucket = env.S3_BUCKET
|
||||||
|
|
||||||
return minioClient.removeObjects(
|
const keys = urls.reduce<string[]>(
|
||||||
bucket,
|
(keys, url) => [
|
||||||
urls
|
...keys,
|
||||||
.filter((url) => url.includes(env.S3_ENDPOINT as string))
|
...addKeyIfIncludesPublicCustomDomain(url),
|
||||||
.map((url) => url.split(`/${bucket}/`)[1])
|
...addKeyIfIncludesDefaultEndpoint(url, bucket),
|
||||||
|
],
|
||||||
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return minioClient.removeObjects(bucket, keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addKeyIfIncludesPublicCustomDomain = (url: string) =>
|
||||||
|
env.S3_PUBLIC_CUSTOM_DOMAIN && url.includes(env.S3_PUBLIC_CUSTOM_DOMAIN)
|
||||||
|
? [url.split(env.S3_PUBLIC_CUSTOM_DOMAIN + '/')[1]]
|
||||||
|
: []
|
||||||
|
|
||||||
|
const addKeyIfIncludesDefaultEndpoint = (url: string, bucket: string) =>
|
||||||
|
url.includes(env.S3_ENDPOINT as string) ? [url.split(`/${bucket}/`)[1]] : []
|
||||||
|
Reference in New Issue
Block a user