| 30 | } |
| 31 | |
| 32 | auto FlameAPI::getModFileChangelog(int modId, int fileId) -> QString |
| 33 | { |
| 34 | QEventLoop lock; |
| 35 | QString changelog; |
| 36 | |
| 37 | auto* netJob = new NetJob(QString("Flame::FileChangelog"), APPLICATION->network()); |
| 38 | auto* response = new QByteArray(); |
| 39 | netJob->addNetAction(Net::Download::makeByteArray( |
| 40 | QString("https://api.curseforge.com/v1/mods/%1/files/%2/changelog") |
| 41 | .arg(QString::fromStdString(std::to_string(modId)), QString::fromStdString(std::to_string(fileId))), |
| 42 | response)); |
| 43 | |
| 44 | QObject::connect(netJob, &NetJob::succeeded, [netJob, response, &changelog] { |
| 45 | QJsonParseError parse_error{}; |
| 46 | QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); |
| 47 | if (parse_error.error != QJsonParseError::NoError) { |
| 48 | qWarning() << "Error while parsing JSON response from Flame::FileChangelog at " << parse_error.offset |
| 49 | << " reason: " << parse_error.errorString(); |
| 50 | qWarning() << *response; |
| 51 | |
| 52 | netJob->failed(parse_error.errorString()); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | changelog = Json::ensureString(doc.object(), "data"); |
| 57 | }); |
| 58 | |
| 59 | QObject::connect(netJob, &NetJob::finished, [response, &lock] { |
| 60 | delete response; |
| 61 | lock.quit(); |
| 62 | }); |
| 63 | |
| 64 | netJob->start(); |
| 65 | lock.exec(); |
| 66 | |
| 67 | return changelog; |
| 68 | } |
| 69 | |
| 70 | auto FlameAPI::getModDescription(int modId) -> QString |
| 71 | { |