mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 11:44:28 +08:00
refactor(ocr): move provider registration to constructor
Initialize built-in OCR providers during service instantiation instead of after creation for better encapsulation and initialization control
This commit is contained in:
parent
f538e89976
commit
84a513a6ae
@ -13,6 +13,21 @@ const logger = loggerService.withContext('OcrService')
|
||||
export class OcrService {
|
||||
private registry: Map<string, OcrBaseService> = new Map()
|
||||
|
||||
constructor() {
|
||||
// Register built-in providers
|
||||
this.register(BuiltinOcrProviderIds.tesseract, tesseractService)
|
||||
|
||||
if (systemOcrService) {
|
||||
this.register(BuiltinOcrProviderIds.system, systemOcrService)
|
||||
}
|
||||
|
||||
this.register(BuiltinOcrProviderIds.paddleocr, ppocrService)
|
||||
|
||||
if (ovOcrService) {
|
||||
this.register(BuiltinOcrProviderIds.ovocr, ovOcrService)
|
||||
}
|
||||
}
|
||||
|
||||
register(providerId: string, service: OcrBaseService): void {
|
||||
if (this.registry.has(providerId)) {
|
||||
logger.warn(`Provider ${providerId} has existing handler. Overwrited.`)
|
||||
@ -38,16 +53,3 @@ export class OcrService {
|
||||
}
|
||||
|
||||
export const ocrService = new OcrService()
|
||||
|
||||
// Register built-in providers
|
||||
ocrService.register(BuiltinOcrProviderIds.tesseract, tesseractService)
|
||||
|
||||
if (systemOcrService) {
|
||||
ocrService.register(BuiltinOcrProviderIds.system, systemOcrService)
|
||||
}
|
||||
|
||||
ocrService.register(BuiltinOcrProviderIds.paddleocr, ppocrService)
|
||||
|
||||
if (ovOcrService) {
|
||||
ocrService.register(BuiltinOcrProviderIds.ovocr, ovOcrService)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user