feat: Split v1 and v2 apis
This commit is contained in:
22
v1/src/apps/public/public-load-attachments/services.js
Normal file
22
v1/src/apps/public/public-load-attachments/services.js
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
const { ROOT_PATH, LIB_PATH, MODELS_PATH, API_CONFIG } = process.env;
|
||||
const { downloadFile } = require(`${ROOT_PATH}/${LIB_PATH}/Misc`);
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
|
||||
const s3Bucket = apiConfig.S3.bucket;
|
||||
const s3BucketKey = apiConfig.S3.load_attachments_key;
|
||||
|
||||
const getAttachmentFile = async(req, res) => {
|
||||
try{
|
||||
const attachmentId = req.params.id;
|
||||
const file = await downloadFile( s3Bucket, s3BucketKey, attachmentId );
|
||||
res.attachment( attachmentId );
|
||||
res.setHeader('Content-Type', file.ContentType );
|
||||
res.send( file.Body );
|
||||
}catch( error ){
|
||||
console.error( error );
|
||||
res.status(500).send({ error });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getAttachmentFile };
|
||||
Reference in New Issue
Block a user