Initial code
This commit is contained in:
commit
1f20a611da
26 changed files with 1050 additions and 0 deletions
25
src/store/store.ts
Normal file
25
src/store/store.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import config from "../config.json" with { type: "json" };
|
||||
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
|
||||
import type { IState } from "./types.js";
|
||||
|
||||
let state: IState = {
|
||||
users: [],
|
||||
};
|
||||
|
||||
const load = () => {
|
||||
if (!existsSync(config.storePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const json = readFileSync(config.storePath).toString();
|
||||
state = JSON.parse(json) as IState;
|
||||
};
|
||||
|
||||
const save = () => {
|
||||
const json = JSON.stringify(state);
|
||||
writeFileSync(config.storePath, json);
|
||||
};
|
||||
|
||||
export { state, load, save };
|
||||
Loading…
Add table
Add a link
Reference in a new issue