Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions src/main/java/me/itzg/helpers/curseforge/CurseForgeApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

/**
* Implements parts of the <a href="https://docs.curseforge.com/rest-api">CurseForge REST API</a>
*/
@Slf4j
public class CurseForgeApiClient implements AutoCloseable {

Expand Down Expand Up @@ -185,25 +188,6 @@ public CurseForgeFile resolveModpackFile(
});
}

Mono<Integer> slugToId(CategoryInfo categoryInfo,
String slug
) {
return preparedFetch
.fetch(
uriBuilder.resolve("/v1/mods/search?gameId={gameId}&slug={slug}", gameId, slug)
)
.toObject(ModsSearchResponse.class)
.assemble()
.map(resp ->
resp.getData().stream()
.filter(curseForgeMod -> categoryInfo.contentClassIds.containsKey(curseForgeMod.getClassId()))
.findFirst()
.map(CurseForgeMod::getId)
.orElseThrow(() -> new GenericException("Unable to resolve slug into ID (no matches): " + slug))
)
.onErrorMap(FailedRequestException::isForbidden, this::errorMapForbidden);
}

public Mono<CurseForgeMod> getModInfo(
int projectID
) {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,18 @@ private ExcludeIncludeIds resolveExcludeIncludes(InstallContext context) {
final ExcludeIncludes specific =
excludeIncludes.getModpacks() != null ? excludeIncludes.getModpacks().get(context.slug) : null;

final int modsClassId = context.categoryInfo.getClassIdForSlug(CurseForgeApiClient.CATEGORY_MC_MODS);

return Mono.zip(
resolveFromSlugOrIds(
context, context.categoryInfo,
context,
modsClassId,
excludeIncludes.getGlobalExcludes(),
specific != null ? specific.getExcludes() : null
),
resolveFromSlugOrIds(
context, context.categoryInfo,
excludeIncludes.getGlobalForceIncludes(),
context,
modsClassId, excludeIncludes.getGlobalForceIncludes(),
specific != null ? specific.getForceIncludes() : null
)
)
Expand All @@ -656,8 +659,8 @@ private ExcludeIncludeIds resolveExcludeIncludes(InstallContext context) {
}

private Mono<Set<Integer>> resolveFromSlugOrIds(
InstallContext context, CategoryInfo categoryInfo,
Collection<String> global, Collection<String> specific
InstallContext context,
int modsClassId, Collection<String> global, Collection<String> specific
) {
log.trace("Resolving slug|id into IDs global={} specific={}", global, specific);

Expand All @@ -668,10 +671,12 @@ private Mono<Set<Integer>> resolveFromSlugOrIds(
)
.flatMap(s -> {
try {
// Is it an integer already? If not, it'll drop into catch-block below
final int id = Integer.parseInt(s);
return Mono.just(id);
} catch (NumberFormatException e) {
return context.cfApi.slugToId(categoryInfo, s);
return context.cfApi.searchMod(s, modsClassId)
.map(CurseForgeMod::getId);
}
})
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Maps data model for <a href="https://docs.curseforge.com/rest-api">CurseForge REST API</a>
*/
package me.itzg.helpers.curseforge.model;