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.
This commit is contained in:
icarus 2025-10-20 07:40:31 +08:00
parent a042892250
commit f9ed8343fe
3 changed files with 20 additions and 3 deletions

View File

@ -382,7 +382,8 @@ export interface ApiSchemas {
response: PutOcrProviderResponse
}
DELETE: {
// TODO
params: { id: OcrProviderId }
response: void
}
}
}

View File

@ -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)
}
}
}

View File

@ -143,6 +143,22 @@ export class OcrService {
return { data: updated }
}
public async deleteProvider(providerId: string): Promise<void> {
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<OcrResult> {
const service = this.registry.get(params.providerId)
if (!service) {