2023-04-26 01:18:05 +00:00
|
|
|
import { readFileSync, writeFileSync } from "fs";
|
2023-02-27 01:09:49 +00:00
|
|
|
|
2023-04-26 01:18:05 +00:00
|
|
|
let template = "localdb.json.template"
|
|
|
|
let filename = "localdb.json";
|
2023-02-27 01:09:49 +00:00
|
|
|
|
2023-04-26 01:18:05 +00:00
|
|
|
let db = JSON.parse(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 () {
|
2023-04-26 01:18:05 +00:00
|
|
|
db = JSON.parse(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 () {
|
2023-04-26 01:18:05 +00:00
|
|
|
writeFileSync(filename, JSON.stringify(db));
|
2023-04-19 02:42:35 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 20:51:07 +00:00
|
|
|
export 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-26 01:18:05 +00:00
|
|
|
export function getUserConfig (username) {
|
2023-04-19 02:42:35 +00:00
|
|
|
return db.users[username];
|
2023-04-26 01:18:05 +00:00
|
|
|
}
|