feat: Moving S3 from AWS to minio
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
"use strict";
|
||||
const { ROOT_PATH, LIB_PATH, MODELS_PATH, API_CONFIG } = process.env;
|
||||
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
const { getPagination , getPage } = require( '../../../lib/Misc' )
|
||||
const { uploadFile } = require('../../../lib/3R/S3')
|
||||
const apiConfig = require( '../../../config/apiConfig.json' )
|
||||
|
||||
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
|
||||
const s3Client = new S3Client({
|
||||
region : apiConfig.S3.region,
|
||||
credentials : {
|
||||
accessKeyId : apiConfig.S3.accessKeyId,
|
||||
secretAccessKey : apiConfig.S3.secretAccessKey
|
||||
}
|
||||
});
|
||||
const s3Bucket = apiConfig.S3.bucket;
|
||||
const s3BucketKey = apiConfig.S3.load_attachments_key;
|
||||
const s3Bucket = apiConfig.S3.bucket
|
||||
const s3BucketKey = apiConfig.S3.load_attachments_key
|
||||
|
||||
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/load-attachments.model.js` );
|
||||
const UserModel = require( `${ROOT_PATH}/${MODELS_PATH}/users.model.js` );
|
||||
const LoadsModel = require( `${ROOT_PATH}/${MODELS_PATH}/loads.model.js` );
|
||||
const Model = require('../../../lib/Models/load-attachments.model')
|
||||
const UserModel = require( '../../../lib/Models/users.model' );
|
||||
const LoadsModel = require( '../../../lib/Models/loads.model' );
|
||||
|
||||
async function getAuthorizationFilter( userId ){
|
||||
const user = await UserModel.findById( userId );
|
||||
@@ -123,22 +115,12 @@ async function createLoadAttachment( type , userId , loadId ){
|
||||
return attachment;
|
||||
}
|
||||
|
||||
async function uploadFile( bucket, key, file , obj_id ){
|
||||
const params = {
|
||||
Bucket: bucket,
|
||||
Key : `${key}/${obj_id}`,
|
||||
ContentType : file.mimetype,
|
||||
Body : file.data
|
||||
};
|
||||
const s3resp = await s3Client.send( new PutObjectCommand( params ) );
|
||||
return s3resp;
|
||||
}
|
||||
const postLoadingAttachment = async(req, res) => {
|
||||
const loadId = req.params.id;
|
||||
const attachment = await createLoadAttachment( "Loading", req.JWT.payload.sub , loadId );
|
||||
const file = req.files.attachment;
|
||||
if( attachment && file ){
|
||||
const s3resp = await uploadFile( s3Bucket, s3BucketKey, file , attachment._id );
|
||||
await uploadFile( s3Bucket, s3BucketKey, attachment._id, file );
|
||||
res.send( attachment );
|
||||
}else if( !file ){
|
||||
res.status(400).send({ error : "attachment file not found" , code: 400 });
|
||||
@@ -152,7 +134,7 @@ const postDownloadingAttachment = async(req, res) => {
|
||||
const attachment = await createLoadAttachment( "Downloading", req.JWT.payload.sub , loadId );
|
||||
const file = req.files.attachment;
|
||||
if( attachment && file ){
|
||||
const s3resp = await uploadFile( s3Bucket, s3BucketKey, file , attachment._id );
|
||||
await uploadFile( s3Bucket, s3BucketKey, attachment._id, file );
|
||||
res.send( attachment );
|
||||
}else if( !file ){
|
||||
res.status(400).send({ error : "attachment file not found" , code: 400 });
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
"use strict";
|
||||
const { API_CONFIG, ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
|
||||
const { getPagination } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
|
||||
const { GenericHandler } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Generic.handler.js` );
|
||||
const { downloadFile } = require(`${ROOT_PATH}/${LIB_PATH}/Misc`);
|
||||
const { getPagination } = require( '../../../lib/Misc' );
|
||||
const { GenericHandler } = require( '../../../lib/Handlers/Generic.handler' );
|
||||
const { downloadFile } = require('../../../lib/3R/S3/index');
|
||||
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
const apiConfig = require( '../../../config/apiConfig.json' );
|
||||
|
||||
const s3Bucket = apiConfig.S3.bucket;
|
||||
const s3BucketKey = apiConfig.S3.news_key;
|
||||
|
||||
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/news.model.js` );
|
||||
const Model = require( '../../../lib/Models/news.model' );
|
||||
const generic = new GenericHandler( Model );
|
||||
|
||||
const getList = async(req, res) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"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 { downloadFile } = require('../../../lib/3R/S3/index');
|
||||
const apiConfig = require('../../../config/apiConfig.json');
|
||||
|
||||
const s3Bucket = apiConfig.S3.bucket;
|
||||
const s3BucketKey = apiConfig.S3.load_attachments_key;
|
||||
|
||||
Reference in New Issue
Block a user