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