aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getZblock
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/getZblock')
-rw-r--r--api/routes/getZblock/index.js19
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"});