| 211 | // Modrinth |
| 212 | |
| 213 | NetJob::Ptr EnsureMetadataTask::modrinthVersionsTask() |
| 214 | { |
| 215 | auto hash_type = ProviderCaps.hashType(ModPlatform::Provider::MODRINTH).first(); |
| 216 | |
| 217 | auto* response = new QByteArray(); |
| 218 | auto ver_task = modrinth_api.currentVersions(m_mods.keys(), hash_type, response); |
| 219 | |
| 220 | // Prevents unfortunate timings when aborting the task |
| 221 | if (!ver_task) |
| 222 | return {}; |
| 223 | |
| 224 | connect(ver_task.get(), &NetJob::succeeded, this, [this, response] { |
| 225 | QJsonParseError parse_error{}; |
| 226 | QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); |
| 227 | if (parse_error.error != QJsonParseError::NoError) { |
| 228 | qWarning() << "Error while parsing JSON response from Modrinth::CurrentVersions at " << parse_error.offset |
| 229 | << " reason: " << parse_error.errorString(); |
| 230 | qWarning() << *response; |
| 231 | |
| 232 | failed(parse_error.errorString()); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | try { |
| 237 | auto entries = Json::requireObject(doc); |
| 238 | for (auto& hash : m_mods.keys()) { |
| 239 | auto mod = m_mods.find(hash).value(); |
| 240 | try { |
| 241 | auto entry = Json::requireObject(entries, hash); |
| 242 | |
| 243 | setStatus(tr("Parsing API response from Modrinth for '%1'...").arg(mod->name())); |
| 244 | qDebug() << "Getting version for" << mod->name() << "from Modrinth"; |
| 245 | |
| 246 | m_temp_versions.insert(hash, Modrinth::loadIndexedPackVersion(entry)); |
| 247 | } catch (Json::JsonException& e) { |
| 248 | qDebug() << e.cause(); |
| 249 | qDebug() << entries; |
| 250 | |
| 251 | emitFail(mod); |
| 252 | } |
| 253 | } |
| 254 | } catch (Json::JsonException& e) { |
| 255 | qDebug() << e.cause(); |
| 256 | qDebug() << doc; |
| 257 | } |
| 258 | }); |
| 259 | |
| 260 | return ver_task; |
| 261 | } |
| 262 | |
| 263 | NetJob::Ptr EnsureMetadataTask::modrinthProjectsTask() |
| 264 | { |
nothing calls this directly
no test coverage detected