[v1.4] 把 fetchIconByDomain 改成 scriptcat.org#1268
Open
cyfung1031 wants to merge 14 commits intoscriptscat:release/v1.4from
Open
[v1.4] 把 fetchIconByDomain 改成 scriptcat.org#1268cyfung1031 wants to merge 14 commits intoscriptscat:release/v1.4from
cyfung1031 wants to merge 14 commits intoscriptscat:release/v1.4from
Conversation
Member
|
我想了一下,要不要和脚本站分开,这样方便提供更多脚本猫扩展需要的API: https://ext.scriptcat.org/api/v1/open/favicons?domain=baidu.com&sz=64 |
Member
|
本地的逻辑应该不用去掉,提供几个icon服务进行选择,放设置里面(具体哪个模块还要思考一下),默认scriptcat,然后本地/google/xxxxx |
新增图标服务设置项,支持 ScriptCat / 本地获取 / Google 三种 provider, 默认使用 ScriptCat API。切换 provider 时自动清除 favicon 缓存。 同时增加了对接口返回异常状态码(>=300)的处理。
Member
|
想要AI帮我提交回复的,结果理解错了 Summary
Closes #1268 Test plan
|
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 主要围绕“脚本列表 favicon 获取”做改造:新增可配置的 favicon 获取服务(默认 ScriptCat),并在设置页提供切换入口;同时补充了开发流程(husky pre-push)与 e2e 稳定性改进。
Changes:
- 新增
favicon_service系统配置项与设置页下拉选择,并在切换时清理 favicon 缓存(storage + OPFS)。 - favicon 获取逻辑抽象为按服务获取(scriptcat/google/local),脚本列表加载时按配置选择服务。
- 引入 Husky pre-push 钩子(仅 main/release* 推送时跑 lint+test),并减少 e2e 中固定等待带来的不稳定。
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pkg/config/config.ts | 新增 FaviconService 类型与 get/setFaviconService 配置读写接口 |
| src/pages/store/favicons.ts | 新增按服务获取 favicon 的入口;调用链扩展传入 service;增强下载状态码判断 |
| src/pages/options/routes/Setting.tsx | 设置页新增 favicon 服务选择,并在切换时清理缓存 |
| src/pages/options/routes/ScriptList/hooks.tsx | 脚本列表加载 favicon 时读取系统配置并传入 service |
| src/locales/*/translation.json | 新增设置项相关文案多语言键值 |
| package.json | 增加 husky 依赖与 prepare 脚本 |
| pnpm-lock.yaml | 锁文件更新以包含 husky |
| e2e/utils.ts | Monaco 注入/保存流程改为基于条件等待,减少固定延迟 |
| e2e/gm-api.spec.ts | 等待 service worker/Chrome API 的方式更稳健,控制台结果收集更快 |
| .husky/pre-push | 新增推送前检查脚本(按目标分支选择性执行) |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
src/pages/store/favicons.ts:262
- loadFavicon 在 create:true 创建文件后,如果 fetch(iconUrl) 发生网络异常/被中断,会直接抛出并留下一个 0 字节的占位文件;之后再次加载会命中文件存在分支,生成空的 blobUrl,导致图标永久损坏直到手动清缓存。建议把下载+写入包在 try/catch 中,任意异常时都 removeEntry(filename) 做清理(包括 response.blob()/createWritable/write/close 失败)。
// 文件不存在,下载并保存
const newFileHandle = await directoryHandle.getFileHandle(filename, { create: true });
const response = await fetch(iconUrl);
if (response.status >= 300) {
// 状态码异常,删除创建的空文件并抛出错误
await directoryHandle.removeEntry(filename).catch(() => {});
throw new Error(`Favicon fetch failed with status ${response.status}`);
}
const blob = await response.blob();
const writable = await newFileHandle.createWritable();
await writable.write(blob);
await writable.close();
- fetchIconByService 添加 default 分支回退到 local - 切换服务时清除内存中的 blob URL 缓存 - 使用 deletes() 批量删除替代逐条删除 - setFaviconService 添加 return - 修复 pre-push 正则匹配 release/ 分支
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.