first commit

This commit is contained in:
2025-12-05 06:21:42 +07:00
commit a3c945a60a
119 changed files with 21757 additions and 0 deletions

View File

@ -0,0 +1,79 @@
const multer = require('multer');
const path = require('path');
var imageStorage = multer.diskStorage({
// Destination to store image
// destination: 'assets/images/'+pathDir,
destination: (req, file, cb) => {
// console.log(req.get("path"));
// let pathdir = req.get("path");
cb(null, "assets/po/")
// cb(null, "assets/words/" + pathdir + "/")
},
filename : (req, file, cb) => {
// let filename=file.originalname.split(".")[0];
// console.log("body :"+req.body);
let nik = req.nik;
// let category = req.body.filecategory;
// let filedoc = category+'_'+nik+'_' + Date.now() + path.extname(file.originalname);
let filedoc = nik+'_' + Date.now() + path.extname(file.originalname);
// req.body.filedoc = filedoc;
// cb(null, filedoc);
// console.log(filedoc);
req.body.filename = filedoc;
cb(null, filedoc)
// file.fieldname is name of the field (image)
// path.extname get the uploaded file extension
}
});
var imageUpload = multer({
storage: imageStorage,
limits: {
fileSize: '5mb' // 1000000 Bytes = 5 MB
},
fileFilter(req, file, cb) {
// if (!file.originalname.match(/\.(png|jpg|pdf)$/)) {
// console.log(file.originalname.match);
if (!file.originalname.match(/\.(docx|pdf|PDF)$/)) {
// upload only png and jpg format
req.fileValidationError = "Please upload a word document in ( docx / pdf ) max 5 mb";
cb(new Error('Please upload a word document in ( docx / pdf ) max 5 mb'), false);
}
else{
cb(null, true);
}
}
}).single("file-doc");
module.exports = (req, res, next) => {
try {
imageUpload(req,res, function(err){
try {
// if (err || err instanceof multer.MulterError){
if (err){
res.status(500).send({
"meta":{
"auth": false,
"code" : 500,
"message" : req.fileValidationError || err.toString(),
},
"data" :[]
});
} else {
next();
// console.log('The filename is ' + res.req.file.filename);
}
} catch (error) {
console.log("error "+error);
}
});
} catch (error) {
console.log("error " + error);
error.message = error.message;
error.statusCode = 500;
throw error;
}
}