Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(ocr): unnecessary initialization logic
Elian Doranc55aa6ee886f
diff --git a/apps/server/src/services/ocr/ocr_service.ts b/apps/server/src/services/ocr/ocr_service.tsindex a2b64beeab..1e47b7e650 100644--- a/apps/server/src/services/ocr/ocr_service.ts+++ b/apps/server/src/services/ocr/ocr_service.ts@@ -35,34 +35,16 @@ interface OCRBlobRow {* Uses Tesseract.js for text recognition*/class OCRService {- private isInitialized = false;private worker: Tesseract.Worker | null = null;private isProcessing = false;private processors: Map<string, FileProcessor> = new Map();- /**- * Initialize the OCR service- */- async initialize(): Promise<void> {- if (this.isInitialized) {- return;- }-- try {- log.info('Initializing OCR service with file processors...');-- // Initialize file processors- this.processors.set('image', new ImageProcessor());- this.processors.set('pdf', new PDFProcessor());- this.processors.set('tiff', new TIFFProcessor());- this.processors.set('office', new OfficeProcessor());-- this.isInitialized = true;- log.info('OCR service initialized successfully');- } catch (error) {- log.error(`Failed to initialize OCR service: ${error}`);- throw error;- }+ constructor() {+ // Initialize file processors+ this.processors.set('image', new ImageProcessor());+ this.processors.set('pdf', new PDFProcessor());+ this.processors.set('tiff', new TIFFProcessor());+ this.processors.set('office', new OfficeProcessor());}/**@@ -101,10 +83,6 @@ class OCRService {* Extract text from file buffer using appropriate processor*/async extractTextFromFile(fileBuffer: Buffer, mimeType: string, options: OCRProcessingOptions = {}): Promise<OCRResult> {- if (!this.isInitialized) {- await this.initialize();- }-try {log.info(`Starting OCR text extraction for MIME type: ${mimeType}`);this.isProcessing = true;@@ -143,10 +121,6 @@ class OCRService {return null;}- if (!this.isInitialized) {- await this.initialize();- }-// Check if note type and MIME type are supported for OCRif (note.type === 'image') {if (!this.isSupportedMimeType(note.mime)) {@@ -205,10 +179,6 @@ class OCRService {return null;}- if (!this.isInitialized) {- await this.initialize();- }-// Check if attachment role and MIME type are supported for OCRif (attachment.role === 'image') {if (!this.isSupportedMimeType(attachment.mime)) {@@ -422,7 +392,6 @@ class OCRService {await this.worker.terminate();this.worker = null;}- this.isInitialized = false;log.info('OCR service cleaned up');}@@ -563,32 +532,6 @@ class OCRService {getAllSupportedMimeTypes(): string[] {const supportedTypes = new Set<string>();- // Initialize processors if not already done- if (!this.isInitialized) {- // Return a static list if not initialized to avoid async issues- // This covers all known supported types- return [- // Images- 'image/jpeg',- 'image/jpg',- 'image/png',- 'image/gif',- 'image/bmp',- 'image/tiff',- 'image/tif',- 'image/webp',- // Documents- 'application/pdf',- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',- 'application/vnd.openxmlformats-officedocument.presentationml.presentation',- 'application/msword',- 'application/vnd.ms-excel',- 'application/vnd.ms-powerpoint',- 'application/rtf'- ];- }-// Gather MIME types from all registered processorsfor (const processor of this.processors.values()) {const processorTypes = processor.getSupportedMimeTypes();