mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Completed manager and moved client to common folder
This commit is contained in:
@@ -1,58 +1,60 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
module.exports = function (databasesLocation) {
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
router.get('/:type/:name', function (req, res) {
|
||||
console.log(req.params.database)
|
||||
});
|
||||
router.get('/:type/:name', function (req, res) {
|
||||
console.log(req.params.database)
|
||||
});
|
||||
|
||||
router.put('/save/:type/:name', function (req, res) {
|
||||
var dir = path.join("./public/databases", req.params.type, "old");
|
||||
if (!fs.existsSync(dir)){
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
router.put('/save/:type/:name', function (req, res) {
|
||||
var dir = path.join(databasesLocation, req.params.type, "old");
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
|
||||
var filepath = path.join("./public/databases", req.params.type, req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join("./public/databases/", req.params.type, "old", req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
if (fs.existsSync(newFilepath)) {
|
||||
try {
|
||||
var json = JSON.stringify(req.body.blueprints, null, "\t" );
|
||||
fs.writeFileSync(filepath, json, 'utf8');
|
||||
res.send("OK");
|
||||
} catch {
|
||||
var filepath = path.join(databasesLocation, req.params.type, req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join(databasesLocation, req.params.type, "old", req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
if (fs.existsSync(newFilepath)) {
|
||||
try {
|
||||
var json = JSON.stringify(req.body.blueprints, null, "\t");
|
||||
fs.writeFileSync(filepath, json, 'utf8');
|
||||
res.send("OK");
|
||||
} catch {
|
||||
res.status(422).send("Error");
|
||||
}
|
||||
} else {
|
||||
res.status(422).send("Error");
|
||||
}
|
||||
} else {
|
||||
res.status(422).send("Error");
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
} else {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/reset/:type/:name', function (req, res) {
|
||||
var filepath = path.join("./public/databases", req.params.type, "default", req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join("./public/databases", req.params.type, req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
res.send("OK");
|
||||
} else {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
router.put('/reset/:type/:name', function (req, res) {
|
||||
var filepath = path.join(databasesLocation, req.params.type, "default", req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join(databasesLocation, req.params.type, req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
res.send("OK");
|
||||
} else {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/restore/:type/:name', function (req, res) {
|
||||
var filepath = path.join("./public/databases", req.params.type, "old", req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join("./public/databases", req.params.type, req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
res.send("OK");
|
||||
} else {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
router.put('/restore/:type/:name', function (req, res) {
|
||||
var filepath = path.join(databasesLocation, req.params.type, "old", req.params.name + ".json");
|
||||
if (fs.existsSync(filepath)) {
|
||||
var newFilepath = path.join(databasesLocation, req.params.type, req.params.name + ".json");
|
||||
fs.copyFileSync(filepath, newFilepath);
|
||||
res.send("OK");
|
||||
} else {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
return router;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user