aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2023-08-03 10:43:32 +0300
committerkaotisk <kaotisk@arching-kaos.org>2023-08-03 10:43:32 +0300
commit67450601ebcbf4cd31d316e9e9a8a339a0719766 (patch)
tree2e95802f46c87bd522898f3f8dd5094366d6a348 /api
parenteb83dc73c0f71b2cf3480b17658ef7f21e92e570 (diff)
downloadarching-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')
-rw-r--r--api/routes/getSBlock/index.js27
-rw-r--r--api/routes/getZblock/index.js19
-rw-r--r--api/routes/index.js4
3 files changed, 28 insertions, 22 deletions
diff --git a/api/routes/getSBlock/index.js b/api/routes/getSBlock/index.js
index 4ad9127..e78c421 100644
--- a/api/routes/getSBlock/index.js
+++ b/api/routes/getSBlock/index.js
@@ -1,18 +1,19 @@
-const { spawn } = require('child_process');
-const config = require("../../config.js");
-
-
/*
- * Gets a SBLOCK from superchain
- * LOL
+ * Receives an SHA512SUM as a SBlock and if exists returns the SBlock content.
*
*/
+
+const { spawn } = require('child_process');
+const fs = require('fs');
+const config = require("../../config.js");
+
module.exports = (req, res) => {
regex= /[a-f0-9]{128}/
- if (regex.test(req.query.sblock)){
+ if (regex.test(req.params.sblock)){
genesisreg = /0{128}/
- if (!genesisreg.test(req.query.sblock)){
- const command = spawn("cat",[config.minedBlocksDir+req.query.sblock]);
+ if (!genesisreg.test(req.params.sblock)){
+ var path = config.minedBlocksDir+"/"+req.params.sblock;
+ const command = spawn("cat",[config.minedBlocksDir+"/"+req.params.sblock]);
response_string = "";
command.stdout.on("data", data => {
response_string = response_string+data;
@@ -28,9 +29,11 @@ module.exports = (req, res) => {
});
command.on("close", code => {
- smt = JSON.stringify(response_string);
- res.send({hrefPrevious:"http://127.0.0.1:8610/v0/sblock?sblock="+smt.previous,sblock:smt});
- // res.send(JSON.parse(response_string));
+ if ( code === 0 ) {
+ res.send(JSON.parse(fs.readFileSync(path)));
+ } else {
+ res.send({"error":"Sblock not found"})
+ }
console.log(`child process exited with code ${code}`);
});
} else {
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"});
diff --git a/api/routes/index.js b/api/routes/index.js
index c019967..e697be7 100644
--- a/api/routes/index.js
+++ b/api/routes/index.js
@@ -32,7 +32,7 @@ router.route(settings.URL_PREFIX+'/see').get(seeEntriesFile);
// Latest known mined block
router.route(settings.URL_PREFIX+'/slatest').get(getSLatest);
// Shows a mined block (provided that /sblock?sblock=SHA512 hash)
-router.route(settings.URL_PREFIX+'/sblock').get(getSBlock);
+router.route(settings.URL_PREFIX+'/sblock/:sblock').get(getSBlock);
// Outputs node's local chain
router.route(settings.URL_PREFIX+'/zchain').get(getZChain);
// Returns latest zblock from node's local chain
@@ -42,7 +42,7 @@ router.route(settings.URL_PREFIX+'/akid').get(getAkid);
// Returns content
router.route(settings.URL_PREFIX+'/content').get(getInnerIPFSContent);
// Returns zblock
-router.route(settings.URL_PREFIX+'/zblock').get(getZblock);
+router.route(settings.URL_PREFIX+'/zblock/:zblock').get(getZblock);
// Send a block to the node (zchain block)
router.route(settings.URL_PREFIX+'/sblk').post(receiveZBlock);
// Send a zchain link to the node (refering to a valid zchain out there)