aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getInnerIPFSContent/index.js
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-14 07:15:52 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-14 07:15:52 +0300
commit3736241cb07eb47c7ceed5fc38cb43633bb0ab4c (patch)
tree91131a6b5b04df363486fc9c265b42829377bd40 /api/routes/getInnerIPFSContent/index.js
parentb672f3904c2e17833ff5745bdbc16a8f351ff517 (diff)
downloadarching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.tar.gz
arching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.tar.bz2
arching-kaos-tools-3736241cb07eb47c7ceed5fc38cb43633bb0ab4c.zip
Refactoring
Diffstat (limited to 'api/routes/getInnerIPFSContent/index.js')
-rw-r--r--api/routes/getInnerIPFSContent/index.js15
1 files changed, 10 insertions, 5 deletions
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"}));
}
}