| 401 | } |
| 402 | |
| 403 | NetJob::Ptr EnsureMetadataTask::flameProjectsTask() |
| 404 | { |
| 405 | QHash<QString, QString> addonIds; |
| 406 | for (auto const& hash : m_mods.keys()) { |
| 407 | if (m_temp_versions.contains(hash)) { |
| 408 | auto const& dataObj = m_temp_versions.find(hash); |
| 409 | auto const& data = dataObj.value(); |
| 410 | |
| 411 | auto id_str = data.addonId.toString(); |
| 412 | if (!id_str.isEmpty()) |
| 413 | addonIds.insert(data.addonId.toString(), hash); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | auto response = new QByteArray(); |
| 418 | NetJob::Ptr proj_task; |
| 419 | |
| 420 | if (addonIds.isEmpty()) { |
| 421 | qWarning() << "No addonId found!"; |
| 422 | } else if (addonIds.size() == 1) { |
| 423 | proj_task = flame_api.getProject(*addonIds.keyBegin(), response); |
| 424 | } else { |
| 425 | proj_task = flame_api.getProjects(addonIds.keys(), response); |
| 426 | } |
| 427 | |
| 428 | // Prevents unfortunate timings when aborting the task |
| 429 | if (!proj_task) |
| 430 | return {}; |
| 431 | |
| 432 | connect(proj_task.get(), &NetJob::succeeded, this, [this, response, addonIds] { |
| 433 | QJsonParseError parse_error{}; |
| 434 | auto doc = QJsonDocument::fromJson(*response, &parse_error); |
| 435 | if (parse_error.error != QJsonParseError::NoError) { |
| 436 | qWarning() << "Error while parsing JSON response from Modrinth projects task at " << parse_error.offset |
| 437 | << " reason: " << parse_error.errorString(); |
| 438 | qWarning() << *response; |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | try { |
| 443 | QJsonArray entries; |
| 444 | if (addonIds.size() == 1) |
| 445 | entries = { Json::requireObject(Json::requireObject(doc), "data") }; |
| 446 | else |
| 447 | entries = Json::requireArray(Json::requireObject(doc), "data"); |
| 448 | |
| 449 | for (auto entry : entries) { |
| 450 | auto entry_obj = Json::requireObject(entry); |
| 451 | |
| 452 | auto id = QString::number(Json::requireInteger(entry_obj, "id")); |
| 453 | auto hash = addonIds.find(id).value(); |
| 454 | auto mod = m_mods.find(hash).value(); |
| 455 | |
| 456 | try { |
| 457 | setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(mod->name())); |
| 458 | |
| 459 | ModPlatform::IndexedPack pack; |
| 460 | FlameMod::loadIndexedPack(pack, entry_obj); |
nothing calls this directly
no test coverage detected