This commit is contained in:
Hongbo Wu 2024-05-14 17:23:56 +08:00
parent d796503fec
commit dbd7b7932f
2 changed files with 3 additions and 40 deletions

View file

@ -24,7 +24,7 @@ import { Merge, PickTuple } from '../util'
import { deepDelete, setRecentlySavedItemInRedis } from '../utils/helpers'
import { logger } from '../utils/logger'
import { parseSearchQuery } from '../utils/search'
import { downloadFileFromBucket, uploadToBucket } from '../utils/uploads'
import { downloadFromBucket, uploadToBucket } from '../utils/uploads'
import { HighlightEvent } from './highlights'
import { addLabelsToLibraryItem, LabelEvent } from './labels'
@ -1703,5 +1703,5 @@ export const downloadOriginalContent = async (
userId: string,
libraryItemId: string
) => {
return downloadFileFromBucket(originalContentFilename(userId, libraryItemId))
return downloadFromBucket(originalContentFilename(userId, libraryItemId))
}

View file

@ -154,44 +154,7 @@ export const isFileExists = async (filePath: string): Promise<boolean> => {
return exists
}
export const downloadFromUrl = async (
contentObjUrl: string,
timeout?: number
) => {
// download the content as stream and max 10MB
const response = await axios.get<Buffer>(contentObjUrl, {
responseType: 'stream',
maxContentLength,
timeout,
})
return response.data
}
export const uploadToSignedUrl = async (
uploadSignedUrl: string,
data: Buffer,
contentType: string,
timeout?: number
) => {
// upload the stream to the signed url
await axios.put(uploadSignedUrl, data, {
headers: {
'Content-Type': contentType,
},
maxBodyLength: maxContentLength,
timeout,
})
}
export const isFileExists = async (filePath: string): Promise<boolean> => {
const [exists] = await storage.bucket(bucketName).file(filePath).exists()
return exists
}
export const downloadFileFromBucket = async (
filePath: string
): Promise<Buffer> => {
export const downloadFromBucket = async (filePath: string): Promise<Buffer> => {
const file = storage.bucket(bucketName).file(filePath)
const [exists] = await file.exists()