mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added multipart support to NetworkRequest
This commit is contained in:
parent
ce53653ecd
commit
986694e4bc
|
@ -17,6 +17,7 @@ namespace chatterino {
|
|||
|
||||
NetworkData::NetworkData()
|
||||
: timer_(new QTimer())
|
||||
, lifetimeManager_(new QObject)
|
||||
{
|
||||
timer_->setSingleShot(true);
|
||||
|
||||
|
@ -26,6 +27,7 @@ NetworkData::NetworkData()
|
|||
NetworkData::~NetworkData()
|
||||
{
|
||||
this->timer_->deleteLater();
|
||||
this->lifetimeManager_->deleteLater();
|
||||
|
||||
DebugCount::decrease("NetworkData");
|
||||
}
|
||||
|
@ -104,8 +106,18 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
|||
data->request_);
|
||||
|
||||
case NetworkRequestType::Post:
|
||||
return NetworkManager::accessManager.post(data->request_,
|
||||
data->payload_);
|
||||
if (data->multiPartPayload_)
|
||||
{
|
||||
assert(data->payload_.isNull());
|
||||
|
||||
return NetworkManager::accessManager.post(
|
||||
data->request_, data->multiPartPayload_);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NetworkManager::accessManager.post(
|
||||
data->request_, data->payload_);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "common/NetworkCommon.hpp"
|
||||
#include "util/QObjectRef.hpp"
|
||||
|
||||
#include <QHttpMultiPart>
|
||||
#include <QNetworkRequest>
|
||||
#include <functional>
|
||||
|
||||
|
@ -45,6 +46,8 @@ struct NetworkData {
|
|||
NetworkRequestType requestType_ = NetworkRequestType::Get;
|
||||
|
||||
QByteArray payload_;
|
||||
// lifetime secured by lifetimeManager_
|
||||
QHttpMultiPart *multiPartPayload_{};
|
||||
|
||||
// Timer that tracks the timeout
|
||||
// By default, there's no explicit timeout for the request
|
||||
|
@ -52,6 +55,7 @@ struct NetworkData {
|
|||
// execute is called
|
||||
bool hasTimeout_{};
|
||||
QTimer *timer_;
|
||||
QObject *lifetimeManager_;
|
||||
|
||||
QString getHash();
|
||||
|
||||
|
|
|
@ -127,6 +127,13 @@ NetworkRequest NetworkRequest::authorizeTwitchV5(const QString &clientID,
|
|||
return tmp;
|
||||
}
|
||||
|
||||
NetworkRequest NetworkRequest::multiPart(QHttpMultiPart *payload) &&
|
||||
{
|
||||
payload->setParent(this->data->lifetimeManager_);
|
||||
this->data->multiPartPayload_ = payload;
|
||||
return std::move(*this);
|
||||
}
|
||||
|
||||
NetworkRequest NetworkRequest::payload(const QByteArray &payload) &&
|
||||
{
|
||||
this->data->payload_ = payload;
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
NetworkRequest concurrent() &&;
|
||||
NetworkRequest authorizeTwitchV5(const QString &clientID,
|
||||
const QString &oauthToken = QString()) &&;
|
||||
NetworkRequest multiPart(QHttpMultiPart *payload) &&;
|
||||
|
||||
void execute();
|
||||
|
||||
|
|
Loading…
Reference in a new issue