mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
upload file only not exists
This commit is contained in:
parent
9286174ec7
commit
7a0b2f3d33
2 changed files with 14 additions and 7 deletions
|
|
@ -158,16 +158,16 @@ export const downloadStringFromBucket = async (
|
|||
filePath: string
|
||||
): Promise<string | null> => {
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue