added admin dashboard

This commit is contained in:
2026-04-20 12:48:58 +02:00
parent 6145775922
commit d3f740cfa9
56 changed files with 4438 additions and 669 deletions
+29
View File
@@ -0,0 +1,29 @@
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync } from 'node:fs';
import { dirname, join } from 'node:path';
const DATA_DIR = join(process.cwd(), 'data');
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
export function dataPath(name: string): string {
return join(DATA_DIR, name);
}
export function readJson<T>(name: string, fallback: T): T {
const p = dataPath(name);
if (!existsSync(p)) return fallback;
try {
return JSON.parse(readFileSync(p, 'utf8')) as T;
} catch {
return fallback;
}
}
export function writeJson<T>(name: string, value: T): void {
const p = dataPath(name);
const dir = dirname(p);
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
const tmp = `${p}.tmp`;
writeFileSync(tmp, JSON.stringify(value, null, 2), 'utf8');
renameSync(tmp, p);
}