This commit is contained in:
2026-02-23 22:52:27 +00:00
parent 8fb96c7cf8
commit 2126f3912e
35 changed files with 1126 additions and 137 deletions
+11 -5
View File
@@ -27,8 +27,11 @@ settingsRouter.get('/settings', async (ctx) => {
const file = Bun.file(filePath);
if (await file.exists()) {
const data = await file.json();
return ctx.json(data);
try {
return ctx.json(await file.json());
} catch {
// corrupted — fall through to defaults
}
}
await ensureDir(filePath);
@@ -54,8 +57,11 @@ settingsRouter.get('/state', async (ctx) => {
const file = Bun.file(filePath);
if (await file.exists()) {
const data = await file.json();
return ctx.json(data);
try {
return ctx.json(await file.json());
} catch {
// corrupted — fall through to empty
}
}
await ensureDir(filePath);
@@ -72,7 +78,7 @@ settingsRouter.patch('/state', async (ctx) => {
let existing: Record<string, unknown> = {};
if (await file.exists()) {
existing = await file.json();
try { existing = await file.json(); } catch { /* corrupted — start fresh */ }
}
const merged = { ...existing, ...body };