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