2023-04-26 01:18:05 +00:00
|
|
|
import { readFileSync, writeFileSync } from "fs";
|
2023-02-27 01:09:49 +00:00
|
|
|
|
2023-05-24 22:21:00 +00:00
|
|
|
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));
|
2023-05-23 00:11:48 +00:00
|
|
|
}
|
2023-05-24 22:21:00 +00:00
|
|
|
getResourceConfig () {
|
|
|
|
return this.#data.resources;
|
2023-05-23 00:11:48 +00:00
|
|
|
}
|
2023-05-24 22:21:00 +00:00
|
|
|
getUserConfig (username) {
|
|
|
|
if (this.#data.users[username]) {
|
|
|
|
return this.#data.users[username];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const db = new localdb();
|