General code sanity

This commit is contained in:
tgpethan 2020-06-15 12:04:17 +01:00
parent 919bfd9993
commit 4db94ce6c3
1 changed files with 79 additions and 74 deletions

37
EUS.js
View File

@ -36,10 +36,10 @@ if (!fs.existsSync(__dirname + BASE_PATH + "/i")) {
console.log(`[EUS] Made EUS images folder`);
}
// Makes the image-type file
if (fs.existsSync(__dirname + BASE_PATH + "image-type.json")) {
if (!fs.existsSync(__dirname + BASE_PATH + "/image-type.json")) {
// Doesn't exist, create it.
fs.writeFileSync(`${__dirname}${BASE_PATH}/image-type.json`, '{}');
console.log("[EUS] Created image-type File!");
console.log("[EUS] Made EUS image-type File!");
// File has been created, load it.
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
} else {
@ -48,10 +48,10 @@ if (fs.existsSync(__dirname + BASE_PATH + "image-type.json")) {
}
// Makes the config file
if (fs.existsSync(__dirname + BASE_PATH + "config.json")) {
if (!fs.existsSync(__dirname + BASE_PATH + "/config.json")) {
// Config doesn't exist, make it.
fs.writeFileSync(`${__dirname}${BASE_PATH}/config.json`, '{\n\t"baseURL":"http://example.com/",\n\t"acceptedTypes": [\n\t\t".png",\n\t\t".jpg",\n\t\t".jpeg",\n\t\t".gif"\n\t],\n\t"uploadKey": ""\n}');
console.log("[EUS] Created config File!");
console.log("[EUS] Made EUS config File!");
console.log("[EUS] Please edit the EUS Config file before restarting.");
// Config has been made, close framework.
process.exit(0);
@ -93,7 +93,10 @@ function validateConfig(json) {
}
// Check if server needs to be shutdown
if (performShutdownAfterValidation) throw "EUS config properties are missing, refer to docs for more details (https://docs.ethanus.ml)";
if (performShutdownAfterValidation) {
console.error("EUS config properties are missing, refer to docs for more details (https://docs.ethanus.ml)");
process.exit(1);
}
else return true;
}
@ -166,9 +169,7 @@ module.exports = {
// Get time at the start of upload
if (useUploadKey) {
if (eusConfig["uploadKey"] != req.header("key")) return res.end("Incorrect key provided for upload");
}
if (useUploadKey && eusConfig["uploadKey"] != req.header("key")) return res.end("Incorrect key provided for upload");
d = new Date(); startTime = d.getTime();
var fstream;
@ -211,16 +212,18 @@ module.exports = {
}
function handleAPI(req, res) {
// Status check for ESL to make sure EUS is online
if (req.query["stat"] == "get") return res.end('{ "status":1, "version":"'+global.internals.version+'" }');
switch (req.url.split("?")[0]) {
// Status check to see the onlint status of EUS
// Used by ESL to make sure EUS is online
case "/api/get-server-status":
return res.end('{ "status":1, "version":"'+global.internals.version+'" }');
/* Stats api endpoint
Query inputs
f : Values [0,1]
s : Values [0,1]
*/
if (req.url.split("?")[0] == "/api/get-stats") {
case "/api/get-stats":
const filesaa = req.query["f"],
spaceaa = req.query["s"];
let jsonaa = {};
@ -272,15 +275,17 @@ function handleAPI(req, res) {
return res.end(JSON.stringify(jsonaa));
});
}
}
if (filesaa != 1 && spaceaa != 1) return res.end("Please add f and or s to your queries to get the files and space");
break;
// Information API
if (req.url.split("?")[0] == "/api/get-info") {
let jsonaa = {
case "/api/get-info":
let jsona = {
version: global.internals.version,
instance: config["server"]["instance_type"]
};
return res.end(JSON.stringify(jsonaa));
return res.end(JSON.stringify(jsona));
}
}