2018-12-02 21:38:29 +00:00
|
|
|
var async = require('async')
|
2017-08-24 09:15:06 +00:00
|
|
|
var express = require('express')
|
|
|
|
var multer = require('multer')
|
2018-12-02 21:38:29 +00:00
|
|
|
var path = require('path')
|
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
var upload = multer({ storage: multer.diskStorage({}) })
|
2017-04-01 09:19:30 +00:00
|
|
|
|
2016-10-29 14:34:54 +00:00
|
|
|
module.exports = function (missionsManager) {
|
2017-08-24 09:15:06 +00:00
|
|
|
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-08-24 09:15:06 +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) {
|
2018-12-02 21:38:29 +00:00
|
|
|
var missions = req.files.filter(function (file) {
|
|
|
|
return path.extname(file.originalname) === '.pbo'
|
|
|
|
})
|
|
|
|
|
2017-10-01 18:04:13 +00:00
|
|
|
async.parallelLimit(
|
2018-12-02 21:38:29 +00:00
|
|
|
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-08-24 09:15:06 +00:00
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.get('/:mission', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var filename = req.params.mission
|
2017-04-01 09:19:30 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
res.download(missionsManager.missionPath(filename), decodeURI(filename))
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.delete('/:mission', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var filename = req.params.mission
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
missionsManager.delete(filename, function (err) {
|
|
|
|
if (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
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 })
|
2016-10-29 14:34:54 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
})
|
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) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var id = req.body.id
|
2016-10-29 14:34:54 +00:00
|
|
|
|
2018-08-18 11:04:33 +00:00
|
|
|
missionsManager.downloadSteamWorkshop(id, function (err) {
|
2017-04-01 09:19:30 +00:00
|
|
|
if (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
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 })
|
2016-10-29 14:34:54 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
})
|
2016-10-29 14:34:54 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
return router
|
|
|
|
}
|