From ed791a3bb3f8094d313f7c1137859d776f28947c Mon Sep 17 00:00:00 2001 From: icarus Date: Mon, 20 Oct 2025 00:34:34 +0800 Subject: [PATCH] refactor(ocr): replace manual type check with zod schema validation Simplify type checking logic by using zod schema validation instead of manual type checks for OcrProviderApiConfig --- src/renderer/src/types/ocr.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/renderer/src/types/ocr.ts b/src/renderer/src/types/ocr.ts index cf56ac1cb8..ecca47fc46 100644 --- a/src/renderer/src/types/ocr.ts +++ b/src/renderer/src/types/ocr.ts @@ -54,22 +54,16 @@ export type OcrModel = z.infer /** * Extend this type to define provider-specefic config types. */ -export type OcrProviderApiConfig = { - apiKey: string - apiHost: string - apiVersion?: string -} +export const OcrProviderApiConfigSchema = z.object({ + apiKey: z.string(), + apiHost: z.string(), + apiVersion: z.string().optional() +}) + +export type OcrProviderApiConfig = z.infer export const isOcrProviderApiConfig = (config: unknown): config is OcrProviderApiConfig => { - return ( - typeof config === 'object' && - config !== null && - 'apiKey' in config && - typeof config.apiKey === 'string' && - 'apiHost' in config && - typeof config.apiHost === 'string' && - (!('apiVersion' in config) || typeof config.apiVersion === 'string') - ) + return OcrProviderApiConfigSchema.safeParse(config).success } /**