feat: add some api calls to modrinth

Calls added:
- Get version from hash
- Get versions from hashes
- Latest version of a project from a hash, loader(s), and game version(s)
- Latest versions of multiple project from hashes, loader(s), and game version(s)

Some of those are not used yet, but may be of use later on, so we have
it if we need it :)

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2022-06-03 19:04:49 -03:00
parent 32a9545360
commit 0e52112016
6 changed files with 141 additions and 9 deletions

View File

@ -111,7 +111,7 @@ void Modrinth::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
pack.versionsLoaded = true;
}
auto Modrinth::loadIndexedPackVersion(QJsonObject &obj) -> ModPlatform::IndexedVersion
auto Modrinth::loadIndexedPackVersion(QJsonObject &obj, QString preferred_hash_type, QString preferred_file_name) -> ModPlatform::IndexedVersion
{
ModPlatform::IndexedVersion file;
@ -142,6 +142,11 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject &obj) -> ModPlatform::IndexedV
auto parent = files[i].toObject();
auto fileName = Json::requireString(parent, "filename");
if (!preferred_file_name.isEmpty() && fileName.contains(preferred_file_name)) {
file.is_preferred = true;
break;
}
// Grab the primary file, if available
if (Json::requireBoolean(parent, "primary"))
break;
@ -153,13 +158,20 @@ auto Modrinth::loadIndexedPackVersion(QJsonObject &obj) -> ModPlatform::IndexedV
if (parent.contains("url")) {
file.downloadUrl = Json::requireString(parent, "url");
file.fileName = Json::requireString(parent, "filename");
file.is_preferred = Json::requireBoolean(parent, "primary");
auto hash_list = Json::requireObject(parent, "hashes");
auto hash_types = ProviderCaps.hashType(ModPlatform::Provider::MODRINTH);
for (auto& hash_type : hash_types) {
if (hash_list.contains(hash_type)) {
file.hash = Json::requireString(hash_list, hash_type);
file.hash_type = hash_type;
break;
if (hash_list.contains(preferred_hash_type)) {
file.hash = Json::requireString(hash_list, preferred_hash_type);
file.hash_type = preferred_hash_type;
} else {
auto hash_types = ProviderCaps.hashType(ModPlatform::Provider::MODRINTH);
for (auto& hash_type : hash_types) {
if (hash_list.contains(hash_type)) {
file.hash = Json::requireString(hash_list, hash_type);
file.hash_type = hash_type;
break;
}
}
}