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

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-04-04 08:37:43 +00:00
var fs = require('fs');
var config = require('./../config');
exports.index = function(req, res){
var path = config.path + '/mpmissions';
fs.readdir(path, function (err, files) {
if (err) {
res.send(err);
} else {
2014-04-04 09:28:33 +00:00
var missions = files.map(function (filename) {
2015-08-15 15:12:50 +00:00
return {
name: filename,
};
2014-04-04 09:28:33 +00:00
});
res.send(missions);
2014-04-04 08:37:43 +00:00
}
});
};
exports.create = function(req, res){
2014-04-04 09:28:33 +00:00
var missionFile = req.files.mission;
2014-04-05 17:02:17 +00:00
2014-04-04 09:28:33 +00:00
fs.readFile(missionFile.path, function (err, data) {
2014-04-05 19:37:53 +00:00
var newPath = config.path + '/mpmissions/' + missionFile.name.toLowerCase();
2014-04-04 09:28:33 +00:00
fs.writeFile(newPath, data, function (err) {
res.json(missionFile);
});
});
2014-04-04 08:37:43 +00:00
};
exports.show = function(req, res){
2014-04-05 19:27:54 +00:00
var path = config.path + '/mpmissions/' + req.params.mission;
if (req.params.format) {
path += '.' + req.params.format;
}
res.download(path);
2014-04-04 08:37:43 +00:00
};
exports.destroy = function(req, res){
2014-04-05 17:02:17 +00:00
var path = config.path + '/mpmissions/' + req.params.mission;
if (req.params.format) {
path += '.' + req.params.format;
}
fs.unlink(path, function (err) {
if (err) {
res.json(500, {success: false});
} else {
res.json({success: true});
}
});
};