MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / executeTask

Method executeTask

launcher/net/Upload.cpp:191–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189 }
190
191 void Upload::executeTask() {
192 setStatus(tr("Uploading %1").arg(m_url.toString()));
193
194 if (m_state == State::AbortedByUser) {
195 qWarning() << "Attempt to start an aborted Upload:" << m_url.toString();
196 emit aborted();
197 return;
198 }
199 QNetworkRequest request(m_url);
200 m_state = m_sink->init(request);
201 switch (m_state) {
202 case State::Succeeded:
203 emitSucceeded();
204 qDebug() << "Upload cache hit " << m_url.toString();
205 return;
206 case State::Running:
207 qDebug() << "Uploading " << m_url.toString();
208 break;
209 case State::Inactive:
210 case State::Failed:
211 emitFailed("");
212 return;
213 case State::AbortedByUser:
214 emitAborted();
215 return;
216 }
217
218 if (APPLICATION->capabilities() & Application::SupportsFlame
219 && request.url().host().contains("api.curseforge.com")) {
220 request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
221 }
222 else {
223 request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
224 }
225 //TODO other types of post requests ?
226 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
227 QNetworkReply* rep = m_network->post(request, m_post_data);
228
229 m_reply.reset(rep);
230 connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64)));
231 connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
232 connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
233 connect(rep, &QNetworkReply::sslErrors, this, &Upload::sslErrors);
234 connect(rep, &QNetworkReply::readyRead, this, &Upload::downloadReadyRead);
235 }
236
237 Upload::Ptr Upload::makeByteArray(QUrl url, QByteArray *output, QByteArray m_post_data) {
238 auto* up = new Upload();

Callers

nothing calls this directly

Calls 9

capabilitiesMethod · 0.80
getFlameAPIKeyMethod · 0.80
getUserAgentMethod · 0.80
postMethod · 0.80
toStringMethod · 0.45
initMethod · 0.45
containsMethod · 0.45
urlMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected