aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getIPFSHash/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/getIPFSHash/index.js')
-rw-r--r--api/routes/getIPFSHash/index.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/api/routes/getIPFSHash/index.js b/api/routes/getIPFSHash/index.js
index f412c80..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
{
@@ -41,9 +44,10 @@ function fetchIPFShash(zblock, res)
}
};
-module.exports = (req, 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]))
{
@@ -66,6 +70,7 @@ module.exports = (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;