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/getZLatest/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/getZLatest/index.js')
-rw-r--r-- | api/routes/getZLatest/index.js | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/api/routes/getZLatest/index.js b/api/routes/getZLatest/index.js index 4dc1899..9141a4e 100644 --- a/api/routes/getZLatest/index.js +++ b/api/routes/getZLatest/index.js @@ -1,28 +1,39 @@ const { spawn } = require('child_process'); /* - * Gets the local latest zblock + * Gets the local latest zblock AKA zlatest * * Returns: * - JSON object * { zlatest: "Qm..." } * */ -module.exports = (req, res) => { +function getZLatest(req, res) +{ const command = spawn("ak-get-zlatest"); + var buffer = ""; command.stdout.on("data", data => { - res.send({zlatest:`${data}`}); + buffer += data; }); 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 => { - 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({zlatest:`${buffer}`})); + } else { + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end({"error":"unreachable"}); + } }); -};
\ No newline at end of file +} + +module.exports = getZLatest; |