Skip to content

[v1.4] 把 fetchIconByDomain 改成 scriptcat.org#1268

Open
cyfung1031 wants to merge 14 commits intoscriptscat:release/v1.4from
cyfung1031:pr-change-fetchIconByDomain
Open

[v1.4] 把 fetchIconByDomain 改成 scriptcat.org#1268
cyfung1031 wants to merge 14 commits intoscriptscat:release/v1.4from
cyfung1031:pr-change-fetchIconByDomain

Conversation

@cyfung1031
Copy link
Collaborator

No description provided.

@CodFrm
Copy link
Member

CodFrm commented Feb 23, 2026

我想了一下,要不要和脚本站分开,这样方便提供更多脚本猫扩展需要的API:

https://ext.scriptcat.org/api/v1/open/favicons?domain=baidu.com&sz=64

@CodFrm
Copy link
Member

CodFrm commented Mar 2, 2026

本地的逻辑应该不用去掉,提供几个icon服务进行选择,放设置里面(具体哪个模块还要思考一下),默认scriptcat,然后本地/google/xxxxx

CodFrm added 2 commits March 11, 2026 21:23
新增图标服务设置项,支持 ScriptCat / 本地获取 / Google 三种 provider,
默认使用 ScriptCat API。切换 provider 时自动清除 favicon 缓存。
同时增加了对接口返回异常状态码(>=300)的处理。
@CodFrm
Copy link
Member

CodFrm commented Mar 11, 2026

想要AI帮我提交回复的,结果理解错了


Summary

  • 新增图标服务设置项,支持 ScriptCat / 本地获取 / Google 三种 provider,默认使用 ScriptCat API
  • 在设置页面「界面」Card 中添加图标服务下拉选择框
  • 切换 provider 时自动清除 favicon 缓存(包括 IndexedDB 和 OPFS)
  • 增加对接口返回异常状态码(>=300)的处理,失败时使用默认图标
  • 添加 zh-CN / zh-TW / en-US / de-DE / ja-JP / ru-RU / vi-VN 多语言翻译

Closes #1268

Test plan

  • 设置页面「界面」Card 中正确显示图标服务选择项
  • 默认选中 ScriptCat,切换为 Local / Google 后保存生效
  • 切换 provider 后脚本列表的 favicon 使用新 provider 重新加载
  • 接口返回错误状态码时显示默认图标而非空白

@cyfung1031 cyfung1031 changed the title 把 fetchIconByDomain 改成 scriptcat.org [v1.4] 把 fetchIconByDomain 改成 scriptcat.org Mar 15, 2026
@cyfung1031 cyfung1031 changed the base branch from release/v1.3 to release/v1.4 March 15, 2026 05:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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();

CodFrm added 5 commits March 16, 2026 14:30
- fetchIconByService 添加 default 分支回退到 local
- 切换服务时清除内存中的 blob URL 缓存
- 使用 deletes() 批量删除替代逐条删除
- setFaviconService 添加 return
- 修复 pre-push 正则匹配 release/ 分支
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.

3 participants