[pull] main from fscarmen2:main#4
Open
pull[bot] wants to merge 13 commits into
Open
Conversation
使用示例: 如果设置 DIR = 'dirA' 访问 https://mydomain.workers.dev/dirB/dirC/file.jpg 实际会访问存储中的 dirA/dirB/dirC/file.jpg
5c8f651 to
f12e195
Compare
Problem:
const r2Path = `${r2Config.bucket}/${DIR}/${storagePath}`;
当 DIR 为空时,生成的路径变成 bucket//subfolder/file.ext,这在 S3 兼容的 API 中被视为不同于 bucket/subfolder/file.ext 的路径,因此找不到文件。
Solution:
const r2Path = DIR ? `${r2Config.bucket}/${DIR}/${storagePath}` : `${r2Config.bucket}/${storagePath}`;
修改路径构建逻辑,增加处理dir为空的逻辑,如果为空则直接拼接 bucket 和 storagePath。
…dflare Worker scripts Changes in github_gitlab_r2_b2.js: - Add encodePathSegments() and buildEncodedPath() to encode path segments individually - Fix double-slash bug when DIR is empty (main//filename → main/filename) - Wrap decodeURIComponent in try/catch to prevent crashes on malformed URLs - Apply correct encoding to all GitHub raw URLs and GitHub API (where mode) URLs - Split CHECK_PASSWORD into CUSTOM_PASSWORD + CHECK_PASSWORD to avoid "always truthy" lint warning - Add @type {string} annotation to DIR to suppress "types have no overlap" lint warning Changes in github_only.js: - Decode requestPath with try/catch before extracting FILE, enabling CJK filename support - Add encodePathSegments() helper and rewrite URL builder to filter empty DIR, avoiding double slashes Changes in gitlab_only.js: - Encode each path segment individually in filePath construction instead of joining then encoding, preserving multi-level directory slashes - Fix getFileSizeFromGitLab to split file.path by "/" and encode each segment, preventing "/" from being encoded as "%2F" --- 修复:在三个 Cloudflare Worker 脚本中支持中日韩文件名及 URL 编码问题 github_gitlab_r2_b2.js 的改动: - 新增 encodePathSegments() 和 buildEncodedPath(),对路径逐段编码,支持中文/日文/韩文文件名 - 修复双斜杠问题:DIR 为空时不再产生 main//文件名 - decodeURIComponent 加 try/catch 保护,防止畸形 URL 导致 Worker 崩溃 - 所有 GitHub raw URL 及 GitHub API(where 模式)均应用了新编码逻辑 - 将 CHECK_PASSWORD 拆分为 CUSTOM_PASSWORD + CHECK_PASSWORD,消除"always truthy"静态检查警告 - 为 DIR 添加 @type {string} 注解,消除"types have no overlap"警告 github_only.js 的改动: - 对 url.pathname 做带 try/catch 保护的解码后再提取 FILE,支持中文文件名 - 新增 encodePathSegments() 并重写 URL 构建逻辑,过滤空 DIR,避免 raw URL 出现双斜杠 gitlab_only.js 的改动: - filePath 构建改为对 pathParts 逐段编码再拼接,修复整体编码时 / 被错误编码为 %2F 的问题 - 修复 getFileSizeFromGitLab:file.path 按 / 分割后逐段编码,正确保留多级目录的斜杠结构
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )