sanitize file uploads to lowercase
This commit is contained in:
parent
aca85d09ac
commit
245fef66a7
1 changed files with 3 additions and 3 deletions
|
@ -6,7 +6,7 @@ let fs = require('fs');
|
|||
|
||||
function extension(str){
|
||||
let file = str.split('/').pop();
|
||||
return [file.substr(0,file.lastIndexOf('.')),file.substr(file.lastIndexOf('.'),file.length)]
|
||||
return [file.substr(0,file.lastIndexOf('.')),file.substr(file.lastIndexOf('.'),file.length).toLowerCase()]
|
||||
}
|
||||
|
||||
const storage = multer.diskStorage({
|
||||
|
@ -15,9 +15,9 @@ const storage = multer.diskStorage({
|
|||
},
|
||||
filename : function(req, file, cb) {
|
||||
db.all('SELECT * FROM media WHERE path = ?', [file.originalname], function (err, exists) {
|
||||
let nameAndExtension = extension(file.originalname);
|
||||
if (exists.length != 0) {
|
||||
let suffix = new Date().getTime() / 1000;
|
||||
let nameAndExtension = extension(file.originalname);
|
||||
|
||||
if (req.body.title == '' || req.body.title == null || req.body.title == undefined)
|
||||
cb(null, nameAndExtension[0] + '-' + suffix + nameAndExtension[1])
|
||||
|
@ -25,7 +25,7 @@ const storage = multer.diskStorage({
|
|||
cb(null, req.body.title + '-' + suffix + nameAndExtension[1])
|
||||
} else {
|
||||
if (req.body.title == '' || req.body.title == null || req.body.title == undefined)
|
||||
cb(null, file.originalname)
|
||||
cb(null, nameAndExtension[0] + nameAndExtension[1])
|
||||
else
|
||||
cb(null, req.body.title + nameAndExtension[1])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue