Fix #4977 Modrinth 依赖可以指向已经被删除的项目 (#5012)

This commit is contained in:
Burning_TNT
2026-02-06 22:56:44 +08:00
committed by GitHub
parent 570e1e2029
commit 5d57052ea2
4 changed files with 61 additions and 9 deletions

View File

@@ -159,7 +159,7 @@ public final class RemoteMod {
if (this.type == DependencyType.BROKEN) {
this.remoteMod = RemoteMod.BROKEN;
} else {
this.remoteMod = this.remoteModRepository.getModById(this.id);
this.remoteMod = this.remoteModRepository.resolveDependency(this.id);
}
}
return this.remoteMod;

View File

@@ -92,6 +92,10 @@ public interface RemoteModRepository {
RemoteMod getModById(String id) throws IOException;
default RemoteMod resolveDependency(String id) throws IOException {
return getModById(id);
}
RemoteMod.File getModFile(String modId, String fileId) throws IOException;
Stream<RemoteMod.Version> getRemoteVersionsById(String id) throws IOException;

View File

@@ -35,6 +35,7 @@ import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.jackhuang.hmcl.util.io.ResponseCodeException;
import org.jetbrains.annotations.Nullable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
@@ -154,6 +155,20 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
}
}
@Override
public RemoteMod resolveDependency(String id) throws IOException {
try {
return getModById(id);
} catch (ResponseCodeException e) {
if (e.getResponseCode() == 502 || e.getResponseCode() == 404) {
return RemoteMod.BROKEN;
}
throw e;
} catch (FileNotFoundException e) {
return RemoteMod.BROKEN;
}
}
@Override
public RemoteMod.File getModFile(String modId, String fileId) throws IOException {
throw new UnsupportedOperationException();