mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Use the public GCS URL for local uploaded files
This commit is contained in:
parent
ef072cb2c9
commit
e23eada168
2 changed files with 13 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ import { WithDataSourcesContext } from '../types'
|
|||
import {
|
||||
generateUploadSignedUrl,
|
||||
generateUploadFilePathName,
|
||||
getFilePublicUrl,
|
||||
} from '../../utils/uploads'
|
||||
import path from 'path'
|
||||
import normalizeUrl from 'normalize-url'
|
||||
|
|
@ -99,11 +100,12 @@ export const uploadFileRequestResolver: ResolverFn<
|
|||
input.contentType
|
||||
)
|
||||
|
||||
// If this is a file URL, we swap in the GCS signed
|
||||
// URL
|
||||
const publicUrl = getFilePublicUrl(uploadFilePathName)
|
||||
|
||||
// If this is a file URL, we swap in the GCS public URL
|
||||
if (isFileUrl(input.url)) {
|
||||
await models.uploadFile.update(uploadFileData.id, {
|
||||
url: uploadSignedUrl,
|
||||
url: publicUrl,
|
||||
status: UploadFileStatus.Initialized,
|
||||
})
|
||||
}
|
||||
|
|
@ -135,7 +137,7 @@ export const uploadFileRequestResolver: ResolverFn<
|
|||
} else {
|
||||
const pageId = await createPage(
|
||||
{
|
||||
url: isFileUrl(input.url) ? uploadSignedUrl : input.url,
|
||||
url: isFileUrl(input.url) ? publicUrl : input.url,
|
||||
id: input.clientRequestId || '',
|
||||
userId: claims.uid,
|
||||
title: title,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ 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 generateUploadSignedUrl = async (
|
||||
filePathName: string,
|
||||
contentType: string,
|
||||
|
|
|
|||
Loading…
Reference in a new issue