diff --git a/.gitignore b/.gitignore index 8e62b9ce7..b6dcebdf3 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ npm-debug.log* yarn-debug.log* yarn-error.log* apps/OpenSign/public/mfbuild/* -microfrontends/SignDocuments/build/* \ No newline at end of file +microfrontends/SignDocuments/build/* +apps/OpenSignServer/files/files/* \ No newline at end of file diff --git a/INSTALLATION.md b/INSTALLATION.md index 6cebe94b8..86a9fb8e6 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -143,5 +143,8 @@ In order to address this, your document storage system must be instructed to acc # Build Local Environment -Below are the steps to follow - +Command to build project - - Execute `make build` + +Command to run project - +- Execute `make run` \ No newline at end of file diff --git a/Makefile b/Makefile index 35fa55901..bf7f219d3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,9 @@ build: + cp .env.local_dev .env + rm -rf apps/OpenSign/public/mfbuild + cd microfrontends/SignDocuments && npm install && npm run build + docker compose up -d + +run: cp .env.local_dev .env docker compose up -d \ No newline at end of file diff --git a/apps/OpenSign/Dockerfile b/apps/OpenSign/Dockerfile index 7d8542bf6..57c815846 100644 --- a/apps/OpenSign/Dockerfile +++ b/apps/OpenSign/Dockerfile @@ -21,5 +21,5 @@ EXPOSE 3000 # ENV NODE_ENV production # Run the application -CMD ["npm", "start"] +ENTRYPOINT npm run start-dev diff --git a/apps/OpenSign/public/mfbuild/.gitkeep b/apps/OpenSign/public/mfbuild/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/OpenSignServer/cloud/customRoute/uploadFile.js b/apps/OpenSignServer/cloud/customRoute/uploadFile.js index 34abc14d0..b0152e1bd 100644 --- a/apps/OpenSignServer/cloud/customRoute/uploadFile.js +++ b/apps/OpenSignServer/cloud/customRoute/uploadFile.js @@ -4,6 +4,12 @@ import multerS3 from 'multer-s3'; import aws from 'aws-sdk'; import dotenv from 'dotenv'; dotenv.config(); + +function sanitizeFileName(fileName) { + // Remove spaces and invalid characters + return fileName.replace(/[^a-zA-Z0-9._-]/g, ''); +} + async function uploadFile(req, res) { try { //--size extended to 100 mb @@ -50,16 +56,28 @@ async function uploadFile(req, res) { region: process.env.DO_REGION, }); - // const s3 = new aws.S3(); - const upload = multer({ - fileFilter: function (req, file, cb) { - if (accepted_extensions.some(ext => file.originalname.toLowerCase().endsWith('.' + ext))) { - return cb(null, true); + const parseBaseUrl = process.env.SERVER_URL; + const parseAppId = process.env.APP_ID; + + if (process.env.USE_LOCAL == "TRUE") { + var fileStorage = multer.diskStorage({ + destination: function(req, file, cb) { + cb(null, "files/files"); + }, + metadata: function (req, file, cb) { + cb(null, { fieldName: 'OPENSIGN_METADATA' }); + }, + filename: function(req, file, cb) { + let filename = file.originalname; + let newFileName = filename.split('.')[0]; + let extension = filename.split('.')[1]; + newFileName = sanitizeFileName(newFileName + '_' + new Date().toISOString() + '.' + extension) + console.log(newFileName); + cb(null, newFileName); } - // otherwise, return error - return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!'); - }, - storage: multerS3({ + }); + } else { + var fileStorage = multerS3({ acl: 'public-read', s3, bucket: DO_SPACE, @@ -69,14 +87,25 @@ async function uploadFile(req, res) { key: function (req, file, cb) { //console.log(file); let filename = file.originalname; - let filenam = filename.split('.')[0]; + let newFileName = filename.split('.')[0]; let extension = filename.split('.')[1]; - filenam = filenam + '_' + new Date().toISOString() + '.' + extension; - console.log(filenam); - cb(null, filenam); - }, - }), + newFileName = sanitizeFileName(newFileName + '_' + new Date().toISOString() + '.' + extension) + console.log(newFileName); + cb(null, newFileName); + } + }); + } + // const s3 = new aws.S3(); + const upload = multer({ + fileFilter: function (req, file, cb) { + if (accepted_extensions.some(ext => file.originalname.toLowerCase().endsWith('.' + ext))) { + return cb(null, true); + } + // otherwise, return error + return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!'); + }, + storage: fileStorage, limits: { fileSize: size }, }).single('file'); @@ -93,7 +122,14 @@ async function uploadFile(req, res) { const status = 'Success'; //res.header("Access-Control-Allow-Headers", "Content-Type"); //res.setHeader("Access-Control-Allow-Origin", "*"); - return res.json({ status, imageUrl: req.file.location }); + if (process.env.USE_LOCAL == "TRUE") { + console.log(req.file); + var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`; + } else { + var fileUrl = req.file.location; + } + + return res.json({ status, imageUrl: fileUrl }); }); } catch (err) { console.log('Exeption in query ' + err.stack);