fix(download): preserve storage mount names when stripping route prefixes - #59
Conversation
There was a problem hiding this comment.
🟢 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
/apiroutes. - 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
left a comment
There was a problem hiding this comment.
🙏 感谢 @karuboniru 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
🎯 结论
✅ 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 — 精准修复,代码质量优秀,可直接合并
Summary / 摘要
Fix downloads failing with
Not found: failed get storage: storage not foundfor 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.jpgfirst loses the/dprefix, then the chained replacements also remove/pfrom the mount name. The resultingikpak_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/apivariants. Existing URL decoding remains in place.Testing / 测试
git diff --checkAI Disclosure / AI 使用声明