Skip to content

Commit

Permalink
Refactor: assume modrinth may not give a SHA 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Dec 9, 2023
1 parent 3a078e7 commit f3972e3
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ public ModDetail getModDetails(ModItem item) {
names[i] = version.get("name").getAsString();
mcNames[i] = version.get("game_versions").getAsJsonArray().get(0).getAsString();
urls[i] = version.get("files").getAsJsonArray().get(0).getAsJsonObject().get("url").getAsString();
hashes[i] = version.getAsJsonArray("files").get(0).getAsJsonObject()
.get("hashes").getAsJsonObject().get("sha1").getAsString();
// Assume there may not be hashes, in case the API changes
JsonObject hashesMap = version.getAsJsonArray("files").get(0).getAsJsonObject()
.get("hashes").getAsJsonObject();
if(hashesMap == null || hashesMap.get("sha1") == null){
hashes[i] = null;
continue;
}

hashes[i] = hashesMap.get("sha1").getAsString();
}

return new ModDetail(item, names, mcNames, urls, hashes);
Expand Down

0 comments on commit f3972e3

Please sign in to comment.