mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
support cn data
This commit is contained in:
parent
864a4c4180
commit
cda0686f1d
@ -199,7 +199,7 @@ export enum FeedUrl {
|
|||||||
|
|
||||||
export const tesseractLangs = ['chi_sim', 'chi_tra', 'eng']
|
export const tesseractLangs = ['chi_sim', 'chi_tra', 'eng']
|
||||||
export enum TesseractLangsDownloadUrl {
|
export enum TesseractLangsDownloadUrl {
|
||||||
CN = 'https://gitcode.com/beyondkmp/tessdata/blob/main/',
|
CN = 'https://gitcode.com/beyondkmp/tessdata/releases/download/4.1.0/',
|
||||||
GLOBAL = 'https://github.com/tesseract-ocr/tessdata/raw/main/'
|
GLOBAL = 'https://github.com/tesseract-ocr/tessdata/raw/main/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { loggerService } from '@logger'
|
|||||||
import { getIpCountry } from '@main/utils/ipService'
|
import { getIpCountry } from '@main/utils/ipService'
|
||||||
import { TesseractLangsDownloadUrl } from '@shared/config/constant'
|
import { TesseractLangsDownloadUrl } from '@shared/config/constant'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import Tesseract, { createWorker } from 'tesseract.js'
|
import Tesseract, { createWorker } from 'tesseract.js'
|
||||||
|
|
||||||
@ -120,7 +121,8 @@ export class TesseractService {
|
|||||||
// for now, only support limited languages
|
// for now, only support limited languages
|
||||||
this.worker = await createWorker(['chi_sim', 'chi_tra', 'eng'], undefined, {
|
this.worker = await createWorker(['chi_sim', 'chi_tra', 'eng'], undefined, {
|
||||||
langPath: await this._getLangPath(),
|
langPath: await this._getLangPath(),
|
||||||
cachePath: this._getCacheDir(),
|
cachePath: await this._getCacheDir(),
|
||||||
|
gzip: false,
|
||||||
logger: (m) => logger.debug('From worker', m)
|
logger: (m) => logger.debug('From worker', m)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -132,8 +134,12 @@ export class TesseractService {
|
|||||||
return country.toLowerCase() === 'cn' ? TesseractLangsDownloadUrl.CN : TesseractLangsDownloadUrl.GLOBAL
|
return country.toLowerCase() === 'cn' ? TesseractLangsDownloadUrl.CN : TesseractLangsDownloadUrl.GLOBAL
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getCacheDir(): string {
|
private async _getCacheDir(): Promise<string> {
|
||||||
return path.join(app.getPath('userData'), 'tesseract')
|
const cacheDir = path.join(app.getPath('userData'), 'tesseract')
|
||||||
|
if (!fs.existsSync(cacheDir)) {
|
||||||
|
await fs.promises.mkdir(cacheDir, { recursive: true })
|
||||||
|
}
|
||||||
|
return cacheDir
|
||||||
}
|
}
|
||||||
|
|
||||||
async dispose(): Promise<void> {
|
async dispose(): Promise<void> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user