2017-04-01 09:19:30 +00:00
|
|
|
var express = require('express');
|
|
|
|
|
2015-01-21 03:00:09 +00:00
|
|
|
module.exports = function (modsManager) {
|
2017-04-01 09:19:30 +00:00
|
|
|
var router = express.Router();
|
|
|
|
|
|
|
|
router.get('/', function (req, res) {
|
|
|
|
res.send(modsManager.mods);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/', function (req, res) {
|
|
|
|
modsManager.download(req.body.name);
|
|
|
|
res.status(204);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.put('/:mod', function (req, res) {
|
|
|
|
modsManager.download(req.params.mod);
|
|
|
|
res.status(204);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.delete('/:mod', function (req, res) {
|
|
|
|
modsManager.delete(req.params.mod, function (err) {
|
|
|
|
if (err) {
|
|
|
|
res.status(500).send(err);
|
|
|
|
} else {
|
|
|
|
res.status(204);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/refresh', function (req, res) {
|
|
|
|
modsManager.updateMods();
|
|
|
|
res.status(204);
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/search', function (req, res) {
|
|
|
|
var query = req.body.query || "";
|
|
|
|
modsManager.search(query, function (err, mods) {
|
|
|
|
if (err || !mods) {
|
|
|
|
res.status(500).send(err);
|
|
|
|
} else {
|
|
|
|
res.send(mods);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return router;
|
2014-04-06 01:10:09 +00:00
|
|
|
};
|