diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-01-11 03:08:41 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-01-11 03:08:41 +0100 |
commit | 1151037f968628cd659f06457f9ca7403f77f071 (patch) | |
tree | e0749ab4d39ebf7767efd44885d7411fe1193f34 /logic/net | |
parent | acb3346409cb1b90fbb9abc929fd8a80038b447c (diff) | |
download | MultiMC-1151037f968628cd659f06457f9ca7403f77f071.tar MultiMC-1151037f968628cd659f06457f9ca7403f77f071.tar.gz MultiMC-1151037f968628cd659f06457f9ca7403f77f071.tar.lz MultiMC-1151037f968628cd659f06457f9ca7403f77f071.tar.xz MultiMC-1151037f968628cd659f06457f9ca7403f77f071.zip |
GH-719 Fix paste upload encoding and do not try to upload over limit
Diffstat (limited to 'logic/net')
-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; |