Preserve original URL if possible

This commit is contained in:
Jackson Harper
2023-10-18 10:23:26 +08:00
parent b6ce4f39b1
commit 4220922ff8
2 changed files with 1 additions and 9 deletions

View File

@ -110,13 +110,9 @@ export const uploadFileRequestResolver = authorized<
input.contentType
)
const publicUrl = getFilePublicUrl(uploadFilePathName)
// If this is a file URL, we swap in the GCS public URL
if (isFileUrl(input.url)) {
await authTrx(async (tx) => {
await tx.getRepository(UploadFile).update(uploadFileId, {
url: publicUrl,
status: UploadFileStatus.Initialized,
})
})
@ -142,7 +138,7 @@ export const uploadFileRequestResolver = authorized<
const uploadFileId = uploadFileData.id
const item = await createLibraryItem(
{
originalUrl: isFileUrl(input.url) ? publicUrl : input.url,
originalUrl: input.url,
id: input.clientRequestId || undefined,
user: { id: uid },
title,

View File

@ -34,10 +34,6 @@ const storage = env.fileUpload?.gcsUploadSAKeyFilePath
: new Storage()
const bucketName = env.fileUpload.gcsUploadBucket
export const getFilePublicUrl = (filePathName: string): string => {
return storage.bucket(bucketName).file(filePathName).publicUrl()
}
export const countOfFilesWithPrefix = async (prefix: string) => {
const [files] = await storage.bucket(bucketName).getFiles({ prefix })
return files.length