feat:try to get more data from modpack providers

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2023-07-21 16:54:13 +03:00
parent 43cc04433d
commit 171868f1c9
10 changed files with 429 additions and 2 deletions

View File

@ -6,6 +6,7 @@
#include "Application.h"
#include "Json.h"
#include "modplatform/modrinth/ModrinthPackIndex.h"
#include "net/NetJob.h"
#include "net/Upload.h"
@ -119,3 +120,32 @@ QList<ResourceAPI::SortingMethod> ModrinthAPI::getSortingMethods() const
{
return s_sorts;
}
Task::Ptr ModrinthAPI::getVersionFromHash(QString hash, ModPlatform::IndexedVersion& output)
{
static ModPlatform::ProviderCapabilities ProviderCaps;
auto hash_type = ProviderCaps.hashType(ModPlatform::ResourceProvider::MODRINTH).first();
auto response = std::make_shared<QByteArray>();
auto ver_task = currentVersion(hash, hash_type, response);
QObject::connect(ver_task.get(), &Task::succeeded, [response, &output] {
QJsonParseError parse_error{};
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
if (parse_error.error != QJsonParseError::NoError) {
qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at " << parse_error.offset
<< " reason: " << parse_error.errorString();
qWarning() << *response;
// failed(parse_error.errorString());
return;
}
try {
auto entry = Json::requireObject(doc);
output = Modrinth::loadIndexedPackVersion(entry);
} catch (Json::JsonException& e) {
qDebug() << e.cause();
qDebug() << doc;
}
});
return ver_task;
}

View File

@ -152,4 +152,6 @@ class ModrinthAPI : public NetworkResourceAPI {
.arg(args.mcVersion.toString())
.arg(getModLoaderStrings(args.loader).join("\",\""));
};
virtual Task::Ptr getVersionFromHash(QString hash, ModPlatform::IndexedVersion&) override;
};