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

74 lines
1.7 KiB
JavaScript
Raw Normal View History

var async = require('async')
var express = require('express')
var multer = require('multer')
var path = require('path')
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) {
2018-08-18 11:04:33 +00:00
res.json(missionsManager.missions)
})
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) {
var missions = req.files.filter(function (file) {
return path.extname(file.originalname) === '.pbo'
})
2017-10-01 18:04:13 +00:00
async.parallelLimit(
missions.map(function (missionFile) {
2017-10-01 18:04:13 +00:00
return function (next) {
missionsManager.handleUpload(missionFile, next)
}
}),
8,
function (err) {
if (err) {
res.status(500).send(err)
} else {
2018-12-15 13:27:07 +00:00
res.status(200).json({ success: true })
2017-10-01 18:04:13 +00:00
}
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 {
2018-12-15 13:27:07 +00:00
res.json({ success: true })
}
})
})
2017-04-01 09:19:30 +00:00
2018-08-18 11:04:33 +00:00
router.post('/refresh', function (req, res) {
missionsManager.updateMissions()
res.status(204).send()
})
2017-04-01 09:19:30 +00:00
router.post('/workshop', function (req, res) {
var id = req.body.id
2018-08-18 11:04:33 +00:00
missionsManager.downloadSteamWorkshop(id, function (err) {
2017-04-01 09:19:30 +00:00
if (err) {
res.status(500).send(err)
2017-04-01 09:19:30 +00:00
} else {
2018-12-15 13:27:07 +00:00
res.json({ success: true })
}
})
})
return router
}