Multipart works now
This commit is contained in:
parent
f139fe1e0c
commit
0d58d67a3c
@ -21,6 +21,10 @@ See the [wiki](https://github.com/ArsenArsen/KShare/wiki).
|
|||||||
* libavcodec
|
* libavcodec
|
||||||
* libavutil
|
* libavutil
|
||||||
* libswscale
|
* libswscale
|
||||||
|
Additionally, on Linux, you require:
|
||||||
|
* XCB
|
||||||
|
* XCB xfixes
|
||||||
|
* XCB cursor
|
||||||
|
|
||||||
Despite the name implying so, this project does not depend on the KDE API at all.
|
Despite the name implying so, this project does not depend on the KDE API at all.
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ build() {
|
|||||||
git checkout dev
|
git checkout dev
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
qmake
|
qmake
|
||||||
make
|
make -j$(($(nproc) + 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
|
@ -293,6 +293,8 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
case RequestFormat::MULTIPART_FORM_DATA: {
|
case RequestFormat::MULTIPART_FORM_DATA: {
|
||||||
QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||||
auto arr = body.toArray();
|
auto arr = body.toArray();
|
||||||
|
QList<QBuffer *> buffersToDelete;
|
||||||
|
QList<QByteArray *> arraysToDelete;
|
||||||
for (QJsonValue val : arr) {
|
for (QJsonValue val : arr) {
|
||||||
auto valo = val.toObject();
|
auto valo = val.toObject();
|
||||||
QHttpPart part;
|
QHttpPart part;
|
||||||
@ -307,18 +309,19 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
body.append(split[i]);
|
body.append(split[i]);
|
||||||
if (i < split.size() - 1) body.append(imgData);
|
if (i < split.size() - 1) body.append(imgData);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
body = s.toUtf8();
|
||||||
QByteArray *bodyHeap = new QByteArray;
|
QByteArray *bodyHeap = new QByteArray;
|
||||||
body.swap(*bodyHeap);
|
body.swap(*bodyHeap);
|
||||||
QBuffer *buffer = new QBuffer(bodyHeap);
|
QBuffer *buffer = new QBuffer(bodyHeap);
|
||||||
buffer->open(QIODevice::ReadOnly);
|
buffer->open(QIODevice::ReadOnly);
|
||||||
part.setBodyDevice(buffer);
|
part.setBodyDevice(buffer);
|
||||||
multipart->append(part);
|
buffersToDelete.append(buffer);
|
||||||
|
arraysToDelete.append(bodyHeap);
|
||||||
} else {
|
} else {
|
||||||
auto bdo = bd.toObject();
|
auto bdo = bd.toObject();
|
||||||
QJsonObject result = recurseAndReplace(bdo, imgData, mime);
|
QJsonObject result = recurseAndReplace(bdo, imgData, mime);
|
||||||
part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson());
|
part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson());
|
||||||
multipart->append(part);
|
|
||||||
}
|
}
|
||||||
QByteArray cdh("form-data");
|
QByteArray cdh("form-data");
|
||||||
for (QString headerVal : valo.keys()) {
|
for (QString headerVal : valo.keys()) {
|
||||||
@ -328,22 +331,28 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
if (str.startsWith("/") && str.endsWith("/"))
|
if (str.startsWith("/") && str.endsWith("/"))
|
||||||
str = str.mid(1, str.length() - 1).replace("%contenttype", mime);
|
str = str.mid(1, str.length() - 1).replace("%contenttype", mime);
|
||||||
part.setRawHeader(headerVal.toLatin1(), str.toLatin1());
|
part.setRawHeader(headerVal.toLatin1(), str.toLatin1());
|
||||||
} else
|
} else if (headerVal != "body")
|
||||||
cdh += "; " + headerVal + "= \"" + valo[headerVal].toString().replace("\"", "\\\"") + "\"";
|
cdh += "; " + headerVal + "=\"" + valo[headerVal].toString().replace("\"", "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
||||||
|
multipart->append(part);
|
||||||
}
|
}
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::POST:
|
case HttpMethod::POST:
|
||||||
if (returnPathspec == "|") {
|
if (returnPathspec == "|") {
|
||||||
ioutils::postMultipartData(target, h, multipart, [&](QByteArray result, QNetworkReply *) {
|
ioutils::postMultipartData(target, h, multipart, [&, buffersToDelete, arraysToDelete](QByteArray result, QNetworkReply *) {
|
||||||
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
QApplication::clipboard()->setText(QString::fromUtf8(result));
|
||||||
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postMultipart(target, h, multipart, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
ioutils::postMultipart(target, h, multipart,
|
||||||
parseResult(result, data, returnPathspec, name());
|
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
});
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
|
parseResult(result, data, returnPathspec, name());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user