Repository navigation
Conversation
Author
|
补充本地验证:已在 dev 最新提交上安装依赖并跑完 pnpm typecheck / pnpm lint / pnpm test,全部通过(63 个测试文件、488 个用例),具体命令见 PR 描述里的“测试情况”。 |
This branch has not been deployed
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.
改动类型
是否包含破坏性变更
改动说明
下载落盘时的扩展名推断里,
content-disposition只在流媒体分支被采信,其余来源完全依赖declaredFormat:format,没问题;resolveByPlugin)只返回url,没有declaredFormat,因此只能走Content-Type→ URL 后缀 → 兜底.mp3;QQ 音乐 / 酷狗的内置分支同样只返回{ url }。于是会出现「服务器已经写明文件名是
.flac,保存下来却是.mp3」的情况:插件音源给出的下载地址常常是一个会 302 到 CDN 的接口地址(路径没有后缀),而 CDN 的Content-Type又不在MIME_EXT表里(例如腾讯 CDN 用audio/x-ogg返回 FLAC),最后一档兜底成.mp3——文件内容是 FLAC,名字却是 MP3。这个 PR 把「服务器返回的文件名」提升为所有下载来源的通用信号:
extensionFromDisposition():从content-disposition的filename/filename*里取扩展名,且只接受KNOWN_EXTS内的音频格式,避免把奇怪的参数当成扩展名;req.declaredFormat || extensionFromDisposition(...):平台声明的格式仍然最优先(网易等现有行为不变),缺声明时采信服务器文件名,最后才回退到原有的Content-Type/ URL 后缀推断;改动只作用于扩展名推断,不改变请求、落盘、写标签等流程。
关联 Issue
无(没有找到对应的 issue;如果希望我先开 issue 再关联,请告知)
测试情况
Windows 11、Node 24.15.0、pnpm 12.15.0,基于
dev当前最新提交006c5806:功能验证:
electron/main/utils/filename.ts,按下载器采用的同一表达式(declaredFormat || extensionFromDisposition(...))跑了 10 个用例,含真实抓到的响应头:attachment; filename*=UTF-8''F000004b7rQP486g8d.flac+audio/x-ogg+ 无后缀 URL →.flac(改动前是.mp3)filename="M800004b7rQP486g8d.mp3"+audio/mpeg→.mp3content-disposition→ 仍按 MIME → URL 后缀 →.mp3依次回退,行为与改动前一致track.weird)→ 不采信,继续回退declaredFormat存在时仍然优先(网易官方接口行为不变)https://<site>/plug/down.php?...,服务端响应为content-disposition: attachment; filename*=UTF-8''F000004b7rQP486g8d.flac、content-type: audio/x-ogg、content-length: 20335993;改动后落盘文件名.flac,首字节fLaC,体积与content-length一致。自查清单