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:
43
src/db.js
Normal file
43
src/db.js
Normal 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;
|
Reference in New Issue
Block a user