Skip to content

Commit 4c1f15c

Browse files
CiiLuGlavo
andauthored
[release/3.6] 修复 CurseForge 源无法搜索到内容的问题 (#5733)
Co-authored-by: Glavo <zjx001202@gmail.com>
1 parent e8b9d98 commit 4c1f15c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepository.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.jackhuang.hmcl.util.StringUtils;
2727
import org.jackhuang.hmcl.util.io.HttpRequest;
2828
import org.jackhuang.hmcl.util.io.JarUtils;
29+
import org.jackhuang.hmcl.util.io.NetworkUtils;
2930
import org.jetbrains.annotations.Nullable;
3031

3132
import java.io.ByteArrayOutputStream;
@@ -105,18 +106,19 @@ public SearchResult search(String gameVersion, @Nullable RemoteModRepository.Cat
105106
if (category != null && category.getSelf() instanceof CurseAddon.Category) {
106107
categoryId = ((CurseAddon.Category) category.getSelf()).getId();
107108
}
108-
Response<List<CurseAddon>> response = HttpRequest.GET(PREFIX + "/v1/mods/search",
109-
pair("gameId", "432"),
110-
pair("classId", Integer.toString(section)),
111-
pair("categoryId", Integer.toString(categoryId)),
112-
pair("gameVersion", gameVersion),
113-
pair("searchFilter", searchFilter),
114-
pair("sortField", Integer.toString(toModsSearchSortField(sortType))),
115-
pair("sortOrder", toSortOrder(sortOrder)),
116-
pair("index", Integer.toString(pageOffset * pageSize)),
117-
pair("pageSize", Integer.toString(pageSize)))
118-
.header("X-API-KEY", apiKey)
119-
.getJson(Response.typeOf(listTypeOf(CurseAddon.class)));
109+
Map<String, String> query = new LinkedHashMap<>();
110+
query.put("gameId", "432");
111+
query.put("classId", Integer.toString(section));
112+
if (categoryId != 0)
113+
query.put("categoryId", Integer.toString(categoryId));
114+
query.put("gameVersion", gameVersion);
115+
query.put("searchFilter", searchFilter);
116+
query.put("sortField", Integer.toString(toModsSearchSortField(sortType)));
117+
query.put("sortOrder", toSortOrder(sortOrder));
118+
query.put("index", Integer.toString(pageOffset * pageSize));
119+
query.put("pageSize", Integer.toString(pageSize));
120+
121+
Response<List<CurseAddon>> response = HttpRequest.GET(NetworkUtils.withQuery(PREFIX + "/v1/mods/search", query)).header("X-API-KEY", apiKey).getJson(Response.typeOf(listTypeOf(CurseAddon.class)));
120122
if (searchFilter.isEmpty()) {
121123
return new SearchResult(response.getData().stream().map(CurseAddon::toMod), calculateTotalPages(response, pageSize));
122124
}

0 commit comments

Comments
 (0)