Add console logging to api endpoints + all endpoints page
This commit is contained in:
parent
cca2ed6991
commit
3ae2a87303
1 changed files with 27 additions and 2 deletions
29
EUS.js
29
EUS.js
|
@ -212,11 +212,14 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAPI(req, res) {
|
function handleAPI(req, res) {
|
||||||
|
d = new Date(); startTime = d.getTime();
|
||||||
let jsonaa = {}, filesaa = 0, spaceaa = 0;
|
let jsonaa = {}, filesaa = 0, spaceaa = 0;
|
||||||
switch (req.url.split("?")[0]) {
|
switch (req.url.split("?")[0]) {
|
||||||
// Status check to see the onlint status of EUS
|
// Status check to see the onlint status of EUS
|
||||||
// Used by ESL to make sure EUS is online
|
// Used by ESL to make sure EUS is online
|
||||||
case "/api/get-server-status":
|
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+'" }');
|
return res.end('{ "status":1, "version":"'+global.internals.version+'" }');
|
||||||
|
|
||||||
/* Stats api endpoint
|
/* Stats api endpoint
|
||||||
|
@ -256,7 +259,11 @@ function handleAPI(req, res) {
|
||||||
jsonaa["files"]["total"] = total;
|
jsonaa["files"]["total"] = total;
|
||||||
|
|
||||||
// If getting the space used on the server isn't required send the json
|
// 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
|
// Getting space is required
|
||||||
|
@ -273,19 +280,37 @@ function handleAPI(req, res) {
|
||||||
sizeOfFolder = (size / 1024 / 1024 / 1024).toFixed(2);
|
sizeOfFolder = (size / 1024 / 1024 / 1024).toFixed(2);
|
||||||
jsonaa["space"]["string"] = `${sizeOfFolder} GB`;
|
jsonaa["space"]["string"] = `${sizeOfFolder} GB`;
|
||||||
// Send the json to the requesting client
|
// 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));
|
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;
|
break;
|
||||||
|
|
||||||
// Information API
|
// Information API
|
||||||
case "/api/get-info":
|
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({
|
return res.end(JSON.stringify({
|
||||||
version: global.internals.version,
|
version: global.internals.version,
|
||||||
instance: config["server"]["instance_type"]
|
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(`
|
||||||
|
<h2>All currently avaliable api endpoints</h2>
|
||||||
|
<a href="/api/get-server-status">/api/get-server-status</a>
|
||||||
|
<a href="/api/get-stats">/api/get-stats</a>
|
||||||
|
<a href="/api/get-info">/api/get-info</a>
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue