Modrinth获取类别列表,搜索时增加类别筛选 (#1501)

* 修复Modrinth源加载列表失败,增加Modrinth源获取前置模组功能

* Revert "修复Modrinth源加载列表失败,增加Modrinth源获取前置模组功能"

This reverts commit 1d29c69d92db8714599ed8f8b524e143e278b80a.

* 修复CF源获取模组版本列表不全

* Modrinth源获取类别列表,搜索时增加类别选项

* Update ModrinthRemoteModRepository.java

* Update ModrinthRemoteModRepository.java
This commit is contained in:
Tungstend
2022-05-23 23:03:33 +08:00
committed by GitHub
parent f12882a389
commit 7d55c7f37f
2 changed files with 49 additions and 8 deletions

View File

@@ -87,7 +87,7 @@ public interface RemoteModRepository {
}
String[] DEFAULT_GAME_VERSIONS = new String[]{
"1.18.1", "1.18",
"1.18.2", "1.18.1", "1.18",
"1.17.1", "1.17",
"1.16.5", "1.16.4", "1.16.3", "1.16.2", "1.16.1", "1.16",
"1.15.2", "1.15.1", "1.15",

View File

@@ -73,12 +73,15 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
}
@Override
public Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, SortType sort, SortOrder sortOrder) throws IOException {
public Stream<RemoteMod> search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, SortType sort, SortOrder sortOrder) throws IOException {
List<List<String>> facets = new ArrayList<>();
facets.add(Collections.singletonList("project_type:" + projectType));
if (StringUtils.isNotBlank(gameVersion)) {
facets.add(Collections.singletonList("versions:" + gameVersion));
}
if (StringUtils.isNotBlank(category.getId())) {
facets.add(Collections.singletonList("categories:" + category.getId()));
}
Map<String, String> query = mapOf(
pair("query", searchFilter),
pair("facets", JsonUtils.UGLY_GSON.toJson(facets)),
@@ -131,14 +134,52 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
return versions.stream().map(ProjectVersion::toVersion).flatMap(Lang::toStream);
}
public List<String> getCategoriesImpl() throws IOException {
return HttpRequest.GET(PREFIX + "/v2/tag/category").getJson(new TypeToken<List<String>>() {
}.getType());
public List<Category> getCategoriesImpl() throws IOException {
List<Category> categories = HttpRequest.GET(PREFIX + "/v2/tag/category").getJson(new TypeToken<List<Category>>() {}.getType());
return categories.stream().filter(category -> category.getProjectType().equals(projectType)).collect(Collectors.toList());
}
public Stream<Category> getCategories() throws IOException {
return getCategoriesImpl().stream()
.map(name -> new Category(null, name, Collections.emptyList()));
@Override
public Stream<RemoteModRepository.Category> getCategories() throws IOException {
return getCategoriesImpl().stream().map(Category::toCategory);
}
public static class Category {
private final String icon;
private final String name;
@SerializedName("project_type")
private final String projectType;
public Category() {
this("","","");
}
public Category(String icon, String name, String projectType) {
this.icon = icon;
this.name = name;
this.projectType = projectType;
}
public String getIcon() {
return icon;
}
public String getName() {
return name;
}
public String getProjectType() {
return projectType;
}
public RemoteModRepository.Category toCategory() {
return new RemoteModRepository.Category(
this,
name,
Collections.emptyList());
}
}
public static class Project implements RemoteMod.IMod {