From 67450601ebcbf4cd31d316e9e9a8a339a0719766 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Thu, 3 Aug 2023 10:43:32 +0300 Subject: Changed to get params instead of query --- api/routes/getZblock/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'api/routes/getZblock/index.js') 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"}); -- cgit v1.2.3