Skip to content

Add plugin OCR 翻译 v1.0.0#194

Open
MermaidFAR wants to merge 3 commits into
ZToolsCenter:mainfrom
MermaidFAR:plugin/ocr-new
Open

Add plugin OCR 翻译 v1.0.0#194
MermaidFAR wants to merge 3 commits into
ZToolsCenter:mainfrom
MermaidFAR:plugin/ocr-new

Conversation

@MermaidFAR
Copy link
Copy Markdown

@MermaidFAR MermaidFAR commented May 16, 2026

插件信息

  • 名称: OCR 翻译
  • 插件ID: ocr-new
  • 版本: 1.0.0
  • 描述: 识别图片文字并跳转到翻译插件
  • 作者: FAR
  • 类型: 新增

本次变更

  • feat: OCR 翻译插件 v1.0.0 初始版本,支持多引擎图片文字识别

截图 / 演示

Uploading PixPin_2026-05-16_14-53-34.png…

自检清单

  • plugin.json 的 name / title / version / description / author 字段均已检查
  • 已移除调试日志、未使用文件、敏感信息(.env、token、密钥等)
  • 本次 PR 的 diff 仅涉及 plugins/ocr-new/ 目录
  • 已在本地 ZTools 客户端实际加载并测试过此插件,主要功能正常
  • 同意以仓库声明的开源协议发布此插件

此 PR 由 ztools-plugin-cli 自动管理:每次 ztools publish 在分支上追加一个 commit,PR 链接保持不变。

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new OCR translation plugin for ZTools, featuring a Vue 3 frontend and a Python-based local OCR server using RapidOCR. The plugin supports various cloud providers and a local engine with pre-processing capabilities. Feedback focused on improving the robustness of the Python server's header parsing, preventing UI blocking by using asynchronous file operations in the Electron preload script, and enhancing type safety by enabling strict mode in the TypeScript configuration.

return

try:
content_length = int(self.headers.get("Content-Length", "0"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

直接使用 int() 转换 Content-Length 可能会因为请求头缺失或格式非法而抛出 ValueError。建议增加校验或异常处理以提高服务器的健壮性。

Suggested change
content_length = int(self.headers.get("Content-Length", "0"))
cl_header = self.headers.get("Content-Length", "0")
content_length = int(cl_header) if cl_header.isdigit() else 0

readImageAsDataUrl(file) {
const ext = path.extname(file).slice(1).toLowerCase()
const mimeType = imageMimeTypes[ext] || 'application/octet-stream'
const base64 = fs.readFileSync(file).toString('base64')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在 Electron 环境中,fs.readFileSync 是同步阻塞操作。如果读取的图片文件较大,会直接导致渲染进程 UI 冻结,影响用户体验。建议改用异步的 fs.promises.readFile 并将 readImageAsDataUrl 设为 async 函数,同时更新调用方(如 index.vue 中的 loadImageFromFile)。

Comment on lines +14 to +15
"strict": false,
"noImplicitAny": false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

对于新创建的 TypeScript 项目,建议开启 strict 模式。当前的配置关闭了严格检查并允许隐式的 any 类型,这会降低类型系统的保护作用,增加维护成本。开启 strict: true 会自动包含 noImplicitAny 等多项安全检查。

Suggested change
"strict": false,
"noImplicitAny": false,
"strict": true,

@MermaidFAR
Copy link
Copy Markdown
Author

MermaidFAR commented May 16, 2026

插件信息

  • 名称: OCR 翻译
  • 插件ID: ocr-new  插件 ID: ocr-new
  • 版本: 1.0.0
  • 描述: 识别图片文字并跳转到翻译插件
  • 作者: FAR
  • 类型: 新增

本次变更

  • feat: OCR 翻译插件 v1.0.0 初始版本,支持多引擎图片文字识别

截图 / 演示

Uploading PixPin_2026-05-16_03-54-34.png…

自检清单

  • plugin.json 的 name / title / version / description / author 字段均已检查
  • 已移除调试日志、未使用文件、敏感信息(.env、token、密钥等)
  • 本次 PR 的 diff 仅涉及 plugins/ocr-new/ 目录
  • 已在本地 ZTools 客户端实际加载并测试过此插件,主要功能正常
  • 同意以仓库声明的开源协议发布此插件

此 PR 由 ztools-plugin-cli 自动管理:每次 ztools publish 在分支上追加一个 commit,PR 链接保持不变。

@MermaidFAR MermaidFAR marked this pull request as ready for review May 16, 2026 06:56
@lzx8589561
Copy link
Copy Markdown
Contributor

感谢佬的贡献,经测试发现两个问题

  1. logo不能使用默认图标,可以尝试ai生成svg图标转png
  2. 点击一键安装报错如下,mac环境
image

@MermaidFAR
Copy link
Copy Markdown
Author

MermaidFAR commented May 17, 2026 via email

- feat: OCR 翻译插件 v1.0.0 初始版本,支持多引擎图片文字识别
- fix: 修复 macOS onnxruntime 兼容性,移除 Python 一键安装,纯内置 RapidOCR 运行时,新增 Logo
- feat: OCR 翻译插件 v1.0.0 初始版本,支持多引擎图片文字识别
- fix: 修复 macOS onnxruntime 兼容性,移除 Python 一键安装,纯内置 RapidOCR 运行时,新增 Logo
- fix: 修复 macOS/Linux 构建脚本,使用真实 OCR 服务代码
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants