feat(ocr): 添加OCR功能支持及文件类型校验

添加OCR功能钩子useOcr,支持图片文件识别
添加不支持文件类型的错误提示国际化文案
This commit is contained in:
icarus 2025-08-22 15:41:43 +08:00
parent 523ce9b7dc
commit 37d9ff59cc
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import { useAppSelector } from '@renderer/store'
import { ImageFileMetadata, isImageFile } from '@renderer/types'
import { SupportedOcrFile } from '@renderer/types/ocr'
import { useTranslation } from 'react-i18next'
export const useImageOcr = () => {}
export const useOcr = () => {
const { t } = useTranslation()
const imageProvider = useAppSelector((state) => state.ocr.imageProvider)
/**
* OCR识别
* @param image
* @returns OCR识别结果的Promise
*/
const ocrImage = async (image: ImageFileMetadata) => {
return window.api.ocr.ocr(image, imageProvider)
}
/**
* OCR识别
* @param file OCR的文件
* @returns OCR识别结果的Promise
* @throws
*/
const ocr = async (file: SupportedOcrFile) => {
if (isImageFile(file)) {
return ocrImage(file)
}
// @ts-expect-error all types should be covered
throw new Error(t('ocr.file.not_supported', { type: file.type }))
}
return {
ocrImage,
ocr
}
}

View File

@ -1558,6 +1558,11 @@
},
"tip": "如果响应成功则只针对超过30秒的消息进行提醒"
},
"ocr": {
"file": {
"not_supported": "不支持的文件类型 {{type}}"
}
},
"ollama": {
"keep_alive_time": {
"description": "对话后模型在内存中保持的时间默认5 分钟)",