Preserve original URL if possible
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user