move source files to src folder,

move localdb to config folder,
consolidate vars.js with localdb,
move service scripts to service folder
This commit is contained in:
2023-06-09 03:58:38 +00:00
parent 24df8df731
commit 485ba0120e
11 changed files with 63 additions and 54 deletions

43
src/db.js Normal file
View File

@@ -0,0 +1,43 @@
import { readFileSync, writeFileSync } from "fs";
import { exit } from "process";
class localdb {
#filename = "config/localdb.json";
#data = null;
constructor() {
try {
this.load(this.#filename);
}
catch {
console.log("Error: localdb.json was not found. Please follow the directions in the README to initialize localdb.json.");
exit(1);
}
}
load(path) {
this.#data = JSON.parse(readFileSync(path));
}
save(path) {
writeFileSync(path, JSON.stringify(this.#data));
}
getApplicationConfig() {
return this.#data.application;
}
getResourceConfig() {
return this.#data.resources;
}
getUserConfig(username) {
if (this.#data.users[username]) {
return this.#data.users[username];
}
else {
return null;
}
}
}
export const db = new localdb();
export const pveAPI = db.getApplicationConfig().pveAPI;
export const pveAPIToken = db.getApplicationConfig().pveAPIToken;
export const listenPort = db.getApplicationConfig().listenPort;
export const hostname = db.getApplicationConfig().hostname;
export const domain = db.getApplicationConfig().domain;