Skip to content

Commit c326849

Browse files
authored
Merge pull request #162 from rishabjasrotia/issue/146
2 parents 9b295f7 + a92188d commit c326849

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ npm-debug.log*
2323
yarn-debug.log*
2424
yarn-error.log*
2525
apps/OpenSign/public/mfbuild/*
26-
microfrontends/SignDocuments/build/*
26+
microfrontends/SignDocuments/build/*
27+
apps/OpenSignServer/files/files/*

INSTALLATION.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,8 @@ In order to address this, your document storage system must be instructed to acc
143143

144144
# Build Local Environment
145145

146-
Below are the steps to follow -
146+
Command to build project -
147147
- Execute `make build`
148+
149+
Command to run project -
150+
- Execute `make run`

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
build:
2+
cp .env.local_dev .env
3+
rm -rf apps/OpenSign/public/mfbuild
4+
cd microfrontends/SignDocuments && npm install && npm run build
5+
docker compose up -d
6+
7+
run:
28
cp .env.local_dev .env
39
docker compose up -d

apps/OpenSign/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ EXPOSE 3000
2121
# ENV NODE_ENV production
2222

2323
# Run the application
24-
CMD ["npm", "start"]
24+
ENTRYPOINT npm run start-dev
2525

apps/OpenSign/public/mfbuild/.gitkeep

Whitespace-only changes.

apps/OpenSignServer/cloud/customRoute/uploadFile.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import multerS3 from 'multer-s3';
44
import aws from 'aws-sdk';
55
import dotenv from 'dotenv';
66
dotenv.config();
7+
8+
function sanitizeFileName(fileName) {
9+
// Remove spaces and invalid characters
10+
return fileName.replace(/[^a-zA-Z0-9._-]/g, '');
11+
}
12+
713
async function uploadFile(req, res) {
814
try {
915
//--size extended to 100 mb
@@ -50,16 +56,28 @@ async function uploadFile(req, res) {
5056
region: process.env.DO_REGION,
5157
});
5258

53-
// const s3 = new aws.S3();
54-
const upload = multer({
55-
fileFilter: function (req, file, cb) {
56-
if (accepted_extensions.some(ext => file.originalname.toLowerCase().endsWith('.' + ext))) {
57-
return cb(null, true);
59+
const parseBaseUrl = process.env.SERVER_URL;
60+
const parseAppId = process.env.APP_ID;
61+
62+
if (process.env.USE_LOCAL == "TRUE") {
63+
var fileStorage = multer.diskStorage({
64+
destination: function(req, file, cb) {
65+
cb(null, "files/files");
66+
},
67+
metadata: function (req, file, cb) {
68+
cb(null, { fieldName: 'OPENSIGN_METADATA' });
69+
},
70+
filename: function(req, file, cb) {
71+
let filename = file.originalname;
72+
let newFileName = filename.split('.')[0];
73+
let extension = filename.split('.')[1];
74+
newFileName = sanitizeFileName(newFileName + '_' + new Date().toISOString() + '.' + extension)
75+
console.log(newFileName);
76+
cb(null, newFileName);
5877
}
59-
// otherwise, return error
60-
return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!');
61-
},
62-
storage: multerS3({
78+
});
79+
} else {
80+
var fileStorage = multerS3({
6381
acl: 'public-read',
6482
s3,
6583
bucket: DO_SPACE,
@@ -69,14 +87,25 @@ async function uploadFile(req, res) {
6987
key: function (req, file, cb) {
7088
//console.log(file);
7189
let filename = file.originalname;
72-
let filenam = filename.split('.')[0];
90+
let newFileName = filename.split('.')[0];
7391
let extension = filename.split('.')[1];
74-
filenam = filenam + '_' + new Date().toISOString() + '.' + extension;
75-
console.log(filenam);
76-
cb(null, filenam);
77-
},
78-
}),
92+
newFileName = sanitizeFileName(newFileName + '_' + new Date().toISOString() + '.' + extension)
93+
console.log(newFileName);
94+
cb(null, newFileName);
95+
}
96+
});
97+
}
7998

99+
// const s3 = new aws.S3();
100+
const upload = multer({
101+
fileFilter: function (req, file, cb) {
102+
if (accepted_extensions.some(ext => file.originalname.toLowerCase().endsWith('.' + ext))) {
103+
return cb(null, true);
104+
}
105+
// otherwise, return error
106+
return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!');
107+
},
108+
storage: fileStorage,
80109
limits: { fileSize: size },
81110
}).single('file');
82111

@@ -93,7 +122,14 @@ async function uploadFile(req, res) {
93122
const status = 'Success';
94123
//res.header("Access-Control-Allow-Headers", "Content-Type");
95124
//res.setHeader("Access-Control-Allow-Origin", "*");
96-
return res.json({ status, imageUrl: req.file.location });
125+
if (process.env.USE_LOCAL == "TRUE") {
126+
console.log(req.file);
127+
var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`;
128+
} else {
129+
var fileUrl = req.file.location;
130+
}
131+
132+
return res.json({ status, imageUrl: fileUrl });
97133
});
98134
} catch (err) {
99135
console.log('Exeption in query ' + err.stack);

0 commit comments

Comments
 (0)