重新启用 MCIM 加速 (#5030)

This commit is contained in:
Glavo
2026-02-24 21:21:46 +08:00
committed by GitHub
parent 285e361a5f
commit 2a6cd17a3c
3 changed files with 62 additions and 14 deletions
@@ -93,13 +93,12 @@ public final class BMCLAPIDownloadProvider implements DownloadProvider {
pair("https://repo.maven.apache.org/maven2", "https://mirrors.cloud.tencent.com/nexus/repository/maven-public"),
pair("https://hmcl.glavo.site/metadata/cleanroom", "https://alist.8mi.tech/d/mirror/HMCL-Metadata/Auto/cleanroom"),
pair("https://hmcl.glavo.site/metadata/fmllibs", "https://alist.8mi.tech/d/mirror/HMCL-Metadata/Auto/fmllibs"),
pair("https://zkitefly.github.io/unlisted-versions-of-minecraft", "https://alist.8mi.tech/d/mirror/unlisted-versions-of-minecraft/Auto")
// // https://github.com/mcmod-info-mirror/mcim-rust-api
// pair("https://api.modrinth.com", "https://mod.mcimirror.top/modrinth"),
// pair("https://cdn.modrinth.com", "https://mod.mcimirror.top"),
// pair("https://api.curseforge.com", "https://mod.mcimirror.top/curseforge"),
// pair("https://edge.forgecdn.net", "https://mod.mcimirror.top"),
// pair("https://mediafilez.forgecdn.net", "https://mod.mcimirror.top")
pair("https://zkitefly.github.io/unlisted-versions-of-minecraft", "https://alist.8mi.tech/d/mirror/unlisted-versions-of-minecraft/Auto"),
// https://github.com/mcmod-info-mirror/mcim-rust-api
pair("https://api.modrinth.com", "https://mod.mcimirror.top/modrinth"),
pair("https://cdn.modrinth.com", "https://mod.mcimirror.top"),
pair("https://api.curseforge.com", "https://mod.mcimirror.top/curseforge"),
pair("https://edge.forgecdn.net", "https://mod.mcimirror.top")
);
}
@@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
@@ -42,6 +43,7 @@ import java.util.stream.Stream;
import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Pair.pair;
import static org.jackhuang.hmcl.util.gson.JsonUtils.listTypeOf;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
public final class CurseForgeRemoteModRepository implements RemoteModRepository {
@@ -131,10 +133,34 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
query.put("index", Integer.toString(pageOffset * pageSize));
query.put("pageSize", Integer.toString(pageSize));
Response<List<CurseAddon>> response = withApiKey(HttpRequest.GET(downloadProvider.injectURL(NetworkUtils.withQuery(PREFIX + "/v1/mods/search", query))))
.getJson(Response.typeOf(listTypeOf(CurseAddon.class)));
if (searchFilter.isEmpty()) {
return new SearchResult(response.getData().stream().map(CurseAddon::toMod), calculateTotalPages(response, pageSize));
Response<List<CurseAddon>> response = null;
IOException exception = null;
List<URI> candidates = downloadProvider.injectURLWithCandidates(NetworkUtils.withQuery(PREFIX + "/v1/mods/search", query));
for (URI candidate : candidates) {
LOG.info("Fetching " + candidate);
try {
response = withApiKey(HttpRequest.GET(candidate.toString()))
.getJson(Response.typeOf(listTypeOf(CurseAddon.class)));
if (searchFilter.isEmpty()) {
return new SearchResult(response.getData().stream().map(CurseAddon::toMod), calculateTotalPages(response, pageSize));
}
break;
} catch (IOException e) {
LOG.warning("Failed to search addons: " + candidate, e);
if (candidates.size() == 1) {
exception = e;
} else {
if (exception == null) {
exception = new IOException("Failed to search addons");
}
exception.addSuppressed(e);
}
}
}
if (response == null) {
throw exception != null ? exception : new IOException("No candidates found");
}
// https://github.com/HMCL-dev/HMCL/issues/1549
@@ -37,6 +37,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.time.Instant;
@@ -54,6 +55,7 @@ import java.util.stream.Stream;
import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Pair.pair;
import static org.jackhuang.hmcl.util.gson.JsonUtils.listTypeOf;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
public final class ModrinthRemoteModRepository implements RemoteModRepository {
public static final ModrinthRemoteModRepository MODS = new ModrinthRemoteModRepository("mod");
@@ -112,9 +114,30 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
pair("limit", Integer.toString(pageSize)),
pair("index", convertSortType(sort))
);
Response<ProjectSearchResult> response = HttpRequest.GET(downloadProvider.injectURL(NetworkUtils.withQuery(PREFIX + "/v2/search", query)))
.getJson(Response.typeOf(ProjectSearchResult.class));
return new SearchResult(response.getHits().stream().map(ProjectSearchResult::toMod), (int) Math.ceil((double) response.totalHits / pageSize));
List<URI> candidates = downloadProvider.injectURLWithCandidates(NetworkUtils.withQuery(PREFIX + "/v2/search", query));
IOException exception = null;
for (URI candidate : candidates) {
try {
LOG.info("Fetching " + candidate);
Response<ProjectSearchResult> response = HttpRequest.GET(candidate.toString())
.getJson(Response.typeOf(ProjectSearchResult.class));
return new SearchResult(response.getHits().stream().map(ProjectSearchResult::toMod), (int) Math.ceil((double) response.totalHits / pageSize));
} catch (IOException e) {
LOG.warning("Failed to search addons: " + candidate, e);
if (candidates.size() == 1) {
exception = e;
} else {
if (exception == null) {
exception = new IOException("Failed to search addons");
}
exception.addSuppressed(e);
}
}
}
throw exception != null ? exception : new IOException("No candidates found");
} finally {
SEMAPHORE.release();
}