fix: add /oss/ route forwarding and fix cvtR2Url for S3 object storage#467
Open
hyrdsetbre wants to merge 1 commit into
Open
fix: add /oss/ route forwarding and fix cvtR2Url for S3 object storage#467hyrdsetbre wants to merge 1 commit into
hyrdsetbre wants to merge 1 commit into
Conversation
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.
问题描述
使用 S3 兼容存储(如 Backblaze B2 私有桶)时,附件上传成功但无法下载。访问
/oss/attachments/xxx.mp4路径时,返回的是前端 HTML 页面而不是文件内容。问题原因
后端路由问题:
mail-worker/src/index.js中只转发了/api/开头的请求给 Hono app 处理,/oss/路径没有被转发,导致该请求被前端 SPA fallback 拦截,返回了index.html。前端 URL 生成问题:
mail-vue/src/utils/convert.js中的cvtR2Url函数,当没有配置r2Domain时,直接返回了相对路径 key(如attachments/xxx.mp4),缺少/oss/前缀。解决方案
1. 后端:添加
/oss/路径转发在
mail-worker/src/index.js的fetch函数中,在/api/判断之后添加/oss/路径的转发逻辑:这样
/oss/开头的请求就会被转发给 Hono app,由r2-api.js中的路由处理。2. 前端:修复
cvtR2Url函数在
mail-vue/src/utils/convert.js中,当没有配置r2Domain时,使用/oss/前缀路径:这样即使没有配置自定义域名,也能通过 Worker 代理正确访问存储的文件。
测试说明
影响范围
/static/和/attachments/路径)r2Domain的用户不受影响修改文件
mail-worker/src/index.js- 添加/oss/路径转发mail-vue/src/utils/convert.js- 修复cvtR2Url函数,无r2Domain时使用/oss/前缀