Skip to content

fix(download): preserve storage mount names when stripping route prefixes - #59

Merged
PIKACHUIM merged 1 commit into
OpenListTeam:mainfrom
karuboniru:fix/download-path-prefix
Sep 16, 2026
Merged

PIKACHUIM merged 1 commit into
OpenListTeam:mainfrom
karuboniru:fix/download-path-prefix

Conversation

@karuboniru

Copy link
Copy Markdown
Contributor

Summary / 摘要

Fix downloads failing with Not found: failed get storage: storage not found for mount names such as /pikpak_webdav, while directory browsing continues to work.

For example, GET /d/pikpak_webdav/My%20Upload/Screenshot_2024-08-06-07-49-33-68.jpg first loses the /d prefix, then the chained replacements also remove /p from the mount name. The resulting ikpak_webdav/... path cannot match the configured storage.

Replace the chained replacements with one anchored expression, /^\/(?:api\/)?(?:raw|sd|d|p)(?=\/|$)/, which removes exactly one complete route prefix. This preserves the mount name and supports both the short routes and their /api variants. Existing URL decoding remains in place.

  • This PR has breaking changes.
  • This PR changes public API, config, storage format, or migration behavior.
  • This PR requires corresponding changes in related repositories.

Testing / 测试

  • Manual test: the reporter confirmed that the fix works as expected for the affected download on Cloudflare.
  • git diff --check
  • Automated tests were not added or run, at the reporter's request.

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
  • Tool: Codex.
  • Scope: diagnosis, code change, and PR description. The reporter manually verified the resulting fix.

Copilot AI lite review requested due to automatic review settings September 15, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review comments remain.

Pull request overview

Fixes download path normalization so storage mount names like /pikpak_webdav remain intact.

Changes:

  • Replaces chained prefix stripping with one anchored expression.
  • Supports short and /api routes.
  • Retains URL decoding.
File summaries
File Description
src/backend/server/raw.ts Corrects download route-prefix normalization.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🙏 感谢 @karuboniru 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
⚠️ AI 分析结果仅供参考,可能存在误判或遗漏。如您发现任何问题或有不同意见,欢迎随时提出讨论和纠正。
⚠️ 重要提醒:即使 AI 评审认为代码质量良好且建议合并,最终是否合并仍需由项目维护者进行人工判定。项目维护者会综合考虑代码质量、项目规划、技术方向、团队资源等多方面因素做出是否合并的决策。

🎯 结论

✅ Approve — 精准修复路由前缀处理缺陷,逻辑严谨且无副作用

📖 概要

fix(download): preserve storage mount names when stripping route prefixes · 修复下载路径中存储挂载名被错误截断的问题
核心改动:将多次链式 .replace() 替换为一次锚定正则表达式,精确移除路由前缀同时保留挂载名

🧭 整体方案

采用正则锚定匹配(/^\/(?:api\/)?(?:raw|sd|d|p)(?=\/|$)/)一次性移除完整路由前缀,避免链式替换的逐字符匹配副作用。方案合理,完美解决了 /pikpak_webdav 被错误处理为 /ikpak_webdav 的问题。

📊 变更统计

1 个文件(+5 / -9 行) | 功能 ⭐⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐⭐⭐ | 前向兼容 ⭐⭐⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐⭐

🚨 关键问题

无重大问题

📂 逐文件分析

src/backend/server/raw.ts

改动意图:修复下载路径处理中存储挂载名被意外截断的 bug
代码逻辑:原先使用 8 次链式 .replace() 依次移除路由前缀(/api/raw、/raw、/d、/p 等),但在处理 /d/pikpak_webdav/... 时会先移除 /d,再移除 /p(匹配到挂载名中的 /p),导致挂载名变为 /ikpak_webdav,无法匹配配置的存储
问题分析:✅ 改动完全合理,新正则表达式 /^\/(?:api\/)?(?:raw|sd|d|p)(?=\/|$)/ 通过 ^ 锚定起始位置、(?=\/|$) 前瞻断言确保匹配完整前缀,避免误匹配挂载名内部字符
详细建议:无需改进,当前实现已非常精准。

其余细节:

  • ✅ 正则使用非捕获组 (?:...) 避免不必要的捕获开销
  • ✅ 前瞻断言 (?=\/|$) 确保匹配边界,既支持 /d/ 也支持单独的 /d(虽然后者在实际场景中较少)
  • ✅ 保留了原有的 decodeURIComponent() 逻辑,前向兼容性完好
  • ✅ 手动测试已验证(reporter confirmed),测试覆盖充分

✅ 待处理清单

无待处理项

🎯 结论:✅ Approve — 精准修复,代码质量优秀,可直接合并

@PIKACHUIM
PIKACHUIM merged commit a36351f into OpenListTeam:main Sep 16, 2026
1 check failed
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.

4 participants