aboutsummaryrefslogtreecommitdiff
path: root/api/routes/getChunk
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/getChunk')
-rw-r--r--api/routes/getChunk/index.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/api/routes/getChunk/index.js b/api/routes/getChunk/index.js
index d848ce9..dc86bd8 100644
--- a/api/routes/getChunk/index.js
+++ b/api/routes/getChunk/index.js
@@ -7,7 +7,8 @@
const fs = require('fs');
const config = require("../../config.js");
-module.exports = (req, res) => {
+function getChunk(req, res)
+{
var args = req.url.split("/");
var hash = args[3];
regex= /[a-f0-9]{128}/
@@ -18,12 +19,19 @@ module.exports = (req, res) => {
{
if(fs.existsSync(path))
{
- res.send(fs.readFileSync(path));
+ res.writeHead(200, {'Content-Type': 'application/json'});
+ res.end(fs.readFileSync(path));
+ }
+ else
+ {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({"error":"not found"}));
}
}
catch (error)
{
- res.send({"error":error.message});
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({"error":error.message}));
}
}
else
@@ -32,4 +40,4 @@ module.exports = (req, res) => {
res.end(JSON.stringify({error:"No hash"}));
}
}
-
+module.exports = getChunk;