Add content disposition editing support
This commit is contained in:
parent
9952edb9f8
commit
f980ef8904
@ -66,7 +66,8 @@ SOURCES += main.cpp\
|
||||
cropeditor/drawing/arrowitem.cpp \
|
||||
uploaders/default/imgursettingsdialog.cpp \
|
||||
uploaders/default/imgplusuploader.cpp \
|
||||
filenamevalidator.cpp
|
||||
filenamevalidator.cpp \
|
||||
logs/requestlogging.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -111,7 +112,8 @@ HEADERS += mainwindow.hpp \
|
||||
cropeditor/drawing/arrowitem.hpp \
|
||||
uploaders/default/imgursettingsdialog.hpp \
|
||||
uploaders/default/imgplusuploader.hpp \
|
||||
filenamevalidator.hpp
|
||||
filenamevalidator.hpp \
|
||||
logs/requestlogging.hpp
|
||||
|
||||
nopkg {
|
||||
# win32 {
|
||||
|
@ -94,3 +94,22 @@ void ioutils::postData(QUrl target,
|
||||
delete reply;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
QString ioutils::methodString(QNetworkAccessManager::Operation operation) {
|
||||
switch (operation) {
|
||||
case QNetworkAccessManager::GetOperation:
|
||||
return "GET";
|
||||
case QNetworkAccessManager::PostOperation:
|
||||
return "POST";
|
||||
case QNetworkAccessManager::PutOperation:
|
||||
return "PUT";
|
||||
case QNetworkAccessManager::DeleteOperation:
|
||||
return "DELETE";
|
||||
case QNetworkAccessManager::HeadOperation:
|
||||
return "HEAD";
|
||||
default:
|
||||
// return "Dunno";
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ void postMultipartData(QUrl target,
|
||||
QList<QPair<QString, QString>> headers,
|
||||
QHttpMultiPart *body,
|
||||
std::function<void(QByteArray, QNetworkReply *)> callback);
|
||||
QString methodString(QNetworkAccessManager::Operation operation);
|
||||
}
|
||||
|
||||
#endif // IOUTILS_HPP
|
||||
|
33
logs/requestlogging.cpp
Normal file
33
logs/requestlogging.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "requestlogging.hpp"
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <io/ioutils.hpp>
|
||||
#include <settings.hpp>
|
||||
|
||||
QDir responses(settings::dir().absoluteFilePath("response"));
|
||||
void requestlogging::addEntry(RequestContext context) {
|
||||
if (!responses.exists()) responses.mkpath(".");
|
||||
QFile responseFile(responses.absoluteFilePath(context.sender + "-" + QDateTime().toString("yyyy-MM-dd HH-mm-ss")));
|
||||
if (!responseFile.open(QIODevice::WriteOnly)) {
|
||||
qCritical().noquote() << "Could not save response! " + responseFile.errorString();
|
||||
return;
|
||||
}
|
||||
responseFile.write(( //
|
||||
ioutils::methodString(context.reply->operation()) + // write method
|
||||
" " + // space
|
||||
context.reply->url().toString() + // write url
|
||||
" " + // space
|
||||
QString::number(context.reply->attribute(QNetworkRequest::HttpStatusCodeAttribute))
|
||||
+ // write status
|
||||
"\n" // newline
|
||||
)
|
||||
.toUtf8());
|
||||
for (auto header : context.reply->rawHeaderList()) responseFile.write(header + "\n");
|
||||
responseFile.write("\n\n" + context.response);
|
||||
responseFile.close();
|
||||
|
||||
addGUIEntry(context, QFileInfo(responseFile).absoluteFilePath());
|
||||
}
|
||||
|
||||
void requestlogging::addGUIEntry(RequestContext context, QString file) {
|
||||
}
|
18
logs/requestlogging.hpp
Normal file
18
logs/requestlogging.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef REQUESTLOGGING_HPP
|
||||
#define REQUESTLOGGING_HPP
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QNetworkReply>
|
||||
|
||||
struct RequestContext {
|
||||
QByteArray response;
|
||||
QString sender;
|
||||
QNetworkReply *reply;
|
||||
};
|
||||
|
||||
namespace requestlogging {
|
||||
void addEntry(RequestContext context);
|
||||
void addGUIEntry(RequestContext context, QString file);
|
||||
}
|
||||
|
||||
#endif // REQUESTLOGGING_HPP
|
4
main.cpp
4
main.cpp
@ -26,7 +26,7 @@ bool verbose = false;
|
||||
bool stillAlive = true;
|
||||
|
||||
#define LOGACT(lvl) \
|
||||
std::cout << lvl << stdMsg << "\n"; \
|
||||
std::cout << lvl << stdMsg << "\n" << std::flush; \
|
||||
if (stillAlive && MainWindow::inst() && MainWindow::inst()->valid()) { \
|
||||
MainWindow::inst()->ui->logBox->addItem(lvl + msg); \
|
||||
}
|
||||
@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
|
||||
Worker::init();
|
||||
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
|
||||
a.connect(&a, &QApplication::aboutToQuit, [] { stillAlive = false; });
|
||||
screenshotutil::renderText("DICKS").save("/home/arsen/test.png");
|
||||
|
||||
if (!parser.isSet(h)) w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -318,6 +318,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
part.setBody(QJsonDocument::fromVariant(result.toVariantMap()).toJson());
|
||||
multipart->append(part);
|
||||
}
|
||||
QByteArray cdh("form-data");
|
||||
for (QString headerVal : valo.keys()) {
|
||||
if (headerVal.startsWith("__")) {
|
||||
headerVal = headerVal.mid(2);
|
||||
@ -325,8 +326,10 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
||||
if (str.startsWith("/") && str.endsWith("/"))
|
||||
str = str.mid(1, str.length() - 1).replace("%contenttype", mime);
|
||||
part.setRawHeader(headerVal.toLatin1(), str.toLatin1());
|
||||
}
|
||||
} else
|
||||
cdh += "; " + headerVal + ": \"" + valo[headerVal].toString().replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh)
|
||||
}
|
||||
switch (method) {
|
||||
case HttpMethod::POST:
|
||||
|
Loading…
Reference in New Issue
Block a user