fix(pikpak): prefer web media link request#2599
Conversation
Use the current web file-detail request shape when media links are enabled, so PikPak returns the same origin media links as the web app. Keep the existing FETCH request path when media links are disabled, and prefer origin/default media links when selecting a media URL.\n\nCo-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jyxjjj
left a comment
There was a problem hiding this comment.
Please do not tamper with the PR template.
Thanks for the reminder! I have restored the PR description to follow the template! |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the PikPak driver’s link-generation logic to improve media link selection and adjust the request used to fetch file metadata.
Changes:
- Split
Link()behavior based onDisableMediaLink, changing request URL/headers accordingly. - Add
pickMediaLink()helper to choose a better media URL (origin/default/any). - Replace “first media only” selection with prioritized iteration across available medias.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.net/drive/v1/files/%s", file.GetID()), | ||
| http.MethodGet, func(req *resty.Request) { | ||
| req.SetContext(ctx). | ||
| SetQueryParams(queryParams) | ||
| }, &resp) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| url = resp.WebContentLink | ||
| } else { | ||
| _, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.com/drive/v1/files/%s", file.GetID()), | ||
| http.MethodGet, func(req *resty.Request) { | ||
| req.SetContext(ctx). | ||
| SetHeader("Accept", "*/*"). | ||
| SetHeader("Content-Type", "application/json"). | ||
| SetHeader("Referer", "https://mypikpak.com/"). | ||
| SetHeader("Origin", "https://mypikpak.com") | ||
| }, &resp) |
| if d.DisableMediaLink { | ||
| queryParams := map[string]string{ | ||
| "_magic": "2021", | ||
| "usage": "FETCH", | ||
| "thumbnail_size": "SIZE_LARGE", | ||
| } | ||
| _, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.net/drive/v1/files/%s", file.GetID()), | ||
| http.MethodGet, func(req *resty.Request) { | ||
| req.SetContext(ctx). | ||
| SetQueryParams(queryParams) | ||
| }, &resp) |
| func pickMediaLink(medias []Media) string { | ||
| for _, media := range medias { | ||
| if media.IsOrigin && media.Link.Url != "" { | ||
| return media.Link.Url | ||
| } | ||
| } | ||
| for _, media := range medias { | ||
| if media.IsDefault && media.Link.Url != "" { | ||
| return media.Link.Url | ||
| } | ||
| } | ||
| for _, media := range medias { | ||
| if media.Link.Url != "" { | ||
| return media.Link.Url | ||
| } | ||
| } | ||
| return "" | ||
| } |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Thanks for the assessment! I agree that this relies on the current PikPak Web behavior, and I understand the maintenance risk here. My understanding is that this is also an inherent risk of the PikPak driver itself, since it already depends on non-public PikPak APIs/client behavior. One example is that the previous implementation was still using the older The request shape used in this PR has been packet captured and verified from the current PikPak Web traffic. In my testing, the previous For the |
Summary / 摘要
This PR updates the PikPak media-link request path to match the current PikPak Web behavior when media links are enabled.
disable_media_linkisfalse, file details are requested with the current web-style request shape instead of forcingusage=CACHE.usage=FETCH/web_content_linkpath is preserved.In my testing, the previous
usage=CACHEmedia-link request could only returndl-z01a-*.mypikpak.*links. Those links were limited to about 12 MB/s in my environment. Thez01ahosts resolved to a Singapore ByteDance data center.After this change, PikPak can return the same origin media links as the official web app, such as
dl-a10b-*.mypikpak.*. In my environment thesea10blinks resolved to Alibaba Cloud and reached about 50 MB/s./ 此 PR 包含破坏性变更。
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
/ 此 PR 需要关联仓库同步修改。
Related repository PRs / 关联仓库 PR:
Related Issues / 关联 Issue
N/A
Testing / 测试
go test ./...go test ./drivers/pikpakdl-a10b-*.mypikpak.*origin media links.dl-z01a-*links to about 50 MB/s ondl-a10b-*links in my environment.web_content_linkbehavior.Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 我已按适用情况使用
gofmt,go fmt或prettier格式化变更代码。/ 我已在适用情况下请求相关维护者或代码所有者审查。
AI Disclosure / AI 使用声明
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
Usage scope / 使用范围:
Code generation / 代码生成
Refactoring / 重构
Documentation / 文档
Tests / 测试
Translation / 翻译
Review assistance / 审查辅助
I have reviewed and validated all AI-assisted content included in this PR.
/ 我已审核并验证此 PR 中的所有 AI 辅助内容。
I have ensured that all AI-assisted commits include
Co-Authored-Byattribution./ 我已确保所有 AI 辅助提交都包含
Co-Authored-By归属信息。I can reproduce all AI-assisted content included in this PR without any AI tools.
/ 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。