fix: choose valid download url even if it's not the primary one
It seems to be possible to have modpack versions that have to primary file. In those cases, we pick a valid one "at random".
This commit is contained in:
parent
49de5d9b07
commit
4745ed2818
@ -81,15 +81,23 @@ auto loadIndexedVersion(QJsonObject &obj) -> ModpackVersion
|
||||
|
||||
auto files = Json::requireArray(obj, "files");
|
||||
|
||||
qWarning() << files;
|
||||
|
||||
for (auto file_iter : files) {
|
||||
File indexed_file;
|
||||
auto parent = Json::requireObject(file_iter);
|
||||
if (!Json::ensureBoolean(parent, "primary", false)) {
|
||||
continue;
|
||||
auto is_primary = Json::ensureBoolean(parent, "primary", false);
|
||||
if (!is_primary) {
|
||||
auto filename = Json::ensureString(parent, "filename");
|
||||
// Checking suffix here is fine because it's the response from Modrinth,
|
||||
// so one would assume it will always be in English.
|
||||
if(!filename.endsWith("mrpack") && !filename.endsWith("zip"))
|
||||
continue;
|
||||
}
|
||||
|
||||
file.download_url = Json::requireString(parent, "url");
|
||||
break;
|
||||
if(is_primary)
|
||||
break;
|
||||
}
|
||||
|
||||
if(file.download_url.isEmpty())
|
||||
|
@ -79,5 +79,5 @@ auto loadIndexedVersion(QJsonObject&) -> ModpackVersion;
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(Modrinth::Modpack);
|
||||
Q_DECLARE_METATYPE(Modrinth::ModpackVersion);
|
||||
Q_DECLARE_METATYPE(Modrinth::Modpack)
|
||||
Q_DECLARE_METATYPE(Modrinth::ModpackVersion)
|
||||
|
Loading…
Reference in New Issue
Block a user