aslobot-matrix/src/store/store.ts
2025-12-23 07:56:01 -05:00

29 lines
607 B
TypeScript

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;
}
console.log("loading data...");
const json = readFileSync(config.storePath).toString();
state = JSON.parse(json) as IState;
};
const save = () => {
console.log("saving data...");
const json = JSON.stringify(state);
writeFileSync(config.storePath, json);
};
export { state, load, save };