Skip to content

fix(pikpak): prefer web media link request#2599

Open
wiskiiii wants to merge 2 commits into
OpenListTeam:mainfrom
wiskiiii:fix/pikpak-web-media-link
Open

fix(pikpak): prefer web media link request#2599
wiskiiii wants to merge 2 commits into
OpenListTeam:mainfrom
wiskiiii:fix/pikpak-web-media-link

Conversation

@wiskiiii

@wiskiiii wiskiiii commented Jun 11, 2026

Copy link
Copy Markdown

Summary / 摘要

This PR updates the PikPak media-link request path to match the current PikPak Web behavior when media links are enabled.

  • When disable_media_link is false, file details are requested with the current web-style request shape instead of forcing usage=CACHE.
  • Media URL selection now prefers:
    1. origin media link
    2. default media link
    3. first available media link
  • When media links are disabled, the existing usage=FETCH / web_content_link path is preserved.

In my testing, the previous usage=CACHE media-link request could only return dl-z01a-*.mypikpak.* links. Those links were limited to about 12 MB/s in my environment. The z01a hosts 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 these a10b links resolved to Alibaba Cloud and reached about 50 MB/s.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend:
  • OpenList-Docs:

Related Issues / 关联 Issue

N/A

Testing / 测试

  • go test ./...
  • go test ./drivers/pikpak
  • Manual test / 手动测试:
    • Built a custom OpenList binary with this change and tested using this change.
    • Verified that PikPak media-link requests can return dl-a10b-*.mypikpak.* origin media links.
    • Verified download speed improved from about 12 MB/s on dl-z01a-* links to about 50 MB/s on dl-a10b-* links in my environment.
    • Verified the disabled-media-link path still uses the normal web_content_link behavior.

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmt, go fmtprettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明):

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-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

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 jyxjjj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not tamper with the PR template.

@wiskiiii

Copy link
Copy Markdown
Author

Please do not tamper with the PR template.

Thanks for the reminder! I have restored the PR description to follow the template!

@wiskiiii wiskiiii marked this pull request as ready for review June 11, 2026 16:22
Copilot AI review requested due to automatic review settings June 11, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 on DisableMediaLink, 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.

Comment thread drivers/pikpak/driver.go
Comment on lines +139 to +156
_, 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)
Comment thread drivers/pikpak/driver.go
Comment on lines +133 to +143
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)
Comment thread drivers/pikpak/driver.go
Comment on lines +172 to +189
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 ""
}
jyxjjj

This comment was marked as outdated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wiskiiii

Copy link
Copy Markdown
Author

Priority assessment:

P2: The implementation now relies on reproducing the current PikPak Web request shape, including endpoint selection and request headers. This introduces coupling to upstream Web behavior. It would be useful to document whether these values were verified from current client traffic and whether there is a fallback strategy if the Web client behavior changes in the future.

P3: pickMediaLink encodes a priority order (origin > default > first available) that appears reasonable, but the rationale is currently implicit in the implementation. A short code comment describing the selection policy would help future maintainers understand why this ordering is preferred.

No P0/P1 issues identified from the reviewed diff.

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 .net API host, while the current Web client traffic uses the .com API host; this PR updates that path as part of aligning the media-link request with the current Web behavior.

The request shape used in this PR has been packet captured and verified from the current PikPak Web traffic. In my testing, the previous usage=CACHE request returned dl-z01a-* media links, while the Web-style file-detail request could return the faster origin dl-a10b-* media link for the same file.

For the pickMediaLink ordering, I have added a short code comment to document the selection policy: prefer origin media first, then the default media, and finally the first available media URL.

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.

5 participants