From 78973e3fbf48a7380468bda4b5c035784bfeaa29 Mon Sep 17 00:00:00 2001 From: jacy <18049821889@163.com> Date: Mon, 27 Jul 2026 23:19:54 +0800 Subject: [PATCH] fix(api): seed empty system settings from env including Tencent LBS key Co-authored-by: Cursor --- .../system-config/system-config.service.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/server/dukang-api/src/common/system-config/system-config.service.ts b/server/dukang-api/src/common/system-config/system-config.service.ts index 7c29c5a..bc54729 100644 --- a/server/dukang-api/src/common/system-config/system-config.service.ts +++ b/server/dukang-api/src/common/system-config/system-config.service.ts @@ -184,16 +184,22 @@ export class SystemConfigService implements OnModuleInit { async importFromProcessEnv(): Promise<{ imported: number }> { let imported = 0; + const overlay: Record = {}; for (const field of SYSTEM_CONFIG_FIELDS) { const envVal = process.env[field.key]; if (envVal === undefined || envVal === '') continue; + const normalized = this.normalizeByMeta(field, envVal); const existing = await this.prisma.systemConfig.findUnique({ where: { configKey: field.key } }); - if (existing) continue; - await this.prisma.systemConfig.create({ - data: { configKey: field.key, value: this.normalizeByMeta(field, envVal) }, + if (existing?.value?.trim()) continue; + await this.prisma.systemConfig.upsert({ + where: { configKey: field.key }, + create: { configKey: field.key, value: normalized }, + update: { value: normalized }, }); + overlay[field.key] = normalized; imported += 1; } + if (imported) applyEnvOverlay(overlay); await this.onModuleInit(); return { imported }; } @@ -208,12 +214,15 @@ export class SystemConfigService implements OnModuleInit { private async seedMissingFromProcessEnv() { for (const field of SYSTEM_CONFIG_FIELDS) { - const existing = await this.prisma.systemConfig.findUnique({ where: { configKey: field.key } }); - if (existing) continue; const envVal = process.env[field.key]; if (envVal === undefined || envVal === '') continue; - await this.prisma.systemConfig.create({ - data: { configKey: field.key, value: this.normalizeByMeta(field, envVal) }, + const existing = await this.prisma.systemConfig.findUnique({ where: { configKey: field.key } }); + if (existing?.value?.trim()) continue; + const value = this.normalizeByMeta(field, envVal); + await this.prisma.systemConfig.upsert({ + where: { configKey: field.key }, + create: { configKey: field.key, value }, + update: { value }, }); } }