2023-02-27 01:09:49 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
|
2023-04-20 20:43:05 +00:00
|
|
|
template = "localdb.json.template"
|
2023-02-27 01:09:49 +00:00
|
|
|
filename = "localdb.json";
|
|
|
|
|
2023-04-20 20:43:05 +00:00
|
|
|
let db = JSON.parse(fs.readFileSync(template));
|
2023-04-24 21:28:58 +00:00
|
|
|
try {
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
save();
|
2023-02-27 01:28:01 +00:00
|
|
|
}
|
2023-02-26 08:36:27 +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-02-26 08:36:27 +00:00
|
|
|
|
2023-04-19 02:42:35 +00:00
|
|
|
function save () {
|
|
|
|
fs.writeFileSync(filename, JSON.stringify(db));
|
|
|
|
}
|
|
|
|
|
2023-04-24 21:28:58 +00:00
|
|
|
function getResourceConfig() {
|
2023-04-20 20:43:05 +00:00
|
|
|
return db.resources;
|
2023-02-27 01:28:01 +00:00
|
|
|
}
|
2023-02-26 08:36:27 +00:00
|
|
|
|
2023-04-24 21:28:58 +00:00
|
|
|
function getUserConfig (username) {
|
2023-04-19 02:42:35 +00:00
|
|
|
return db.users[username];
|
|
|
|
}
|
|
|
|
|
2023-04-24 21:28:58 +00:00
|
|
|
module.exports = {getUserConfig, getResourceConfig};
|