mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 11:44:28 +08:00
refactor(ocr): use config from useOcrProvider hook directly
Update OCR settings components to use config object returned by useOcrProvider hook instead of accessing it through provider.config. This provides more direct access to the configuration data and improves consistency across components.
This commit is contained in:
parent
a34426d431
commit
b262410518
@ -13,14 +13,14 @@ export const OcrPpocrSettings = () => {
|
||||
const AISTUDIO_URL = 'https://aistudio.baidu.com/pipeline/mine'
|
||||
|
||||
const { t } = useTranslation()
|
||||
const { provider, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.paddleocr)
|
||||
const { provider, config, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.paddleocr)
|
||||
|
||||
if (!isOcrPpocrProvider(provider)) {
|
||||
throw new Error('Not PaddleOCR provider.')
|
||||
}
|
||||
|
||||
const [apiUrl, setApiUrl] = useState<string>(provider.config.apiUrl || '')
|
||||
const [accessToken, setAccessToken] = useState<string>(provider.config.accessToken || '')
|
||||
const [apiUrl, setApiUrl] = useState<string>(config.apiUrl || '')
|
||||
const [accessToken, setAccessToken] = useState<string>(config.accessToken || '')
|
||||
|
||||
const onApiUrlChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value
|
||||
|
||||
@ -19,7 +19,7 @@ export const OcrSystemSettings = () => {
|
||||
const { t } = useTranslation()
|
||||
// 和翻译自定义语言耦合了,应该还ok
|
||||
const { translateLanguages } = useTranslate()
|
||||
const { provider, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.system)
|
||||
const { provider, config, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.system)
|
||||
|
||||
if (!isOcrSystemProvider(provider)) {
|
||||
throw new Error('Not system provider.')
|
||||
@ -29,7 +29,7 @@ export const OcrSystemSettings = () => {
|
||||
throw new Error('Only Windows and MacOS is supported.')
|
||||
}
|
||||
|
||||
const [langs, setLangs] = useState<TranslateLanguageCode[]>(provider.config?.langs ?? [])
|
||||
const [langs, setLangs] = useState<TranslateLanguageCode[]>(config?.langs ?? [])
|
||||
|
||||
// currently static
|
||||
const options = useMemo(
|
||||
|
||||
@ -17,13 +17,13 @@ import { SettingRow, SettingRowTitle } from '..'
|
||||
|
||||
export const OcrTesseractSettings = () => {
|
||||
const { t } = useTranslation()
|
||||
const { provider, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.tesseract)
|
||||
const { provider, config, updateConfig } = useOcrProvider(BuiltinOcrProviderIds.tesseract)
|
||||
|
||||
if (!isOcrTesseractProvider(provider)) {
|
||||
throw new Error('Not tesseract provider.')
|
||||
}
|
||||
|
||||
const [langs, setLangs] = useState<Partial<Record<TesseractLangCode, boolean>>>(provider.config?.langs ?? {})
|
||||
const [langs, setLangs] = useState<Partial<Record<TesseractLangCode, boolean>>>(config?.langs ?? {})
|
||||
const { translateLanguages } = useTranslate()
|
||||
|
||||
const options = useMemo(
|
||||
|
||||
@ -9,10 +9,10 @@ import { isEmbeddingModel, isRerankModel, isTextToImageModel } from '@renderer/c
|
||||
import { LanguagesEnum, UNKNOWN } from '@renderer/config/translate'
|
||||
import { useCodeStyle } from '@renderer/context/CodeStyleProvider'
|
||||
import db from '@renderer/databases'
|
||||
import { useOcr } from '@renderer/hooks/ocr/useOcr'
|
||||
import { useDefaultModel } from '@renderer/hooks/useAssistant'
|
||||
import { useDrag } from '@renderer/hooks/useDrag'
|
||||
import { useFiles } from '@renderer/hooks/useFiles'
|
||||
import { useOcr } from '@renderer/hooks/useOcr'
|
||||
import { useTemporaryValue } from '@renderer/hooks/useTemporaryValue'
|
||||
import { useTimer } from '@renderer/hooks/useTimer'
|
||||
import useTranslate from '@renderer/hooks/useTranslate'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user