From 82dd8285ef2771f931437ff7dae16155840ea735 Mon Sep 17 00:00:00 2001 From: 488254306 <488254306@qq.com> Date: Mon, 1 Jun 2026 23:59:51 +0800 Subject: [PATCH] fix: replace PREFIX_FULL_URL with API_PREFIX for cache-121.199.60.4 mirror 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. --- .../mindustry/download/MirrorSelector.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/XenonCore/src/main/java/determination/xenon/mindustry/download/MirrorSelector.java b/XenonCore/src/main/java/determination/xenon/mindustry/download/MirrorSelector.java index 3ea3a8e8f65..e1fa2625469 100644 --- a/XenonCore/src/main/java/determination/xenon/mindustry/download/MirrorSelector.java +++ b/XenonCore/src/main/java/determination/xenon/mindustry/download/MirrorSelector.java @@ -70,9 +70,13 @@ public final class MirrorSelector { * mirror penalty. */ private static final List CANDIDATES = List.of( - // Domestic cache proxy for Chinese users — faster than direct GitHub access + // Domestic API cache proxy. Only handles GitHub API paths + // (/github/repos/...), not raw.githubusercontent.com or + // github.com pages. PREFIX_FULL_URL would produce + // /github/https://raw.githubusercontent.com/... which the + // server cannot serve → HTTP 403. new Mirror("cache-121.199.60.4", - "http://121.199.60.4/github/", Strategy.PREFIX_FULL_URL, "http://121.199.60.4/github/"), + "http://121.199.60.4/github/", Strategy.API_PREFIX, "http://121.199.60.4/github/"), // gh.tinylake.top first — TinyLake's own proxy, the same one // mindustry.top/download links to. Empirically the most // reliable mirror for users in mainland China. @@ -252,7 +256,17 @@ private enum Strategy { * Substitute {@code github.com} with the mirror host * (and {@code raw.githubusercontent.com} with {@code raw./}). */ - HOST_REPLACE + HOST_REPLACE, + /** + * Rewrite only {@code api.github.com} URLs by stripping the API + * host and prepending {@code prefix} + {@code repos/...}. + * Other GitHub origins (raw, github.com, codeload) are passed + * through unchanged — this mirror cannot serve them. + * + *

Designed for cache proxies that speak the GitHub API v3 + * protocol but cannot proxy raw file downloads.

+ */ + API_PREFIX } private static final class Mirror { @@ -286,6 +300,12 @@ String wrap(String url) { } // api.github.com / codeload not handled by host-replace mirrors return url; + case API_PREFIX: + if (url.startsWith(API)) { + return prefix + url.substring(API.length()); + } + // raw / github.com / codeload URLs cannot go through this proxy + return url; default: return url; } @@ -305,4 +325,4 @@ public List candidateNames() { for (Mirror m : CANDIDATES) names.add(m.name); return Collections.unmodifiableList(names); } -} +} \ No newline at end of file