49 lines
1.1 KiB
JavaScript
Raw Normal View History

import { readFileSync, writeFileSync } from "fs";
import { exit } from "process";
2023-06-29 21:35:19 +00:00
class LocalDB {
#filename = "config/localdb.json";
#data = null;
2023-06-29 21:35:19 +00:00
constructor () {
try {
this.load(this.#filename);
2023-06-29 22:09:57 +00:00
}
catch {
console.log("Error: localdb.json was not found. Please follow the directions in the README to initialize localdb.json.");
exit(1);
}
}
2023-06-29 21:35:19 +00:00
load (path) {
this.#data = JSON.parse(readFileSync(path));
}
2023-06-29 21:35:19 +00:00
save (path) {
writeFileSync(path, JSON.stringify(this.#data));
}
2023-06-29 21:35:19 +00:00
getApplicationConfig () {
return this.#data.application;
}
2023-06-29 21:35:19 +00:00
getResourceConfig () {
return this.#data.resources;
}
2023-06-29 21:35:19 +00:00
getUserConfig (username) {
if (this.#data.users[username]) {
return this.#data.users[username];
2023-06-29 22:09:57 +00:00
}
else {
return null;
}
}
}
2023-06-29 21:35:19 +00:00
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;
2023-06-29 21:35:19 +00:00
export const domain = db.getApplicationConfig().domain;