| 266 | } |
| 267 | |
| 268 | Task::Ptr EnsureMetadataTask::modrinthProjectsTask() |
| 269 | { |
| 270 | QHash<QString, QString> addonIds; |
| 271 | for (auto const& data : m_temp_versions) |
| 272 | addonIds.insert(data.addonId.toString(), data.hash); |
| 273 | |
| 274 | auto response = std::make_shared<QByteArray>(); |
| 275 | Task::Ptr proj_task; |
| 276 | |
| 277 | if (addonIds.isEmpty()) { |
| 278 | qWarning() << "No addonId found!"; |
| 279 | } else if (addonIds.size() == 1) { |
| 280 | proj_task = modrinth_api.getProject(*addonIds.keyBegin(), response); |
| 281 | } else { |
| 282 | proj_task = modrinth_api.getProjects(addonIds.keys(), response); |
| 283 | } |
| 284 | |
| 285 | // Prevents unfortunate timings when aborting the task |
| 286 | if (!proj_task) |
| 287 | return Task::Ptr{ nullptr }; |
| 288 | |
| 289 | connect(proj_task.get(), &Task::succeeded, this, [this, response, addonIds] { |
| 290 | QJsonParseError parse_error{}; |
| 291 | auto doc = QJsonDocument::fromJson(*response, &parse_error); |
| 292 | if (parse_error.error != QJsonParseError::NoError) { |
| 293 | qWarning() << "Error while parsing JSON response from Modrinth projects task at " << parse_error.offset |
| 294 | << " reason: " << parse_error.errorString(); |
| 295 | qWarning() << *response; |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | QJsonArray entries; |
| 300 | |
| 301 | try { |
| 302 | if (addonIds.size() == 1) |
| 303 | entries = { doc.object() }; |
| 304 | else |
| 305 | entries = Json::requireArray(doc); |
| 306 | } catch (Json::JsonException& e) { |
| 307 | qDebug() << e.cause(); |
| 308 | qDebug() << doc; |
| 309 | } |
| 310 | |
| 311 | for (auto entry : entries) { |
| 312 | ModPlatform::IndexedPack pack; |
| 313 | |
| 314 | try { |
| 315 | auto entry_obj = Json::requireObject(entry); |
| 316 | |
| 317 | Modrinth::loadIndexedPack(pack, entry_obj); |
| 318 | } catch (Json::JsonException& e) { |
| 319 | qDebug() << e.cause(); |
| 320 | qDebug() << doc; |
| 321 | |
| 322 | // Skip this entry, since it has problems |
| 323 | continue; |
| 324 | } |
| 325 |
nothing calls this directly
no test coverage detected