diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-17 05:12:50 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-17 05:12:50 +0300 |
commit | 2043e733c9d1a2ad5c9f4a91a422b13656e12f05 (patch) | |
tree | b0719a9ac0c6706a707485871494e4d1ce077ea0 /api/routes/getSLatest/index.js | |
parent | 003fb850f911812538242ef2a2cac0915444f121 (diff) | |
download | arching-kaos-tools-2043e733c9d1a2ad5c9f4a91a422b13656e12f05.tar.gz arching-kaos-tools-2043e733c9d1a2ad5c9f4a91a422b13656e12f05.tar.bz2 arching-kaos-tools-2043e733c9d1a2ad5c9f4a91a422b13656e12f05.zip |
Refactoring
Diffstat (limited to 'api/routes/getSLatest/index.js')
-rw-r--r-- | api/routes/getSLatest/index.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/api/routes/getSLatest/index.js b/api/routes/getSLatest/index.js index 5a31ae7..72005b6 100644 --- a/api/routes/getSLatest/index.js +++ b/api/routes/getSLatest/index.js @@ -1,13 +1,11 @@ const { spawn } = require('child_process'); -const os = require("os"); -const HomeDir = os.userInfo().homedir; /* * Gets the latest SBLOCK from superchain * LOL * sorry I was laughing at the term.. superchain */ -module.exports = (req, res) => { +function getSLatest(req, res) { const command = spawn("ak-schain-latest-cached"); response_string = ""; command.stdout.on("data", data => { @@ -15,15 +13,23 @@ module.exports = (req, res) => { }); command.stderr.on("data", data => { - console.log(`stderr: ${data}`); + console.log(`stderr: ${data}`); }); command.on('error', (error) => { - console.log(`error: ${error.message}`); + console.log(`error: ${error.message}`); }); command.on("close", code => { - res.send(JSON.parse(response_string)); - console.log(`child process exited with code ${code}`); + console.log(`child process exited with code ${code}`); + if (code === 0){ + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end(JSON.stringify(JSON.parse(response_string))); + } else { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end({"error":"unreachable"}); + } }); } + +module.exports = getSLatest; |