mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
#146 - Fix issue of build & Add local File upload support
This commit is contained in:
@@ -24,3 +24,4 @@ yarn-debug.log*
|
||||
yarn-error.log*
|
||||
apps/OpenSign/public/mfbuild/*
|
||||
microfrontends/SignDocuments/build/*
|
||||
apps/OpenSignServer/files/files/*
|
||||
@@ -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
|
||||
@@ -21,5 +21,5 @@ EXPOSE 3000
|
||||
# ENV NODE_ENV production
|
||||
|
||||
# Run the application
|
||||
CMD ["npm", "start"]
|
||||
ENTRYPOINT npm run start-dev
|
||||
|
||||
|
||||
@@ -50,16 +50,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);
|
||||
}
|
||||
// otherwise, return error
|
||||
return cb('Only ' + accepted_extensions.join(', ') + ' files are allowed!');
|
||||
const parseBaseUrl = process.env.REACT_APP_SERVERURL;
|
||||
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");
|
||||
},
|
||||
storage: multerS3({
|
||||
metadata: function (req, file, cb) {
|
||||
cb(null, { fieldName: 'OPENSIGN_METADATA' });
|
||||
},
|
||||
filename: function(req, file, cb) {
|
||||
let filename = file.originalname;
|
||||
let filenam = filename.split('.')[0];
|
||||
let extension = filename.split('.')[1];
|
||||
filenam = filenam + '_' + new Date().toISOString() + '.' + extension;
|
||||
console.log(filenam);
|
||||
cb(null, filenam);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var fileStorage = multerS3({
|
||||
acl: 'public-read',
|
||||
s3,
|
||||
bucket: DO_SPACE,
|
||||
@@ -74,9 +86,20 @@ async function uploadFile(req, res) {
|
||||
filenam = filenam + '_' + new Date().toISOString() + '.' + extension;
|
||||
console.log(filenam);
|
||||
cb(null, filenam);
|
||||
},
|
||||
}),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 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 +116,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);
|
||||
|
||||
Reference in New Issue
Block a user