diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-14 07:15:52 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-14 07:15:52 +0300 |
commit | 3736241cb07eb47c7ceed5fc38cb43633bb0ab4c (patch) | |
tree | 91131a6b5b04df363486fc9c265b42829377bd40 /api | |
parent | b672f3904c2e17833ff5745bdbc16a8f351ff517 (diff) | |
download | arching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.tar.gz arching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.tar.bz2 arching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.zip |
Refactoring
Diffstat (limited to 'api')
-rw-r--r-- | api/routes/announceZChain/index.js | 6 | ||||
-rw-r--r-- | api/routes/getInnerIPFSContent/index.js | 15 |
2 files changed, 14 insertions, 7 deletions
diff --git a/api/routes/announceZChain/index.js b/api/routes/announceZChain/index.js index a1b336c..0261aa4 100644 --- a/api/routes/announceZChain/index.js +++ b/api/routes/announceZChain/index.js @@ -22,9 +22,11 @@ module.exports = (req, res) => { if (regex.test(zchain)){ getNSvalidity(zchain,res); } else { - res.send({error:"Invalid data"}); + res.writeHead(404, { 'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"Invalid data"})); } } else { - res.send({error:"Invalid data"}); + res.writeHead(404, { 'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"Invalid data"})); } } diff --git a/api/routes/getInnerIPFSContent/index.js b/api/routes/getInnerIPFSContent/index.js index b3a05cb..721e836 100644 --- a/api/routes/getInnerIPFSContent/index.js +++ b/api/routes/getInnerIPFSContent/index.js @@ -1,4 +1,3 @@ -const { spawn } = require('child_process'); const fs = require("fs"); const config = require("../../config"); @@ -11,8 +10,11 @@ const config = require("../../config"); * */ function fetchZblock(zblock, res){ - res.send(fs.readFileSync(config.workDir+"/ipfs/"+zblock)); + res.writeHead(200, { 'Content-Type': 'application/json'}); + var path = config.workDir+"/ipfs/"+zblock; + res.end(JSON.stringify(JSON.parse(fs.readFileSync(path)))); }; + module.exports = (req, res) => { console.log(req.query) if ( (req.query.ipfs) && typeof req.query.ipfs === "string" && req.query.ipfs.length === 46 ){ @@ -20,14 +22,17 @@ module.exports = (req, res) => { regex= /Qm[A-Za-z0-9]{44}/; if (regex.test(ipfs)){ if (ipfs === "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" ){ - res.send({error:"Genesis block"}); + res.writeHead(200, { 'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"Genesis block"})); } else { fetchZblock(ipfs,res); } } else { - res.send({error:"Invalid data: regexp failed to pass"}); + res.writeHead(404, { 'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"Invalid data: regexp failed to pass"})); } } else { - res.send({error:"Invalid data: no valid zblock was provided"}); + res.writeHead(404, { 'Content-Type': 'application/json'}); + res.end(JSON.stringify({error:"Invalid data: no valid zblock was provided"})); } } |