diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2023-08-03 10:43:32 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2023-08-03 10:43:32 +0300 |
commit | 67450601ebcbf4cd31d316e9e9a8a339a0719766 (patch) | |
tree | 2e95802f46c87bd522898f3f8dd5094366d6a348 /api/routes/getZblock/index.js | |
parent | eb83dc73c0f71b2cf3480b17658ef7f21e92e570 (diff) | |
download | arching-kaos-tools-67450601ebcbf4cd31d316e9e9a8a339a0719766.tar.gz arching-kaos-tools-67450601ebcbf4cd31d316e9e9a8a339a0719766.tar.bz2 arching-kaos-tools-67450601ebcbf4cd31d316e9e9a8a339a0719766.zip |
Changed to get params instead of query
Diffstat (limited to 'api/routes/getZblock/index.js')
-rw-r--r-- | api/routes/getZblock/index.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/api/routes/getZblock/index.js b/api/routes/getZblock/index.js index 7787d23..878c240 100644 --- a/api/routes/getZblock/index.js +++ b/api/routes/getZblock/index.js @@ -26,29 +26,32 @@ function fetchZblock(zblock, res){ command.on("close", code => { console.log(`child process exited with code ${code}`); - if ( code == 0 ) { - const path = config.zblockDir+"/"+zblock; + if ( code === 0 ) { + const path = config.cacheDir+"/fzblocks/"+zblock; + console.log(path) try { if(fs.existsSync(path)){ res.send(JSON.parse(fs.readFileSync(path))); } } catch (error) { - res.send({"error":error}); + res.send({"error":error.message}); } + } else if ( code === 2){ + res.send({"error":"The roof is on fire"}); } else { res.send({"error":"invalid or unreachable"}); } }); }; module.exports = (req, res) => { - console.log(req.query) - if ( (req.query.zblock) && req.query.zblock.length === 46 ){ + console.log(req.params) + if ( (req.params.zblock) && req.params.zblock.length === 46 ){ regex= /Qm[A-Za-z0-9]{44}/; - if (regex.test(req.query.zblock)){ - if (req.query.zblock === "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" ){ + if (regex.test(req.params.zblock)){ + if (req.params.zblock === "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" ){ res.send({error:"Genesis block"}); } else { - fetchZblock(req.query.zblock,res); + fetchZblock(req.params.zblock,res); } } else { res.send({error:"Invalid data: regexp failed to pass"}); |