From b67b4c817898d5a996baf8c4b48d0b78585ffcec Mon Sep 17 00:00:00 2001 From: icarus Date: Mon, 20 Oct 2025 07:27:09 +0800 Subject: [PATCH] feat(ocr): update provider config by merging with existing values Use lodash merge to combine existing provider config with updates instead of overwriting --- src/main/services/ocr/OcrService.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/services/ocr/OcrService.ts b/src/main/services/ocr/OcrService.ts index 0ea6fd8dd7..3a837fb049 100644 --- a/src/main/services/ocr/OcrService.ts +++ b/src/main/services/ocr/OcrService.ts @@ -11,6 +11,7 @@ import type { } from '@types' import { BuiltinOcrProviderIds } from '@types' import { eq } from 'drizzle-orm' +import { merge } from 'lodash' import type { OcrBaseService } from './builtin/OcrBaseService' import { ovOcrService } from './builtin/OvOcrService' @@ -84,7 +85,18 @@ export class OcrService { if (providers.length == 0) { throw new Error(`OCR provider ${update.id} not found`) } - return { data: providers[0] } + const config = providers[0].config + const newConfig = merge({}, config, update.config) + const [updated] = await dbService + .getDb() + .update(ocrProviderTable) + .set({ + name: update.name, + config: newConfig + }) + .where(eq(ocrProviderTable.id, update.id)) + .returning() + return { data: updated } } public async ocr(file: SupportedOcrFile, params: OcrParams): Promise {