From 9b63d981b0d9625e3a29d0a1b9f905e22d141fdf Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Sat, 16 May 2026 20:18:32 +0200 Subject: [PATCH] fix(settings): store JSON as string in DB and parse on read\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- app/lib/settings.server.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/lib/settings.server.ts b/app/lib/settings.server.ts index c4bad27..318d1d1 100644 --- a/app/lib/settings.server.ts +++ b/app/lib/settings.server.ts @@ -13,7 +13,14 @@ class SettingsService extends EventEmitter { async init() { if (this.initialized) return; const rows = await prisma.appSetting.findMany(); - rows.forEach(r => this.cache.set(r.key, r.value)); + rows.forEach(r => { + try { + this.cache.set(r.key, JSON.parse(r.value)); + } catch (e) { + // fall back to raw string if parse fails + this.cache.set(r.key, r.value); + } + }); this.initialized = true; } @@ -24,10 +31,11 @@ class SettingsService extends EventEmitter { async set(key: string, value: JSONValue, updatedBy?: string) { if (!this.initialized) await this.init(); + const valueStr = typeof value === 'string' ? value : JSON.stringify(value); await prisma.appSetting.upsert({ where: { key }, - update: { value, updatedBy }, - create: { key, value, updatedBy }, + update: { value: valueStr, updatedBy }, + create: { key, value: valueStr, updatedBy }, }); this.cache.set(key, value); this.emit('update', { key, value });