diff --git a/service/src/main.ts b/service/src/main.ts index bc63db3..2df7fd2 100644 --- a/service/src/main.ts +++ b/service/src/main.ts @@ -5,6 +5,7 @@ import { routeMessage } from './common/router'; import { VSCodeWebViewLike } from './hook/adapter'; import path from 'node:path'; import * as fs from 'node:fs'; +import { setRunningCWD } from './hook/setting'; export interface VSCodeMessage { command: string; @@ -94,6 +95,9 @@ function updateConnectionOption(data: any) { } } +const devHome = path.join(__dirname, '..', '..'); +setRunningCWD(devHome); + wss.on('connection', ws => { // 仿造 webview 进行统一接口访问 diff --git a/service/src/mcp/ocr.service.ts b/service/src/mcp/ocr.service.ts index 74058f5..91225ce 100644 --- a/service/src/mcp/ocr.service.ts +++ b/service/src/mcp/ocr.service.ts @@ -47,17 +47,23 @@ export async function tesseractOCR( logger: (message: Tesseract.LoggerMessage) => void, lang: string = 'eng+chi_sim' ) { - + const ocrHome = path.join(RUNNING_CWD, 'resources', 'ocr'); + + if (!ocrHome) { + console.log('ocr 目录不存在'); + return '安装包已经损坏'; + } + try { const { data: { text } } = await Tesseract.recognize( imagePath, lang, { logger, - langPath: './', gzip: false, - cacheMethod: 'cache', - cachePath: RUNNING_CWD + langPath: ocrHome, + corePath: ocrHome, + workerPath: path.join(ocrHome, 'worker.js'), } ); diff --git a/src/hook/hook.controller.ts b/src/hook/hook.controller.ts index 551ff8d..dfa582e 100644 --- a/src/hook/hook.controller.ts +++ b/src/hook/hook.controller.ts @@ -14,8 +14,9 @@ export class HookController { console.log('test ocr begin'); const cachePath = context.extensionPath; - const workerPath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.js'); - const corePath = path.join(cachePath, 'resources', 'ocr', 'tesseract-core.wasm'); + const workerPath = path.join(cachePath, 'resources', 'ocr', 'worker.js'); + const corePath = path.join(cachePath, 'resources', 'ocr'); + const langPath = path.join(cachePath,'resources', 'ocr'); console.log('workerPath', workerPath); console.log('corePath', corePath); @@ -26,10 +27,8 @@ export class HookController { 'eng+chi_sim', { logger: (m) => console.log(m), - langPath: './', + langPath, gzip: false, - cacheMethod: 'cache', - cachePath, workerPath, corePath }