diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/net/PasteUpload.cpp | 11 | ||||
-rw-r--r-- | logic/net/PasteUpload.h | 8 |
2 files changed, 16 insertions, 3 deletions
diff --git a/logic/net/PasteUpload.cpp b/logic/net/PasteUpload.cpp index 2b953c5c..5fd8d679 100644 --- a/logic/net/PasteUpload.cpp +++ b/logic/net/PasteUpload.cpp @@ -6,8 +6,15 @@ #include "gui/dialogs/CustomMessageBox.h" #include <QDesktopServices> -PasteUpload::PasteUpload(QWidget *window, QString text) : m_text(text), m_window(window) +PasteUpload::PasteUpload(QWidget *window, QString text) : m_window(window) { + m_text = text.toUtf8(); + m_text.replace('\n', "\r\n"); +} + +bool PasteUpload::validateText() +{ + return m_text.size() <= maxSize(); } void PasteUpload::executeTask() @@ -16,7 +23,7 @@ void PasteUpload::executeTask() request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); QByteArray content( "key=public&description=MultiMC5+Log+File&language=plain&format=json&expire=2592000&paste=" + - m_text.toUtf8()); + m_text.toPercentEncoding()); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRawHeader("Content-Length", QByteArray::number(content.size())); diff --git a/logic/net/PasteUpload.h b/logic/net/PasteUpload.h index 0ddc8cef..307d592b 100644 --- a/logic/net/PasteUpload.h +++ b/logic/net/PasteUpload.h @@ -18,12 +18,18 @@ public: { return m_pasteID; } + uint32_t maxSize() + { + // 2MB for paste.ee + return 1024*1024*2; + } + bool validateText(); protected: virtual void executeTask(); private: bool parseResult(QJsonDocument doc); - QString m_text; + QByteArray m_text; QString m_error; QWidget *m_window; QString m_pasteID; |