From dd5c8c3e10851d3b8c5d7764c90035e1d976a958 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sat, 4 Jun 2022 09:13:03 +0200 Subject: Immutable --- modules/delete.js | 33 ++++++++++++++++++++++----------- modules/write.js | 7 +++++++ 2 files changed, 29 insertions(+), 11 deletions(-) (limited to 'modules') 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") { -- cgit