General code sanity

This commit is contained in:
tgpethan 2020-06-15 12:04:17 +01:00
parent 919bfd9993
commit 4db94ce6c3

37
EUS.js
View file

@ -36,10 +36,10 @@ if (!fs.existsSync(__dirname + BASE_PATH + "/i")) {
console.log(`[EUS] Made EUS images folder`); console.log(`[EUS] Made EUS images folder`);
} }
// Makes the image-type file // 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. // Doesn't exist, create it.
fs.writeFileSync(`${__dirname}${BASE_PATH}/image-type.json`, '{}'); 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. // File has been created, load it.
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`); image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
} else { } else {
@ -48,10 +48,10 @@ if (fs.existsSync(__dirname + BASE_PATH + "image-type.json")) {
} }
// Makes the config file // 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. // 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}'); 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."); console.log("[EUS] Please edit the EUS Config file before restarting.");
// Config has been made, close framework. // Config has been made, close framework.
process.exit(0); process.exit(0);
@ -93,7 +93,10 @@ function validateConfig(json) {
} }
// Check if server needs to be shutdown // 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; else return true;
} }
@ -166,9 +169,7 @@ module.exports = {
// Get time at the start of upload // Get time at the start of upload
if (useUploadKey) { if (useUploadKey && eusConfig["uploadKey"] != req.header("key")) return res.end("Incorrect key provided for upload");
if (eusConfig["uploadKey"] != req.header("key")) return res.end("Incorrect key provided for upload");
}
d = new Date(); startTime = d.getTime(); d = new Date(); startTime = d.getTime();
var fstream; var fstream;
@ -211,16 +212,18 @@ module.exports = {
} }
function handleAPI(req, res) { function handleAPI(req, res) {
switch (req.url.split("?")[0]) {
// Status check for ESL to make sure EUS is online // Status check to see the onlint status of EUS
if (req.query["stat"] == "get") return res.end('{ "status":1, "version":"'+global.internals.version+'" }'); // 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 /* Stats api endpoint
Query inputs Query inputs
f : Values [0,1] f : Values [0,1]
s : Values [0,1] s : Values [0,1]
*/ */
if (req.url.split("?")[0] == "/api/get-stats") { case "/api/get-stats":
const filesaa = req.query["f"], const filesaa = req.query["f"],
spaceaa = req.query["s"]; spaceaa = req.query["s"];
let jsonaa = {}; let jsonaa = {};
@ -272,15 +275,17 @@ function handleAPI(req, res) {
return res.end(JSON.stringify(jsonaa)); 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 // Information API
if (req.url.split("?")[0] == "/api/get-info") { case "/api/get-info":
let jsonaa = { let jsona = {
version: global.internals.version, version: global.internals.version,
instance: config["server"]["instance_type"] instance: config["server"]["instance_type"]
}; };
return res.end(JSON.stringify(jsonaa)); return res.end(JSON.stringify(jsona));
} }
} }