arma-server-web-admin/routes/missions.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

var express = require('express')
var multer = require('multer')
var upload = multer({ storage: multer.diskStorage({}) })
2017-10-01 18:04:13 +00:00
var async = require('async')
2017-04-01 09:19:30 +00:00
module.exports = function (missionsManager) {
var router = express.Router()
2017-04-01 09:19:30 +00:00
router.get('/', function (req, res) {
missionsManager.list(function (err, missions) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
res.json(missions)
2017-04-01 09:19:30 +00:00
}
})
})
2017-04-01 09:19:30 +00:00
2017-10-01 18:04:13 +00:00
router.post('/', upload.array('missions', 64), function (req, res) {
async.parallelLimit(
req.files.map(function (missionFile) {
return function (next) {
missionsManager.handleUpload(missionFile, next)
}
}),
8,
function (err) {
if (err) {
res.status(500).send(err)
} else {
res.status(200).json({success: true})
}
2017-04-01 09:19:30 +00:00
}
2017-10-01 18:04:13 +00:00
)
})
2017-04-01 09:19:30 +00:00
router.get('/:mission', function (req, res) {
var filename = req.params.mission
2017-04-01 09:19:30 +00:00
res.download(missionsManager.missionPath(filename), decodeURI(filename))
})
2017-04-01 09:19:30 +00:00
router.delete('/:mission', function (req, res) {
var filename = req.params.mission
2017-04-01 09:19:30 +00:00
missionsManager.delete(filename, function (err) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
res.json({success: true})
}
})
})
2017-04-01 09:19:30 +00:00
router.post('/workshop', function (req, res) {
var id = req.body.id
2017-04-01 09:19:30 +00:00
missionsManager.downloadSteamWorkshop(id, function (err, files) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
res.json({success: true})
}
})
})
return router
}