mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Preserve original URL if possible
This commit is contained in:
parent
b6ce4f39b1
commit
4220922ff8
2 changed files with 1 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue