aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2025-04-14 18:41:27 +0300
committerkaotisk <kaotisk@arching-kaos.org>2025-04-14 18:41:27 +0300
commitafe9b4600b805e8627e539121d85cc7bcc22d6af (patch)
treec28f8fdcad08cb5570bc4de2000b2f8698f3844c
parent333864c5fe098b6993066d73b8d6d8e6fb358eb0 (diff)
downloadarching-kaos-tools-master.tar.gz
arching-kaos-tools-master.tar.bz2
arching-kaos-tools-master.zip
[api] workaround + generified from zblock to ipfs_hashHEADorigin/masterorigin/HEADmaster
-rwxr-xr-xapi/index.js1
-rw-r--r--api/routes/getIPFSHash/index.js19
2 files changed, 12 insertions, 8 deletions
diff --git a/api/index.js b/api/index.js
index f5cf8c8..f2ca713 100755
--- a/api/index.js
+++ b/api/index.js
@@ -59,6 +59,7 @@ function getRoutes(req, res)
case 'peers': getPeers(req, res); break;
case 'node_info': getNodeInfo(req, res); break;
case 'ipfs_hash': getIPFSHash(req, res); break;
+ case 'ipfs': getIPFSHash(req, res); break;
case 'zlatest': getZlatest(req, res); break;
case 'sblock': getSblock(req, res); break;
case 'slatest': getSlatest(req, res); break;
diff --git a/api/routes/getIPFSHash/index.js b/api/routes/getIPFSHash/index.js
index 4fc8d69..d1bdc5f 100644
--- a/api/routes/getIPFSHash/index.js
+++ b/api/routes/getIPFSHash/index.js
@@ -1,26 +1,29 @@
const { spawn } = require('child_process');
const fs = require("fs");
const config = require("../../config");
+const akLogMessage = require("../../lib/akLogMessage");
+akLogMessage('lol');
/*
- * Returns a cached zblock
+ * Returns a cached ipfs_hash
*
* Returns:
* - JSON object
*
*/
-function fetchIPFShash(zblock, res)
+function fetchIPFShash(ipfs_hash, res)
{
regex= /Qm[A-Za-z0-9]{44}/;
- if (regex.test(zblock)){
- const path = `${config.ipfsArtifactsDir}/${zblock}`;
+ if (regex.test(ipfs_hash)){
+ const path = `${config.ipfsArtifactsDir}/${ipfs_hash}`;
console.log(path)
try
{
if(fs.existsSync(path))
{
- res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
+ res.writeHead(200); //, {'Content-Type': 'application/json'});
+ // res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
+ res.end(fs.readFileSync(path));
}
else
{
@@ -44,7 +47,7 @@ function fetchIPFShash(zblock, res)
function getIPFSHash(req, res)
{
var args = req.url.split("/");
- if ( (args[2] === 'ipfs_hash') && args[3] && typeof args[3] === "string" && args[3].length === 46 ){
+ if ( (args[2] === 'ipfs_hash'||args[2] === 'ipfs') && args[3] && typeof args[3] === "string" && args[3].length === 46 ){
regex= /Qm[A-Za-z0-9]{44}/;
if (regex.test(args[3]))
{
@@ -67,7 +70,7 @@ function getIPFSHash(req, res)
else
{
res.writeHead(404, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({error:"Invalid data: no valid zblock was provided"}));
+ res.end(JSON.stringify({error:"Invalid data: no valid ipfs_hash was provided"}));
}
}
module.exports = getIPFSHash;