Skip to content

fix: replace PREFIX_FULL_URL with API_PREFIX for cache-121.199.60.4 mirror#3

Open
ZenthXSin wants to merge 1 commit into
DeterMination-Wind:mainfrom
ZenthXSin:fix/cache-mirror-api-prefix-strategy
Open

fix: replace PREFIX_FULL_URL with API_PREFIX for cache-121.199.60.4 mirror#3
ZenthXSin wants to merge 1 commit into
DeterMination-Wind:mainfrom
ZenthXSin:fix/cache-mirror-api-prefix-strategy

Conversation

@ZenthXSin

Copy link
Copy Markdown

问题

cache-121.199.60.4 镜像使用 Strategy.PREFIX_FULL_URL,对所有 GitHub 源头 URL 做 prefix + fullUrl 拼接:

http://121.199.60.4/github/https://raw.githubusercontent.com/...

但该服务器只处理 GitHub API v3 路径(/github/repos/...),对其他 URL 类型(raw、codeload、github.com 页面)一律返回 HTTP 403。这导致:

  • MindustryModsIndexRepository.fetch()MirrorSelector.wrap(INDEX_URL) → raw URL → 403 → 回退到其他镜像
  • 正确路径(/github/repos/...)只由硬编码的 Metadata.UPSTREAM_MOD_INDEXGitHubReleaseClient.CACHE_API_BASE 生成,不走 MirrorSelector

修复

不删镜像,改为新增 Strategy.API_PREFIX,只改写 api.github.com 来源的 URL:

  • prefix + url.substring("https://api.github.com/".length())http://121.199.60.4/github/repos/Anuken/Mindustry/...
  • raw.githubusercontent.comgithub.comcodeload.github.com 来源保持原样,由其他镜像或直连处理

测试验证

# API 路径 — API_PREFIX 正确改写
http://121.199.60.4/github/repos/Anuken/mindustry-mods/mods.json
→ HTTP 200, 581KB ✅

# raw 路径 — API_PREFIX 不解,留给其他镜像
gh.tinylake.top/https://raw.githubusercontent.com/Anuken/MindustryMods/master/mods.json
→ HTTP 200, 95KB ✅

…irror

The cache-121.199.60.4 server only proxies GitHub API v3 paths
(/github/repos/...). Using Strategy.PREFIX_FULL_URL caused
raw.githubusercontent.com URLs (e.g. mods.json) to be rewritten to
http://121.199.60.4/github/https://raw.githubusercontent.com/...
which the server cannot handle, returning HTTP 403.

Replace with the new Strategy.API_PREFIX that:
- Rewrites api.github.com URLs to the cache prefix (correctly)
- Passes through raw.githubusercontent.com, github.com, and
  codeload.github.com URLs unchanged (skips unsupported origin types)

This preserves the mirror for API requests while letting other
candidates (gh.tinylake.top, ghproxy.com, etc.) handle downloads.
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.

2 participants