fix: sort not work in modrinth. Closes #1274.
This commit is contained in:
@@ -25,7 +25,16 @@ import java.util.stream.Stream;
|
||||
|
||||
public interface RemoteModRepository {
|
||||
|
||||
Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort)
|
||||
enum SortType {
|
||||
DATE_CREATED,
|
||||
POPULARITY,
|
||||
LAST_UPDATED,
|
||||
NAME,
|
||||
AUTHOR,
|
||||
TOTAL_DOWNLOADS
|
||||
}
|
||||
|
||||
Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, SortType sort)
|
||||
throws IOException;
|
||||
|
||||
Optional<RemoteMod.Version> getRemoteVersionByLocalFile(LocalModFile localModFile, Path file) throws IOException;
|
||||
|
||||
@@ -63,10 +63,10 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<RemoteMod> search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
|
||||
public Stream<RemoteMod> search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, SortType sort) throws IOException {
|
||||
int categoryId = 0;
|
||||
if (category != null) categoryId = ((Category) category.getSelf()).getId();
|
||||
return searchPaginated(gameVersion, categoryId, pageOffset, pageSize, searchFilter, sort).stream()
|
||||
return searchPaginated(gameVersion, categoryId, pageOffset, pageSize, searchFilter, sort.ordinal()).stream()
|
||||
.map(CurseAddon::toMod);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,29 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
|
||||
private ModrinthRemoteModRepository() {
|
||||
}
|
||||
|
||||
public List<ModResult> searchPaginated(String gameVersion, int pageOffset, int pageSize, String searchFilter) throws IOException {
|
||||
private static String convertSortType(SortType sortType) {
|
||||
switch (sortType) {
|
||||
case DATE_CREATED:
|
||||
return "newest";
|
||||
case POPULARITY:
|
||||
case NAME:
|
||||
case AUTHOR:
|
||||
return "relevance";
|
||||
case LAST_UPDATED:
|
||||
return "updated";
|
||||
case TOTAL_DOWNLOADS:
|
||||
return "downloads";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported sort type " + sortType);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModResult> searchPaginated(String gameVersion, int pageOffset, int pageSize, String searchFilter, SortType sort) throws IOException {
|
||||
Map<String, String> query = mapOf(
|
||||
pair("query", searchFilter),
|
||||
pair("offset", Integer.toString(pageOffset)),
|
||||
pair("limit", Integer.toString(pageSize))
|
||||
pair("limit", Integer.toString(pageSize)),
|
||||
pair("index", convertSortType(sort))
|
||||
);
|
||||
if (StringUtils.isNotBlank(gameVersion)) {
|
||||
query.put("version", "versions=" + gameVersion);
|
||||
@@ -68,8 +86,8 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
|
||||
return searchPaginated(gameVersion, pageOffset, pageSize, searchFilter).stream()
|
||||
public Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, SortType sort) throws IOException {
|
||||
return searchPaginated(gameVersion, pageOffset, pageSize, searchFilter, sort).stream()
|
||||
.map(ModResult::toMod);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user