Mission Upload broken after Express 4 update

This commit is contained in:
Björn Dahlgren 2017-04-04 23:23:35 +02:00
parent a841ad5027
commit 8f1389464d
3 changed files with 12 additions and 4 deletions

View File

@ -47,7 +47,7 @@ Missions.prototype.list = function (cb){
};
Missions.prototype.handleUpload = function (uploadedFile, cb) {
var filename = decodeURI(uploadedFile.name.toLowerCase());
var filename = decodeURI(uploadedFile.originalname.toLowerCase());
fs.rename(uploadedFile.path, path.join(this.missionsPath(), filename), function (err) {
cb(err);
});

View File

@ -20,6 +20,7 @@
"gamedig": "0.2.25",
"lodash": "^3.6.0",
"morgan": "^1.8.1",
"multer": "^1.3.0",
"playwithsix": "0.0.11",
"serve-static": "^1.12.1",
"slugify": "^1.1.0",

View File

@ -1,4 +1,6 @@
var express = require('express');
var multer = require('multer');
var upload = multer({ storage: multer.diskStorage({}) });
module.exports = function (missionsManager) {
var router = express.Router();
@ -13,13 +15,18 @@ module.exports = function (missionsManager) {
});
});
router.post('/', function (req, res) {
var missionFile = req.files.mission;
router.post('/', upload.single('mission'), function (req, res) {
var missionFile = req.file;
if (!missionFile) {
return res.status(400).send('No mission file uploaded');;
}
missionsManager.handleUpload(missionFile, function (err) {
if (err) {
res.status(500).send(err);
} else {
res.status(204);
res.status(200).json({success: true});
}
});
});