| 70 | } |
| 71 | |
| 72 | QString FlameAPI::getModDescription(int modId) |
| 73 | { |
| 74 | QEventLoop lock; |
| 75 | QString description; |
| 76 | |
| 77 | auto netJob = makeShared<NetJob>(QString("Flame::ModDescription"), APPLICATION->network()); |
| 78 | auto response = std::make_shared<QByteArray>(); |
| 79 | netJob->addNetAction(Net::ApiDownload::makeByteArray( |
| 80 | QString("https://api.curseforge.com/v1/mods/%1/description").arg(QString::number(modId)), response)); |
| 81 | |
| 82 | QObject::connect(netJob.get(), &NetJob::succeeded, [&netJob, response, &description] { |
| 83 | QJsonParseError parse_error{}; |
| 84 | QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); |
| 85 | if (parse_error.error != QJsonParseError::NoError) { |
| 86 | qWarning() << "Error while parsing JSON response from Flame::ModDescription at " << parse_error.offset |
| 87 | << " reason: " << parse_error.errorString(); |
| 88 | qWarning() << *response; |
| 89 | |
| 90 | netJob->failed(parse_error.errorString()); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | description = Json::ensureString(doc.object(), "data"); |
| 95 | }); |
| 96 | |
| 97 | QObject::connect(netJob.get(), &NetJob::finished, [&lock] { lock.quit(); }); |
| 98 | |
| 99 | netJob->start(); |
| 100 | lock.exec(); |
| 101 | |
| 102 | return description; |
| 103 | } |
| 104 | |
| 105 | QList<ModPlatform::IndexedVersion> FlameAPI::getLatestVersions(VersionSearchArgs&& args) |
| 106 | { |