Skip to content

Commit

Permalink
cf-files: fail gracefully when auto download disallowed (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg authored Aug 6, 2023
1 parent 58dc995 commit 690290c
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,30 @@ private Mono<Path> retrieveModFile(CurseForgeApiClient apiClient, CategoryInfo c
CurseForgeFile curseForgeFile
) {
return apiClient.getModInfo(curseForgeFile.getModId())
.flatMap(curseForgeMod ->
setupSubdir(categoryInfo, curseForgeMod)
.flatMap(subdir ->
apiClient.download(curseForgeFile,
outputDir.resolve(subdir).resolve(curseForgeFile.getFileName()),
modFileDownloadStatusHandler(outputDir, log)
)
));
.flatMap(curseForgeMod -> {
if (curseForgeFile.getDownloadUrl() == null) {
log.error("The authors of the mod '{}' have disallowed automated downloads. " +
"Manually download the file '{}' from {} and supply separately.",
curseForgeMod.getName(), curseForgeFile.getDisplayName(), curseForgeMod.getLinks().getWebsiteUrl()
);

return Mono.error(new InvalidParameterException(
String.format("The authors of %s do not allow automated downloads",
curseForgeMod.getName()
))
);
}

return setupSubdir(categoryInfo, curseForgeMod)
.flatMap(subdir ->
apiClient.download(curseForgeFile,
outputDir.resolve(subdir).resolve(curseForgeFile.getFileName()),
modFileDownloadStatusHandler(outputDir, log)
)
);
}
)
.checkpoint(String.format("Retrieving %d:%d", curseForgeFile.getModId(), curseForgeFile.getId()));
}

@NotNull
Expand Down

0 comments on commit 690290c

Please sign in to comment.