pi sills
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user