aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-04 08:51:01 +0200
committerMinteck <contact@minteck.org>2022-06-04 08:51:01 +0200
commit383285ecd5292bf9a825e05904955b937de84cc9 (patch)
tree0a53b6f02c1604b078044567c03dc1b6c944c8c2 /modules
downloadequestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.gz
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.bz2
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.zip
Initial commit
Diffstat (limited to 'modules')
-rw-r--r--modules/_.js26
-rw-r--r--modules/delete.js35
-rw-r--r--modules/exists.js37
-rw-r--r--modules/head.js9
-rw-r--r--modules/read.js39
-rw-r--r--modules/scandir.js49
-rw-r--r--modules/size.js39
-rw-r--r--modules/version.js16
-rw-r--r--modules/write.js40
9 files changed, 290 insertions, 0 deletions
diff --git a/modules/_.js b/modules/_.js
new file mode 100644
index 0000000..f5f9cb5
--- /dev/null
+++ b/modules/_.js
@@ -0,0 +1,26 @@
+const os = require("os");
+module.exports = (req, res) => {
+ res.writeHead(200, {'Content-Type':'text/plain'});
+ const os = require('os');
+ res.write("__ ____ ____\n" +
+ "\\ \\ ____ ____ __ _____ _____/ __ \\/ __ )\n" +
+ " \\ \\/ __ \\/ __ `/ | /| / / _ \\/ ___/ / / / __ |\n" +
+ " / / /_/ / /_/ /| |/ |/ / __/ / / /_/ / /_/ /\n" +
+ "/_/ .___/\\__,_/ |__/|__/\\___/_/ /_____/_____/_____\n" +
+ " /_/ /_____/\n" +
+ "\n" +
+ "==============================\n" +
+ "Runtime Information:\n" +
+ " pawerDB version: " + variables.version + "\n NodeJS version: " + process.versions.node + "\n System: " + os.type() + " " + os.arch() + " " + os.release() + "\n User: " + os.userInfo().username + " (" + os.userInfo().uid + ":" + os.userInfo().gid + ")" +
+ "\n\n" +
+ "==============================\n" +
+ "Get libpawerdb:\n" +
+ " PHP: -\n NodeJS: -\n JavaScript (browser): -\n Bash: -\n Python: -" +
+ "\n\n" +
+ "==============================\n" +
+ "About pawerDB:\n" +
+ " Setting up: -\n API: -\n Maintenance tasks: -\n Optimizations: -" +
+ "\n\n"
+ );
+ res.end();
+} \ No newline at end of file
diff --git a/modules/delete.js b/modules/delete.js
new file mode 100644
index 0000000..928b7b3
--- /dev/null
+++ b/modules/delete.js
@@ -0,0 +1,35 @@
+const body = require("body/json");
+const crypto = require('crypto');
+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 (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string") {
+ node = crypto.createHash('md5').update(body.path).digest('hex');
+ file = "/data/" + dbid + "/" + node.substring(0, 2) + "/" + node;
+
+ 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"));
+
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": node,
+ "path": file
+ },
+ "error": 200
+ }));
+ res.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ })
+} \ No newline at end of file
diff --git a/modules/exists.js b/modules/exists.js
new file mode 100644
index 0000000..ff50765
--- /dev/null
+++ b/modules/exists.js
@@ -0,0 +1,37 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ body(req, res, variables.bodyOptions, (err, body) => {
+ try {
+ if (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string") {
+ node = crypto.createHash('md5').update(body.path).digest('hex');
+ file = "/data/" + dbid + "/" + node.substring(0, 2) + "/" + node;
+
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": node,
+ "path": file
+ },
+ "error": 200,
+ "data": fs.existsSync(__dirname + "/../" + file)
+ }));
+ res.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ } catch (e) {
+ console.error(e);
+ res.writeHead(502, {'Content-Type':'application/json'});
+ res.write("{\"error\":502}");
+ res.end();
+ }
+ })
+} \ No newline at end of file
diff --git a/modules/head.js b/modules/head.js
new file mode 100644
index 0000000..39a81b4
--- /dev/null
+++ b/modules/head.js
@@ -0,0 +1,9 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ res.write(JSON.stringify(heads[entry]) ?? "{}");
+ res.end();
+} \ No newline at end of file
diff --git a/modules/read.js b/modules/read.js
new file mode 100644
index 0000000..3806c14
--- /dev/null
+++ b/modules/read.js
@@ -0,0 +1,39 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ body(req, res, variables.bodyOptions, (err, body) => {
+ try {
+ if (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string") {
+ node = crypto.createHash('md5').update(body.path).digest('hex');
+ file = "/data/" + dbid + "/" + node.substring(0, 2) + "/" + node;
+
+ data = Buffer.from(fs.readFileSync(__dirname + "/../" + file).toString(), "base64").toString("utf-8");
+
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": node,
+ "path": file
+ },
+ "error": 200,
+ "data": data
+ }));
+ res.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ } catch (e) {
+ console.error(e);
+ res.writeHead(502, {'Content-Type':'application/json'});
+ res.write("{\"error\":502}");
+ res.end();
+ }
+ })
+} \ No newline at end of file
diff --git a/modules/scandir.js b/modules/scandir.js
new file mode 100644
index 0000000..ebd5e32
--- /dev/null
+++ b/modules/scandir.js
@@ -0,0 +1,49 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ body(req, res, variables.bodyOptions, (err, body) => {
+ try {
+ if (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string") {
+ let contents = [];
+
+ let search;
+ if (body.path.endsWith("/")) {
+ search = body.path;
+ } else {
+ search = body.path + "/";
+ }
+
+ for (let item of Object.keys(heads[entry])) {
+ if (item.startsWith(search)) {
+ contents.push(item.substring(search.length).split("/")[0]);
+ }
+ }
+
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": null,
+ "path": null
+ },
+ "error": 200,
+ "data": [...new Set(contents)]
+ }));
+ res.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ } catch (e) {
+ console.error(e);
+ res.writeHead(502, {'Content-Type':'application/json'});
+ res.write("{\"error\":502}");
+ res.end();
+ }
+ })
+} \ No newline at end of file
diff --git a/modules/size.js b/modules/size.js
new file mode 100644
index 0000000..4dc8046
--- /dev/null
+++ b/modules/size.js
@@ -0,0 +1,39 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ body(req, res, variables.bodyOptions, (err, body) => {
+ try {
+ if (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string") {
+ node = crypto.createHash('md5').update(body.path).digest('hex');
+ file = "/data/" + dbid + "/" + node.substring(0, 2) + "/" + node;
+
+ data = fs.readFileSync(__dirname + "/../" + file).length;
+
+ res.write(JSON.stringify({
+ "_internal": {
+ "database": entry,
+ "node": node,
+ "path": file
+ },
+ "error": 200,
+ "data": data
+ }));
+ res.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ } catch (e) {
+ console.error(e);
+ res.writeHead(502, {'Content-Type':'application/json'});
+ res.write("{\"error\":502}");
+ res.end();
+ }
+ })
+} \ No newline at end of file
diff --git a/modules/version.js b/modules/version.js
new file mode 100644
index 0000000..22a3667
--- /dev/null
+++ b/modules/version.js
@@ -0,0 +1,16 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+const os = require("os");
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ res.write(JSON.stringify({
+ error: 200,
+ ...process.versions,
+ pawerdb: variables.version,
+ os: os.type() + " " + os.arch() + " " + os.release(),
+ user: os.userInfo()
+ }));
+ res.end();
+} \ No newline at end of file
diff --git a/modules/write.js b/modules/write.js
new file mode 100644
index 0000000..d733360
--- /dev/null
+++ b/modules/write.js
@@ -0,0 +1,40 @@
+const body = require("body/json");
+const crypto = require('crypto');
+const fs = require('fs');
+
+module.exports = (req, res, entry, dbid) => {
+ res.writeHead(200, {'Content-Type':'application/json'});
+ body(req, res, variables.bodyOptions, (err, body) => {
+ try {
+ if (err) throw err;
+ console.log(body);
+ if (typeof body.path === "string" && typeof body.data === "string") {
+ node = crypto.createHash('md5').update(body.path).digest('hex');
+ file = "/data/" + dbid + "/" + node.substring(0, 2) + "/" + node;
+
+ fs.writeFileSync(__dirname + "/../" + file, Buffer.from(body.data).toString("base64"));
+ heads[entry][body.path] = file;
+ 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.end();
+ } else {
+ res.writeHead(400, {'Content-Type':'application/json'});
+ res.write("{\"error\":400}");
+ res.end();
+ }
+ } catch (e) {
+ console.error(e);
+ res.writeHead(502, {'Content-Type':'application/json'});
+ res.write("{\"error\":502}");
+ res.end();
+ }
+ })
+} \ No newline at end of file