From 5d7e8ce7735dddbd5e4c38ecb97cd8a029fc35f8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Jun 2026 18:39:30 +0800 Subject: [PATCH] fix: allow system setting writes from jobs --- lib/db/queries.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/db/queries.ts b/lib/db/queries.ts index d37ea9621..067a7f7e1 100644 --- a/lib/db/queries.ts +++ b/lib/db/queries.ts @@ -3668,6 +3668,15 @@ export async function getAllSystemSettings() { } } +function normalizeSystemSettingUpdatedBy(updatedBy: string | null | undefined) { + const normalized = String(updatedBy || "").trim(); + return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test( + normalized + ) + ? normalized + : null; +} + export async function upsertSystemSetting({ key, value, @@ -3675,22 +3684,24 @@ export async function upsertSystemSetting({ }: { key: string; value: any; - updatedBy: string; + updatedBy: string | null | undefined; }) { + const normalizedUpdatedBy = normalizeSystemSettingUpdatedBy(updatedBy); + try { return await db .insert(systemSettings) .values({ key, value, - updatedBy, + updatedBy: normalizedUpdatedBy, updatedAt: new Date(), }) .onConflictDoUpdate({ target: systemSettings.key, set: { value, - updatedBy, + updatedBy: normalizedUpdatedBy, updatedAt: new Date(), }, })