Skip to content

Comments

fix: GM_download 补回 conflictAction#1250

Merged
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:pr-GM_download-conflictAction-2
Feb 15, 2026
Merged

fix: GM_download 补回 conflictAction#1250
CodFrm merged 2 commits intoscriptscat:mainfrom
cyfung1031:pr-GM_download-conflictAction-2

Conversation

@cyfung1031
Copy link
Collaborator

一直漏了还是之前改漏了?不清楚
另外加了新例子

注:新例子使用的是 test/test.png . 目前 1.2 未包含上次 PR #1203 的修改

@CodFrm
Copy link
Member

CodFrm commented Feb 15, 2026

一直漏的

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 主要用于修复内容脚本侧 GM_download 参数透传缺失的问题,把 conflictAction 补回消息传递链路,使后台 chrome.downloads.download 能按期望处理重名文件策略;同时更新示例脚本补充 Blob 下载场景。

Changes:

  • 在 content 侧 GM_download 的两处转发参数中补回 conflictAction
  • 更新 example/gm_download.js,新增 Blob 资源下载示例并展示 conflictAction: 'overwrite'

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/app/service/content/gm_api/gm_api.ts GM_download 转发参数补充 conflictAction,对齐 SW 侧下载选项支持
example/gm_download.js 增加 Blob 下载示例与 conflictAction 使用示例


GM_download({
url: testImageUrl,
name: 'test/test.png', // 储存在 test 资料夹内
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

示例里 name: 'test/test.png' 并注释“储存在 test 资料夹内”,但当前实现会在后台通过 cleanFileName 把 / 替换成 -(因此实际文件名会变成 test-test.png,不会创建子目录)。建议要么改成不含路径分隔符的文件名,要么更新注释/示例以符合实际行为。

Suggested change
name: 'test/test.png', // 储存在 test 资料夹内
name: 'test-test.png', // 使用固定文件名(不会创建子目录)

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AI 有时候聪明过了

Comment on lines 886 to 891
url: url as string,
name: details.name,
headers: details.headers,
saveAs: details.saveAs,
conflictAction: details.conflictAction,
timeout: details.timeout,
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

这次补回了 conflictAction 的透传,但目前看不到对应的自动化测试来防止后续回归(例如校验 content 侧发送的参数、以及 SW 侧最终传给 chrome.downloads.download 的 options 含 conflictAction)。建议补一个用例覆盖 conflictAction=overwrite/uniquify 等至少一个分支。

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +59

GM_download({
url: testImageUrl,
name: 'test/test.png', // 储存在 test 资料夹内
conflictAction: 'overwrite', // 每次都使用固定的档案名
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

这里用 URL.createObjectURL 生成了 blob URL,但示例里没有在下载完成/失败后调用 URL.revokeObjectURL 释放,可能导致页面侧内存与 blob 注册表条目泄漏。建议在 onload/onerror/ontimeout 回调里(或 finally)revoke,并注意不要过早 revoke 以免下载未开始。

Suggested change
GM_download({
url: testImageUrl,
name: 'test/test.png', // 储存在 test 资料夹内
conflictAction: 'overwrite', // 每次都使用固定的档案名
function revokeTestImageUrl() {
URL.revokeObjectURL(testImageUrl);
}
GM_download({
url: testImageUrl,
name: 'test/test.png', // 储存在 test 资料夹内
conflictAction: 'overwrite', // 每次都使用固定的档案名
onload() {
revokeTestImageUrl();
},
onerror() {
revokeTestImageUrl();
},
ontimeout() {
revokeTestImageUrl();
},

Copilot uses AI. Check for mistakes.
@CodFrm CodFrm merged commit 43652e0 into scriptscat:main Feb 15, 2026
8 of 9 checks passed
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