Skip to content

Commit febc4e5

Browse files
authored
cf: qualify mapping of excluded slug to mod IDs (#508)
1 parent ced7a0a commit febc4e5

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/main/java/me/itzg/helpers/curseforge/CurseForgeApiClient.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import reactor.core.publisher.Mono;
3636
import reactor.core.scheduler.Schedulers;
3737

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

@@ -185,25 +188,6 @@ public CurseForgeFile resolveModpackFile(
185188
});
186189
}
187190

188-
Mono<Integer> slugToId(CategoryInfo categoryInfo,
189-
String slug
190-
) {
191-
return preparedFetch
192-
.fetch(
193-
uriBuilder.resolve("/v1/mods/search?gameId={gameId}&slug={slug}", gameId, slug)
194-
)
195-
.toObject(ModsSearchResponse.class)
196-
.assemble()
197-
.map(resp ->
198-
resp.getData().stream()
199-
.filter(curseForgeMod -> categoryInfo.contentClassIds.containsKey(curseForgeMod.getClassId()))
200-
.findFirst()
201-
.map(CurseForgeMod::getId)
202-
.orElseThrow(() -> new GenericException("Unable to resolve slug into ID (no matches): " + slug))
203-
)
204-
.onErrorMap(FailedRequestException::isForbidden, this::errorMapForbidden);
205-
}
206-
207191
public Mono<CurseForgeMod> getModInfo(
208192
int projectID
209193
) {

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,18 @@ private ExcludeIncludeIds resolveExcludeIncludes(InstallContext context) {
637637
final ExcludeIncludes specific =
638638
excludeIncludes.getModpacks() != null ? excludeIncludes.getModpacks().get(context.slug) : null;
639639

640+
final int modsClassId = context.categoryInfo.getClassIdForSlug(CurseForgeApiClient.CATEGORY_MC_MODS);
641+
640642
return Mono.zip(
641643
resolveFromSlugOrIds(
642-
context, context.categoryInfo,
644+
context,
645+
modsClassId,
643646
excludeIncludes.getGlobalExcludes(),
644647
specific != null ? specific.getExcludes() : null
645648
),
646649
resolveFromSlugOrIds(
647-
context, context.categoryInfo,
648-
excludeIncludes.getGlobalForceIncludes(),
650+
context,
651+
modsClassId, excludeIncludes.getGlobalForceIncludes(),
649652
specific != null ? specific.getForceIncludes() : null
650653
)
651654
)
@@ -656,8 +659,8 @@ private ExcludeIncludeIds resolveExcludeIncludes(InstallContext context) {
656659
}
657660

658661
private Mono<Set<Integer>> resolveFromSlugOrIds(
659-
InstallContext context, CategoryInfo categoryInfo,
660-
Collection<String> global, Collection<String> specific
662+
InstallContext context,
663+
int modsClassId, Collection<String> global, Collection<String> specific
661664
) {
662665
log.trace("Resolving slug|id into IDs global={} specific={}", global, specific);
663666

@@ -668,10 +671,12 @@ private Mono<Set<Integer>> resolveFromSlugOrIds(
668671
)
669672
.flatMap(s -> {
670673
try {
674+
// Is it an integer already? If not, it'll drop into catch-block below
671675
final int id = Integer.parseInt(s);
672676
return Mono.just(id);
673677
} catch (NumberFormatException e) {
674-
return context.cfApi.slugToId(categoryInfo, s);
678+
return context.cfApi.searchMod(s, modsClassId)
679+
.map(CurseForgeMod::getId);
675680
}
676681
})
677682
.collect(Collectors.toSet());
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Maps data model for <a href="https://docs.curseforge.com/rest-api">CurseForge REST API</a>
3+
*/
4+
package me.itzg.helpers.curseforge.model;

0 commit comments

Comments
 (0)