40 lines
996 B
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
getGlobalConfig () {
return this.#data.global;
}
2023-06-29 21:35:19 +00:00
getUserConfig (username) {
return this.#data.users[username];
}
}
2023-06-29 21:35:19 +00:00
export const db = new LocalDB();
export const pveAPI = db.getGlobalConfig().application.pveAPI;
export const pveAPIToken = db.getGlobalConfig().application.pveAPIToken;
export const listenPort = db.getGlobalConfig().application.listenPort;
export const hostname = db.getGlobalConfig().application.hostname;
export const domain = db.getGlobalConfig().application.domain;