ProxmoxAAS-API/db.js
Arthur Lu 0ad242a557 implement db as class,
improve approveResources

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
2023-05-24 22:21:00 +00:00

35 lines
650 B
JavaScript

import { readFileSync, writeFileSync } from "fs";
class localdb {
#template = "localdb.json.template";
#filename = "localdb.json";
#data = null;
constructor () {
try {
this.load(this.#filename);
}
catch {
this.load(this.#template);
this.save(this.#filename);
}
}
load(path) {
this.#data = JSON.parse(readFileSync(path));
}
save(path) {
writeFileSync(path, JSON.stringify(this.#data));
}
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();