ADD: API_URL to env
ADD: DocumentUrls and mainImageUrls field in belonging model FIX: Indexing bugs for belonging ADD: getImage endpoint to get private images ADD: PrivateUrl field as virtual FIX: Minor bug in bucketDeleteFile service ADD: Word type to multer file checker
This commit is contained in:
@@ -52,10 +52,20 @@ const bucketMultiUpload = async (files, bucketName) => {
|
||||
}
|
||||
|
||||
const bucketDeleteFile = async (fileName, bucketName) => {
|
||||
await deleteObject(fileName, bucketName)
|
||||
await deleteFile(fileName)
|
||||
let exportedFileName = getLastUrlSegment(fileName)
|
||||
await deleteObject(exportedFileName, bucketName)
|
||||
await deleteFile(exportedFileName)
|
||||
|
||||
return null
|
||||
return { fileName }
|
||||
}
|
||||
|
||||
const getLastUrlSegment = (url) => {
|
||||
if (!url.includes('/')) {
|
||||
return url
|
||||
}
|
||||
const cleanUrl = url.endsWith('/') ? url.slice(0, -1) : url
|
||||
const segments = cleanUrl.split('/')
|
||||
return segments[segments.length - 1]
|
||||
}
|
||||
|
||||
const getAllFiles = async () => {
|
||||
@@ -100,6 +110,7 @@ const getSignedUrl = async (fileName, bucketName) => {
|
||||
if (!fileName) {
|
||||
return
|
||||
}
|
||||
console.log(bucketName,fileName)
|
||||
return signedUrl(bucketName, fileName)
|
||||
}
|
||||
|
||||
@@ -120,6 +131,39 @@ const moveFromTempToMain = async (files, targetBucket) => {
|
||||
await removeObject(tempBucket, file)
|
||||
}
|
||||
}
|
||||
|
||||
const getImage = async (bucketName, fileName) => {
|
||||
if (!fileName) {
|
||||
throw new AppError('NoFileFound', 404, {})
|
||||
}
|
||||
|
||||
|
||||
// Get signed URL from the file service
|
||||
const signedUrl = await getSignedUrl(fileName, bucketName);
|
||||
|
||||
if (!signedUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Fetch the image from the signed URL
|
||||
const response = await fetch(signedUrl);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new AppError('NoFileFound', 404, {})
|
||||
}
|
||||
|
||||
// Get the content type from the response headers
|
||||
const contentType = response.headers.get('content-type');
|
||||
|
||||
// Convert the response to a buffer
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
// Return both the buffer and content type
|
||||
return {
|
||||
buffer: Buffer.from(buffer),
|
||||
contentType
|
||||
};
|
||||
};
|
||||
module.exports = {
|
||||
moveFromTempToMain,
|
||||
getMultipleSignedUrls,
|
||||
@@ -133,4 +177,5 @@ module.exports = {
|
||||
bucketMultiUpload,
|
||||
bucketDeleteFile,
|
||||
bucketGetFiles,
|
||||
getImage,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user