| 149 | } |
| 150 | |
| 151 | Task::Ptr ResourceAPI::getProjectInfo(ProjectInfoArgs&& args, Callback<ModPlatform::IndexedPack::Ptr>&& callbacks) const |
| 152 | { |
| 153 | auto [job, response] = getProject(args.pack->addonId.toString()); |
| 154 | |
| 155 | QObject::connect(job.get(), &NetJob::succeeded, [this, response, callbacks, args] { |
| 156 | auto pack = args.pack; |
| 157 | QJsonParseError parse_error{}; |
| 158 | QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); |
| 159 | if (parse_error.error != QJsonParseError::NoError) { |
| 160 | qWarning() << "Error while parsing JSON response for mod info at" << parse_error.offset |
| 161 | << "reason:" << parse_error.errorString(); |
| 162 | qWarning() << *response; |
| 163 | return; |
| 164 | } |
| 165 | try { |
| 166 | auto obj = Json::requireObject(doc); |
| 167 | if (obj.contains("data")) |
| 168 | obj = Json::requireObject(obj, "data"); |
| 169 | loadIndexedPack(*pack, obj); |
| 170 | loadExtraPackInfo(*pack, obj); |
| 171 | } catch (const JSONValidationError& e) { |
| 172 | qDebug() << doc; |
| 173 | qWarning() << "Error while reading" << debugName() << "resource info:" << e.cause(); |
| 174 | } |
| 175 | callbacks.on_succeed(pack); |
| 176 | }); |
| 177 | // Capture a weak_ptr instead of a shared_ptr to avoid circular dependency issues. |
| 178 | // This prevents the lambda from extending the lifetime of the shared resource, |
| 179 | // as it only temporarily locks the resource when needed. |
| 180 | auto weak = job.toWeakRef(); |
| 181 | QObject::connect(job.get(), &NetJob::failed, [weak, callbacks](const QString& reason) { |
| 182 | int network_error_code = -1; |
| 183 | if (auto job = weak.lock()) { |
| 184 | if (auto netJob = qSharedPointerDynamicCast<NetJob>(job)) { |
| 185 | if (auto* failed_action = netJob->getFailedActions().at(0); failed_action) { |
| 186 | network_error_code = failed_action->replyStatusCode(); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | callbacks.on_fail(reason, network_error_code); |
| 191 | }); |
| 192 | QObject::connect(job.get(), &NetJob::aborted, [callbacks] { |
| 193 | if (callbacks.on_abort != nullptr) |
| 194 | callbacks.on_abort(); |
| 195 | }); |
| 196 | return job; |
| 197 | } |
| 198 | |
| 199 | Task::Ptr ResourceAPI::getDependencyVersion(DependencySearchArgs&& args, Callback<ModPlatform::IndexedVersion>&& callbacks) const |
| 200 | { |
no test coverage detected