aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-04 09:13:03 +0200
committerMinteck <contact@minteck.org>2022-06-04 09:13:03 +0200
commitdd5c8c3e10851d3b8c5d7764c90035e1d976a958 (patch)
treede90f23501dd5ab19356ccd466792fd0f5c7bf49
parent90db3a8698d385f9ac2086d238cd58de20d153ba (diff)
downloadequestriadb-dd5c8c3e10851d3b8c5d7764c90035e1d976a958.tar.gz
equestriadb-dd5c8c3e10851d3b8c5d7764c90035e1d976a958.tar.bz2
equestriadb-dd5c8c3e10851d3b8c5d7764c90035e1d976a958.zip
ImmutableHEADmane
-rw-r--r--.gitignore1
-rw-r--r--data/databases.yml2
-rw-r--r--modules/delete.js33
-rw-r--r--modules/write.js7
4 files changed, 31 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 3b81951..5e7e92c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
data/e900a9020bbb5db562fe3b148873a78d
+data/cc411e6c13670e52124629b8ac83f7d0
node_modules \ No newline at end of file
diff --git a/data/databases.yml b/data/databases.yml
index 62646f6..2590589 100644
--- a/data/databases.yml
+++ b/data/databases.yml
@@ -17,7 +17,7 @@ neutron:
# Whether the database should be immutable (read-only) or not
# If enabled, all 'delete' and 'write' commands will be
# rejected.
- immutable: false
+ immutable: true
# You can add one or multiple access tokens; make sure all
# the access tokens are unique across all databases.
diff --git a/modules/delete.js b/modules/delete.js
index 928b7b3..b4e54b0 100644
--- a/modules/delete.js
+++ b/modules/delete.js
@@ -5,6 +5,13 @@ const fs = require('fs');
module.exports = (req, res, entry, dbid) => {
res.writeHead(200, {'Content-Type':'application/json'});
body(req, res, variables.bodyOptions, (err, body) => {
+ if (databases[entry]["immutable"]) {
+ res.writeHead(501, {'Content-Type':'application/json'});
+ res.write("{\"error\":501}");
+ res.end();
+ return;
+ }
+
if (err) throw err;
console.log(body);
if (typeof body.path === "string") {
@@ -13,18 +20,22 @@ module.exports = (req, res, entry, dbid) => {
if (fs.existsSync(__dirname + "/../" + file)) {
fs.unlinkSync(__dirname + "/../" + file);
- }
- delete heads[entry][body.path];
- fs.writeFileSync(__dirname + "/../data/" + dbid + "/HEAD", Buffer.from(JSON.stringify(heads[entry])).toString("hex"));
+ delete heads[entry][body.path];
+ fs.writeFileSync(__dirname + "/../data/" + dbid + "/HEAD", Buffer.from(JSON.stringify(heads[entry])).toString("hex"));
- res.write(JSON.stringify({
- "_internal": {
- "database": entry,
- "node": node,
- "path": file
- },
- "error": 200
- }));
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": node,
+ "path": file
+ },
+ "error": 200
+ }));
+ } else {
+ res.write(JSON.stringify({
+ "error": 404
+ }));
+ }
res.end();
} else {
res.writeHead(400, {'Content-Type':'application/json'});
diff --git a/modules/write.js b/modules/write.js
index d733360..48ab1d6 100644
--- a/modules/write.js
+++ b/modules/write.js
@@ -6,6 +6,13 @@ module.exports = (req, res, entry, dbid) => {
res.writeHead(200, {'Content-Type':'application/json'});
body(req, res, variables.bodyOptions, (err, body) => {
try {
+ if (databases[entry]["immutable"]) {
+ res.writeHead(501, {'Content-Type':'application/json'});
+ res.write("{\"error\":501}");
+ res.end();
+ return;
+ }
+
if (err) throw err;
console.log(body);
if (typeof body.path === "string" && typeof body.data === "string") {