ProxmoxAAS-API/db.js

30 lines
488 B
JavaScript
Raw Normal View History

2023-02-27 01:09:49 +00:00
const fs = require("fs");
template = "localdb.json.template"
2023-02-27 01:09:49 +00:00
filename = "localdb.json";
let db = JSON.parse(fs.readFileSync(template));
try {
load();
}
catch {
save();
2023-02-27 01:28:01 +00:00
}
2023-04-19 02:42:35 +00:00
function load () {
db = JSON.parse(fs.readFileSync(filename));
2023-02-27 01:28:01 +00:00
}
2023-04-19 02:42:35 +00:00
function save () {
fs.writeFileSync(filename, JSON.stringify(db));
}
function getResourceConfig() {
return db.resources;
2023-02-27 01:28:01 +00:00
}
function getUserConfig (username) {
2023-04-19 02:42:35 +00:00
return db.users[username];
}
module.exports = {getUserConfig, getResourceConfig};