From f9ed8343fe2ed4390aed6a7cb6a39687e0e365bc Mon Sep 17 00:00:00 2001 From: icarus Date: Mon, 20 Oct 2025 07:40:31 +0800 Subject: [PATCH] feat(ocr): implement delete provider API endpoint Add DELETE endpoint for OCR providers with proper type definitions and handler implementation. The endpoint removes the provider from both the registry and database after validation checks. --- packages/shared/data/api/apiSchemas.ts | 3 ++- src/main/data/api/handlers/index.ts | 4 ++-- src/main/services/ocr/OcrService.ts | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/shared/data/api/apiSchemas.ts b/packages/shared/data/api/apiSchemas.ts index f183b107aa..b1f07618b2 100644 --- a/packages/shared/data/api/apiSchemas.ts +++ b/packages/shared/data/api/apiSchemas.ts @@ -382,7 +382,8 @@ export interface ApiSchemas { response: PutOcrProviderResponse } DELETE: { - // TODO + params: { id: OcrProviderId } + response: void } } } diff --git a/src/main/data/api/handlers/index.ts b/src/main/data/api/handlers/index.ts index ae887d4d29..d0ea4f2447 100644 --- a/src/main/data/api/handlers/index.ts +++ b/src/main/data/api/handlers/index.ts @@ -230,8 +230,8 @@ export const apiHandlers: ApiImplementation = { PUT: async ({ body }) => { return ocrService.putProvider(body) }, - DELETE: async () => { - throw new Error('Not implemented') + DELETE: async ({ params }) => { + return ocrService.deleteProvider(params.id) } } } diff --git a/src/main/services/ocr/OcrService.ts b/src/main/services/ocr/OcrService.ts index 836d6fa764..7946b14066 100644 --- a/src/main/services/ocr/OcrService.ts +++ b/src/main/services/ocr/OcrService.ts @@ -143,6 +143,22 @@ export class OcrService { return { data: updated } } + public async deleteProvider(providerId: string): Promise { + if (!this.registry.has(providerId)) { + throw new Error(`OCR provider ${providerId} is not registered`) + } + const providers = await dbService + .getDb() + .select() + .from(ocrProviderTable) + .where(eq(ocrProviderTable.id, providerId)) + .limit(1) + if (providers.length === 0) { + throw new Error(`OCR provider ${providerId} not found`) + } + await dbService.getDb().delete(ocrProviderTable).where(eq(ocrProviderTable.id, providerId)) + } + public async ocr(file: SupportedOcrFile, params: OcrParams): Promise { const service = this.registry.get(params.providerId) if (!service) {