2017-08-24 09:15:06 +00:00
|
|
|
var express = require('express')
|
2017-04-01 09:19:30 +00:00
|
|
|
|
2015-01-21 03:00:09 +00:00
|
|
|
module.exports = function (modsManager) {
|
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) {
|
2017-08-24 09:15:06 +00:00
|
|
|
res.send(modsManager.mods)
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.post('/', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
modsManager.download(req.body.name)
|
|
|
|
res.status(204)
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.put('/:mod', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
modsManager.download(req.params.mod)
|
|
|
|
res.status(204)
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.delete('/:mod', function (req, res) {
|
|
|
|
modsManager.delete(req.params.mod, 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 {
|
2017-08-24 09:15:06 +00:00
|
|
|
res.status(204)
|
2017-04-01 09:19:30 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.post('/refresh', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
modsManager.updateMods()
|
|
|
|
res.status(204)
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
|
|
|
router.post('/search', function (req, res) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var query = req.body.query || ''
|
2017-04-01 09:19:30 +00:00
|
|
|
modsManager.search(query, function (err, mods) {
|
|
|
|
if (err || !mods) {
|
2017-08-24 09:15:06 +00:00
|
|
|
res.status(500).send(err)
|
2017-04-01 09:19:30 +00:00
|
|
|
} else {
|
2017-08-24 09:15:06 +00:00
|
|
|
res.send(mods)
|
2017-04-01 09:19:30 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
})
|
2017-04-01 09:19:30 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
return router
|
|
|
|
}
|