diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2025-04-14 18:41:27 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2025-04-14 18:41:27 +0300 |
commit | afe9b4600b805e8627e539121d85cc7bcc22d6af (patch) | |
tree | c28f8fdcad08cb5570bc4de2000b2f8698f3844c /api/routes/getIPFSHash | |
parent | 333864c5fe098b6993066d73b8d6d8e6fb358eb0 (diff) | |
download | arching-kaos-tools-origin/master.tar.gz arching-kaos-tools-origin/master.tar.bz2 arching-kaos-tools-origin/master.zip |
[api] workaround + generified from zblock to ipfs_hashHEADorigin/masterorigin/HEADmaster
Diffstat (limited to 'api/routes/getIPFSHash')
-rw-r--r-- | api/routes/getIPFSHash/index.js | 19 |
1 files changed, 11 insertions, 8 deletions
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; |