ProxmoxAAS-API/db.js

33 lines
525 B
JavaScript
Raw Normal View History

import { readFileSync, writeFileSync } from "fs";
2023-02-27 01:09:49 +00:00
let template = "localdb.json.template"
let filename = "localdb.json";
2023-02-27 01:09:49 +00:00
let db = JSON.parse(readFileSync(template));
try {
load();
}
catch {
save();
2023-02-27 01:28:01 +00:00
}
2023-05-17 21:38:11 +00:00
function load() {
db = JSON.parse(readFileSync(filename));
2023-02-27 01:28:01 +00:00
}
2023-05-17 21:38:11 +00:00
function save() {
writeFileSync(filename, JSON.stringify(db));
2023-04-19 02:42:35 +00:00
}
2023-05-17 21:38:11 +00:00
export function getResourceConfig() {
return db.resources;
2023-02-27 01:28:01 +00:00
}
2023-05-17 21:38:11 +00:00
export function getUserConfig(username) {
if (db.users[username]) {
return db.users[username];
}
else {
return null;
}
}