mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #2959 from omnivore-app/fix/api-attachments
Only use signed URLs for PDF attachments
This commit is contained in:
commit
f8d5e3f261
4 changed files with 9 additions and 35 deletions
|
|
@ -98,10 +98,7 @@ import {
|
|||
parsePreparedContent,
|
||||
} from '../../utils/parser'
|
||||
import { parseSearchQuery, sortParamsToSort } from '../../utils/search'
|
||||
import {
|
||||
getStorageFileDetails,
|
||||
makeStorageFilePublic,
|
||||
} from '../../utils/uploads'
|
||||
import { getStorageFileDetails } from '../../utils/uploads'
|
||||
import { itemTypeForContentType } from '../upload_files'
|
||||
|
||||
export enum ArticleFormat {
|
||||
|
|
@ -310,7 +307,6 @@ export const createArticleResolver = authorized<
|
|||
pubsub
|
||||
)
|
||||
}
|
||||
await makeStorageFilePublic(uploadFileData.id, uploadFileData.fileName)
|
||||
}
|
||||
|
||||
let libraryItemToReturn: LibraryItem
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
contentReaderForLibraryItem,
|
||||
generateUploadFilePathName,
|
||||
generateUploadSignedUrl,
|
||||
getFilePublicUrl,
|
||||
} from '../../utils/uploads'
|
||||
|
||||
const isFileUrl = (url: string): boolean => {
|
||||
|
|
@ -110,13 +109,12 @@ export const uploadFileRequestResolver = authorized<
|
|||
input.contentType
|
||||
)
|
||||
|
||||
const publicUrl = getFilePublicUrl(uploadFilePathName)
|
||||
|
||||
// If this is a file URL, we swap in the GCS public URL
|
||||
// If this is a file URL, we swap in a special URL
|
||||
const attachmentUrl = `https://omnivore.app/attachments/${uploadFilePathName}`
|
||||
if (isFileUrl(input.url)) {
|
||||
await authTrx(async (tx) => {
|
||||
await tx.getRepository(UploadFile).update(uploadFileId, {
|
||||
url: publicUrl,
|
||||
url: attachmentUrl,
|
||||
status: UploadFileStatus.Initialized,
|
||||
})
|
||||
})
|
||||
|
|
@ -142,8 +140,8 @@ export const uploadFileRequestResolver = authorized<
|
|||
const uploadFileId = uploadFileData.id
|
||||
const item = await createLibraryItem(
|
||||
{
|
||||
originalUrl: isFileUrl(input.url) ? publicUrl : input.url,
|
||||
id: input.clientRequestId || undefined,
|
||||
originalUrl: isFileUrl(input.url) ? attachmentUrl : input.url,
|
||||
user: { id: uid },
|
||||
title,
|
||||
readableContent: '',
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import {
|
|||
generateUploadFilePathName,
|
||||
generateUploadSignedUrl,
|
||||
getStorageFileDetails,
|
||||
makeStorageFilePublic,
|
||||
} from '../../utils/uploads'
|
||||
|
||||
export function emailAttachmentRouter() {
|
||||
|
|
@ -143,11 +142,12 @@ export function emailAttachmentRouter() {
|
|||
return res.status(400).send('BAD REQUEST')
|
||||
}
|
||||
|
||||
const uploadFileUrlOverride = await makeStorageFilePublic(
|
||||
uploadFileData.id,
|
||||
uploadFileData.fileName
|
||||
const uploadFilePathName = generateUploadFilePathName(
|
||||
uploadFileId,
|
||||
uploadFile.fileName
|
||||
)
|
||||
|
||||
const uploadFileUrlOverride = `https://omnivore.app/attachments/${uploadFilePathName}`
|
||||
const uploadFileHash = uploadFileDetails.md5Hash
|
||||
const itemType =
|
||||
uploadFile.contentType === 'application/pdf'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -81,22 +77,6 @@ export const generateDownloadSignedUrl = async (
|
|||
return url
|
||||
}
|
||||
|
||||
export const makeStorageFilePublic = async (
|
||||
id: string,
|
||||
fileName: string
|
||||
): Promise<string> => {
|
||||
// if (env.dev.isLocal) {
|
||||
// return 'http://localhost:3000/public/' + id + '/' + fileName
|
||||
// }
|
||||
|
||||
// Makes the file public
|
||||
const filePathName = generateUploadFilePathName(id, fileName)
|
||||
await storage.bucket(bucketName).file(filePathName).makePublic()
|
||||
|
||||
const fileObj = storage.bucket(bucketName).file(filePathName)
|
||||
return fileObj.publicUrl()
|
||||
}
|
||||
|
||||
export const getStorageFileDetails = async (
|
||||
id: string,
|
||||
fileName: string
|
||||
|
|
|
|||
Loading…
Reference in a new issue