From 3ae2a873034924d6b63b96fb81dcf48b87373465 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Mon, 15 Jun 2020 12:46:19 +0100 Subject: [PATCH] Add console logging to api endpoints + all endpoints page --- EUS.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/EUS.js b/EUS.js index 376253c..462105c 100644 --- a/EUS.js +++ b/EUS.js @@ -212,11 +212,14 @@ module.exports = { } function handleAPI(req, res) { + d = new Date(); startTime = d.getTime(); let jsonaa = {}, filesaa = 0, spaceaa = 0; 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": + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); return res.end('{ "status":1, "version":"'+global.internals.version+'" }'); /* Stats api endpoint @@ -256,7 +259,11 @@ function handleAPI(req, res) { jsonaa["files"]["total"] = total; // If getting the space used on the server isn't required send the json - if (spaceaa != 1) return res.end(JSON.stringify(jsonaa)); + if (spaceaa != 1) { + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); + return res.end(JSON.stringify(jsonaa)); + } }); } // Getting space is required @@ -273,19 +280,37 @@ function handleAPI(req, res) { sizeOfFolder = (size / 1024 / 1024 / 1024).toFixed(2); jsonaa["space"]["string"] = `${sizeOfFolder} GB`; // Send the json to the requesting client + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); 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"); + if (filesaa != 1 && spaceaa != 1) { + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); + return res.end("Please add f and or s to your queries to get the files and space"); + } break; // Information API case "/api/get-info": + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); return res.end(JSON.stringify({ version: global.internals.version, instance: config["server"]["instance_type"] })); + + default: + d = new Date(); endTime = d.getTime(); + global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`); + return res.send(` +

All currently avaliable api endpoints

+ /api/get-server-status + /api/get-stats + /api/get-info + `); } }