Skip to content

Add plugin 编码小助手 v2.1.1#174

Open
WankkoRee wants to merge 1 commit into
ZToolsCenter:mainfrom
WankkoRee:plugin/utools-fork-codehelper
Open

Add plugin 编码小助手 v2.1.1#174
WankkoRee wants to merge 1 commit into
ZToolsCenter:mainfrom
WankkoRee:plugin/utools-fork-codehelper

Conversation

@WankkoRee
Copy link
Copy Markdown

@WankkoRee WankkoRee commented May 11, 2026

插件信息

  • 名称: 编码小助手
  • 插件ID: utools-fork-codehelper
  • 版本: 2.1.1
  • 描述: 时间转换、base64编解码、URL编解码、哈希加密、Unicode、UUID、进制转换、HTML转义
  • 作者: 福州猿力信息科技有限公司
  • 类型: 新增

本次变更

  • 首次镜像 codehelper 2.1.1

截图 / 演示

image image

自检清单

  • plugin.json 的 name / title / version / description / author 字段均已检查
  • 已移除调试日志、未使用文件、敏感信息(.env、token、密钥等)
  • 本次 PR 的 diff 仅涉及 plugins/utools-fork-codehelper/ 目录
  • 已在本地 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 the utools-fork-codehelper plugin, which is a mirror of the uTools "codehelper" adapted for ZTools. The changes include the plugin configuration, an HTML entry point that maps window.ztools to window.utools, and a preload.js script containing core utility functions for hashing and base64 processing. Feedback for preload.js identifies a logic error in base64EncodeImageFile that could cause multiple callback executions, the use of deprecated new Buffer() APIs, fragile regex handling in imageBase64ToFile, and a recommendation to use fs.createReadStream for standard stream creation.

@@ -0,0 +1 @@
const crypto=require("crypto"),fs=require("fs"),path=require("path");window.services={textHashs:(e,a)=>{const t={};return a?e.forEach((e=>{t[e]=crypto.createHash(e).update(a).digest("hex")})):e.forEach((e=>{t[e]=""})),t},fileHashs:(e,a,t)=>{if(!fs.existsSync(a))return t(null);const o=[];for(const a of e)o.push(crypto.createHash(a));try{const s=fs.ReadStream(a);s.on("data",(e=>{o.forEach((a=>a.update(e)))})),s.on("end",(()=>{const a=o.map((e=>e.digest("hex"))),s={};e.forEach(((e,t)=>{s[e]=a[t]})),t(s)}))}catch(e){t(null)}},base64Encode:e=>Buffer.from(e).toString("base64"),base64EncodeImageFile:(e,a)=>{fs.existsSync(e)||a(null),fs.readFile(e,((t,o)=>{t&&a(null);const s="data:image/"+path.extname(e).replace(".","").toLowerCase()+";base64,";a(s+new Buffer(o).toString("base64"))}))},base64Decode:e=>Buffer.from(e,"base64").toString(),imageBase64ToFile:e=>{const a=Buffer.from(e.replace(/^data:image\/([a-z]+?);base64,/,""),"base64"),t=path.join(window.utools.getPath("downloads"),Date.now()+"."+RegExp.$1);fs.writeFileSync(t,a),window.utools.shellShowItemInFolder(t)}}; No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

preload.js 中发现以下问题:

  1. 逻辑错误: 在 base64EncodeImageFile 中,如果文件不存在或读取出错,回调函数 a(null) 会被调用,但由于缺乏 return 语句且使用了逗号运算符,程序会继续执行 fs.readFile 或后续逻辑,导致回调可能被多次触发,并引发潜在的运行时错误。
  2. API 弃用: new Buffer() 已在 Node.js 中弃用,建议使用 Buffer.from()
  3. 代码健壮性: imageBase64ToFile 依赖全局 RegExp.$1 来获取文件后缀,这在并发或复杂逻辑下非常脆弱。建议使用 .match() 明确获取匹配组。
  4. Stream 创建: 建议使用标准的 fs.createReadStream 代替 fs.ReadStream 构造函数。
Suggested change
const crypto=require("crypto"),fs=require("fs"),path=require("path");window.services={textHashs:(e,a)=>{const t={};return a?e.forEach((e=>{t[e]=crypto.createHash(e).update(a).digest("hex")})):e.forEach((e=>{t[e]=""})),t},fileHashs:(e,a,t)=>{if(!fs.existsSync(a))return t(null);const o=[];for(const a of e)o.push(crypto.createHash(a));try{const s=fs.ReadStream(a);s.on("data",(e=>{o.forEach((a=>a.update(e)))})),s.on("end",(()=>{const a=o.map((e=>e.digest("hex"))),s={};e.forEach(((e,t)=>{s[e]=a[t]})),t(s)}))}catch(e){t(null)}},base64Encode:e=>Buffer.from(e).toString("base64"),base64EncodeImageFile:(e,a)=>{fs.existsSync(e)||a(null),fs.readFile(e,((t,o)=>{t&&a(null);const s="data:image/"+path.extname(e).replace(".","").toLowerCase()+";base64,";a(s+new Buffer(o).toString("base64"))}))},base64Decode:e=>Buffer.from(e,"base64").toString(),imageBase64ToFile:e=>{const a=Buffer.from(e.replace(/^data:image\/([a-z]+?);base64,/,""),"base64"),t=path.join(window.utools.getPath("downloads"),Date.now()+"."+RegExp.$1);fs.writeFileSync(t,a),window.utools.shellShowItemInFolder(t)}};
const crypto=require("crypto"),fs=require("fs"),path=require("path");window.services={textHashs:(e,a)=>{const t={};return a?e.forEach((e=>{t[e]=crypto.createHash(e).update(a).digest("hex")})):e.forEach((e=>{t[e]=""})),t},fileHashs:(e,a,t)=>{if(!fs.existsSync(a))return t(null);const o=[];for(const a of e)o.push(crypto.createHash(a));try{const s=fs.createReadStream(a);s.on("data",(e=>{o.forEach((a=>a.update(e)))})),s.on("end",(()=>{const a=o.map((e=>e.digest("hex"))),s={};e.forEach(((e,t)=>{s[e]=a[t]})),t(s)}))}catch(e){t(null)}},base64Encode:e=>Buffer.from(e).toString("base64"),base64EncodeImageFile:(e,a)=>{if(!fs.existsSync(e))return a(null);fs.readFile(e,((t,o)=>{if(t)return a(null);const s="data:image/"+path.extname(e).replace(".","").toLowerCase()+";base64,";a(s+Buffer.from(o).toString("base64"))}))},base64Decode:e=>Buffer.from(e,"base64").toString(),imageBase64ToFile:e=>{const r=e.match(/^data:image\/([a-z]+?);base64,/);if(!r)return;const a=Buffer.from(e.replace(r[0],""),"base64"),t=path.join(window.utools.getPath("downloads"),Date.now()+"."+r[1]);fs.writeFileSync(t,a),window.utools.shellShowItemInFolder(t)}};

@WankkoRee WankkoRee marked this pull request as ready for review May 11, 2026 13:09
@WankkoRee
Copy link
Copy Markdown
Author

WankkoRee commented May 11, 2026

尝试了已有的插件“开发百宝箱”和“开发加解密编码工具”,但是无奈这两个都没有实现任何匹配指令,也没有复制快捷键,所以只好把 uTools 官方的搬过来了。

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.

1 participant