fix various formatting,

add interface for generic backends,
add interfaces for DB and AUTH type backends,
implement basic user password change method
This commit is contained in:
2024-01-09 00:47:33 +00:00
parent a0109d3546
commit b27172dd9e
11 changed files with 156 additions and 52 deletions

View File

@@ -1,11 +1,14 @@
import { readFileSync, writeFileSync } from "fs";
import { exit } from "process";
import { DB_BACKEND } from "./backends.js";
export default class LocalDB {
export default class LocalDB extends DB_BACKEND {
#path = null;
#data = null;
#defaultuser = null;
constructor (config) {
super();
const path = config.dbfile;
try {
this.#path = path;
@@ -13,7 +16,7 @@ export default class LocalDB {
this.#defaultuser = global.config.defaultuser;
}
catch {
console.log(`Error: ${path} was not found. Please follow the directions in the README to initialize localdb.json.`);
console.log(`error: ${path} was not found. Please follow the directions in the README to initialize localdb.json.`);
exit(1);
}
}
@@ -32,6 +35,10 @@ export default class LocalDB {
writeFileSync(this.#path, JSON.stringify(this.#data));
}
openSession (credentials) { return [] }
closeSesssion (tokens) {return true }
addUser (username, config = null) {
config = config || this.#defaultuser;
this.#data.users[username] = config;