mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
refactor(ocr): move ocr config to shared and add utility function
Migrate ocr configuration from renderer to shared config and introduce getDefaultOcrProvider utility function to centralize default provider logic
This commit is contained in:
parent
61a71a0486
commit
47366064ca
@ -1,8 +1 @@
|
||||
import type { BuiltinOcrProvider, OcrProviderCapability } from '@renderer/types'
|
||||
import { systemOcr, tesseract } from '@shared/config/ocr'
|
||||
|
||||
import { isMac, isWin } from './constant'
|
||||
|
||||
export const DEFAULT_OCR_PROVIDER = {
|
||||
image: isWin || isMac ? systemOcr : tesseract
|
||||
} as const satisfies Record<OcrProviderCapability, BuiltinOcrProvider>
|
||||
// All config are migrated to @shared/config/ocr
|
||||
|
||||
@ -11,7 +11,6 @@ import {
|
||||
isNotSupportedTextDelta,
|
||||
SYSTEM_MODELS
|
||||
} from '@renderer/config/models'
|
||||
import { DEFAULT_OCR_PROVIDER } from '@renderer/config/ocr'
|
||||
import {
|
||||
isSupportArrayContentProvider,
|
||||
isSupportDeveloperRoleProvider,
|
||||
@ -33,6 +32,7 @@ import type {
|
||||
} from '@renderer/types'
|
||||
import { isBuiltinOcrProvider, isSystemProvider, SystemProviderIds } from '@renderer/types'
|
||||
import { getDefaultGroupName, getLeadingEmoji, runAsyncFunction, uuid } from '@renderer/utils'
|
||||
import { getDefaultOcrProvider } from '@renderer/utils/ocr'
|
||||
import { defaultByPassRules } from '@shared/config/constant'
|
||||
import { BUILTIN_OCR_PROVIDERS } from '@shared/config/ocr'
|
||||
import { BUILTIN_OCR_PROVIDER_CONFIG_MAP, BUILTIN_OCR_PROVIDERS_MAP } from '@shared/config/ocr'
|
||||
@ -2238,7 +2238,7 @@ const migrateConfig = {
|
||||
// @ts-expect-error old migration
|
||||
state.ocr = {
|
||||
providers: BUILTIN_OCR_PROVIDERS,
|
||||
imageProviderId: DEFAULT_OCR_PROVIDER.image.id
|
||||
imageProviderId: getDefaultOcrProvider('image').id
|
||||
}
|
||||
state.translate.translateInput = ''
|
||||
return state
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { PayloadAction } from '@reduxjs/toolkit'
|
||||
import { createSlice } from '@reduxjs/toolkit'
|
||||
import { DEFAULT_OCR_PROVIDER } from '@renderer/config/ocr'
|
||||
import type { BuiltinOcrProviderId, OcrProvider, OcrProviderConfig } from '@renderer/types'
|
||||
import { getDefaultOcrProvider } from '@renderer/utils/ocr'
|
||||
import { BUILTIN_OCR_PROVIDERS } from '@shared/config/ocr'
|
||||
import { BUILTIN_OCR_PROVIDER_CONFIG_MAP } from '@shared/config/ocr'
|
||||
|
||||
@ -19,7 +19,7 @@ const initialState: OcrState = {
|
||||
paddleocr: BUILTIN_OCR_PROVIDER_CONFIG_MAP.paddleocr,
|
||||
ovocr: BUILTIN_OCR_PROVIDER_CONFIG_MAP.ovocr
|
||||
},
|
||||
imageProviderId: DEFAULT_OCR_PROVIDER.image.id
|
||||
imageProviderId: getDefaultOcrProvider('image').id
|
||||
}
|
||||
|
||||
const ocrSlice = createSlice({
|
||||
|
||||
10
src/renderer/src/utils/ocr.ts
Normal file
10
src/renderer/src/utils/ocr.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { isMac, isWin } from '@renderer/config/constant'
|
||||
import type { OcrProviderCapability } from '@renderer/types'
|
||||
import { systemOcr, tesseract } from '@shared/config/ocr'
|
||||
|
||||
export const getDefaultOcrProvider = (cap: OcrProviderCapability) => {
|
||||
switch (cap) {
|
||||
case 'image':
|
||||
return isWin || isMac ? systemOcr : tesseract
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user