aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-11-20 11:48:10 +0200
committerkaotisk <kaotisk@arching-kaos.org>2024-11-20 11:48:10 +0200
commit59afc2bc737f4c9edf32cc1ee05e81b99f0eeb2f (patch)
tree25582bbe1d97b22029c298207a455fda871026a4 /api
parent4aa29c28f54704c3fdba9ba432916ad340447c61 (diff)
downloadarching-kaos-tools-59afc2bc737f4c9edf32cc1ee05e81b99f0eeb2f.tar.gz
arching-kaos-tools-59afc2bc737f4c9edf32cc1ee05e81b99f0eeb2f.tar.bz2
arching-kaos-tools-59afc2bc737f4c9edf32cc1ee05e81b99f0eeb2f.zip
Implements the following routes to the API
- /leaf - /chunk - /map
Diffstat (limited to 'api')
-rw-r--r--api/routes/getChunk/index.js35
-rw-r--r--api/routes/getLeaf/index.js35
-rw-r--r--api/routes/getMap/index.js35
3 files changed, 105 insertions, 0 deletions
diff --git a/api/routes/getChunk/index.js b/api/routes/getChunk/index.js
new file mode 100644
index 0000000..d848ce9
--- /dev/null
+++ b/api/routes/getChunk/index.js
@@ -0,0 +1,35 @@
+/*
+ * Receives an SHA512SUM as a chunk's hash and if exists it
+ * returns the chunk's content
+ *
+ */
+
+const fs = require('fs');
+const config = require("../../config.js");
+
+module.exports = (req, res) => {
+ var args = req.url.split("/");
+ var hash = args[3];
+ regex= /[a-f0-9]{128}/
+ if (regex.test(hash))
+ {
+ var path = config.chunksDir+"/"+hash;
+ try
+ {
+ if(fs.existsSync(path))
+ {
+ res.send(fs.readFileSync(path));
+ }
+ }
+ catch (error)
+ {
+ res.send({"error":error.message});
+ }
+ }
+ else
+ {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"No hash"}));
+ }
+}
+
diff --git a/api/routes/getLeaf/index.js b/api/routes/getLeaf/index.js
new file mode 100644
index 0000000..593d52a
--- /dev/null
+++ b/api/routes/getLeaf/index.js
@@ -0,0 +1,35 @@
+/*
+ * Receives an SHA512SUM as a leaf's hash and if exists it
+ * returns the leaf's content
+ *
+ */
+
+const fs = require('fs');
+const config = require("../../config.js");
+
+module.exports = (req, res) => {
+ var args = req.url.split("/");
+ var hash = args[3];
+ regex= /[a-f0-9]{128}/
+ if (regex.test(hash))
+ {
+ var path = config.leafsDir+"/"+hash;
+ try
+ {
+ if(fs.existsSync(path))
+ {
+ res.send(fs.readFileSync(path));
+ }
+ }
+ catch (error)
+ {
+ res.send({"error":error.message});
+ }
+ }
+ else
+ {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"No hash"}));
+ }
+}
+
diff --git a/api/routes/getMap/index.js b/api/routes/getMap/index.js
new file mode 100644
index 0000000..fa834ab
--- /dev/null
+++ b/api/routes/getMap/index.js
@@ -0,0 +1,35 @@
+/*
+ * Receives an SHA512SUM as a map's hash and if exists it
+ * returns the map's content
+ *
+ */
+
+const fs = require('fs');
+const config = require("../../config.js");
+
+module.exports = (req, res) => {
+ var args = req.url.split("/");
+ var hash = args[3];
+ regex= /[a-f0-9]{128}/
+ if (regex.test(hash))
+ {
+ var path = config.mapsDir+"/"+hash;
+ try
+ {
+ if(fs.existsSync(path))
+ {
+ res.send(fs.readFileSync(path));
+ }
+ }
+ catch (error)
+ {
+ res.send({"error":error.message});
+ }
+ }
+ else
+ {
+ res.writeHead(404, {'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"No hash"}));
+ }
+}
+