diff --git a/packages/api/src/utils/uploads.ts b/packages/api/src/utils/uploads.ts index 2209a9139..e53fe079d 100644 --- a/packages/api/src/utils/uploads.ts +++ b/packages/api/src/utils/uploads.ts @@ -158,16 +158,16 @@ export const downloadStringFromBucket = async ( filePath: string ): Promise => { try { - const bucket = storage.bucket(bucketName) + const file = storage.bucket(bucketName).file(filePath) - const [exists] = await bucket.file(filePath).exists() + const [exists] = await file.exists() if (!exists) { logger.error(`File not found: ${filePath}`) return null } // Download the file contents as a string - const [data] = await bucket.file(filePath).download() + const [data] = await file.download() return data.toString() } catch (error) { logger.info('Error downloading file:', error) diff --git a/packages/content-fetch/src/request_handler.ts b/packages/content-fetch/src/request_handler.ts index 51283e497..706430063 100644 --- a/packages/content-fetch/src/request_handler.ts +++ b/packages/content-fetch/src/request_handler.ts @@ -54,10 +54,17 @@ const storage = process.env.GCS_UPLOAD_SA_KEY_FILE_PATH const bucketName = process.env.GCS_UPLOAD_BUCKET || 'omnivore-files' export const uploadToBucket = async (filename: string, data: string) => { - await storage - .bucket(bucketName) - .file(`originalContent/${filename}`) - .save(data, { public: false, timeout: 30000 }) + const file = storage.bucket(bucketName).file(`originalContent/${filename}`) + + // check if the file already exists + const [exists] = await file.exists() + + if (exists) { + console.log('file already exists', filename) + return + } + + await file.save(data, { public: false, timeout: 30000 }) } const hash = (content: string) =>