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

66 lines
1.5 KiB
JavaScript
Raw Normal View History

var express = require('express')
var multer = require('multer')
var upload = multer({ storage: multer.diskStorage({}) })
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
router.post('/', upload.single('mission'), function (req, res) {
var missionFile = req.file
if (!missionFile) {
return res.status(400).send('No mission file uploaded')
}
2017-04-01 09:19:30 +00:00
missionsManager.handleUpload(missionFile, function (err) {
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
res.status(200).json({success: true})
2017-04-01 09:19:30 +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
}