Remove preprocess image on upload image or it will losing support of image some formats

This commit is contained in:
Wu Cheng-Han 2016-12-03 14:37:12 +08:00
parent 840cac7435
commit 5958654ea4
2 changed files with 53 additions and 75 deletions

21
app.js
View file

@ -462,29 +462,13 @@ app.post('/uploadimage', function (req, res) {
form.uploadDir = "public/uploads";
}
function preprocessImage(path) {
return new Promise((resolve) => {
var oldFile = `${path}-old`;
fs.rename(path, oldFile, function() {
var sharp = require('sharp');
sharp(oldFile).toFile(path).then(() => {
fs.unlink(oldFile, function() {
resolve(path);
})
});
});
});
}
form.parse(req, function (err, fields, files) {
if (err || !files.image || !files.image.path) {
response.errorForbidden(res);
} else {
preprocessImage(files.image.path).then(() => {
if (config.debug)
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image));
var path = require('path');
try {
switch (config.imageUploadType) {
case 'filesystem':
@ -542,11 +526,6 @@ app.post('/uploadimage', function (req, res) {
logger.error(err);
return res.status(500).end('upload image error');
}
}).catch((err) => {
logger.error(err);
return res.status(500).end('process image error');
});
}
});
});

View file

@ -101,7 +101,6 @@
"scrypt": "^6.0.3",
"select2": "^3.5.2-browserify",
"sequelize-cli": "^2.4.0",
"sharp": "^0.16.2",
"shortid": "2.2.6",
"socket.io": "~1.6.0",
"socket.io-client": "~1.6.0",