From a62155c1c9e561327cc589fe3da7b6d5a107d58d Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 14 Jan 2022 18:20:06 -0500 Subject: [PATCH 1/6] preliminary stuff for paste.ee removal --- CMakeLists.txt | 3 - buildconfig/BuildConfig.cpp.in | 1 - buildconfig/BuildConfig.h | 5 -- launcher/Application.cpp | 4 +- launcher/CMakeLists.txt | 6 +- .../global/{PasteEEPage.cpp => PastePage.cpp} | 22 ++++---- .../global/{PasteEEPage.h => PastePage.h} | 11 ++-- .../global/{PasteEEPage.ui => PastePage.ui} | 55 ++++++------------- 8 files changed, 40 insertions(+), 67 deletions(-) rename launcher/ui/pages/global/{PasteEEPage.cpp => PastePage.cpp} (81%) rename launcher/ui/pages/global/{PasteEEPage.h => PastePage.h} (88%) rename launcher/ui/pages/global/{PasteEEPage.ui => PastePage.ui} (61%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2af0aa71..91119b2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,9 +68,6 @@ set(Launcher_NOTIFICATION_URL "" CACHE STRING "URL for checking for notification # The metadata server set(Launcher_META_URL "https://meta.multimc.org/v1/" CACHE STRING "URL to fetch Launcher's meta files from.") -# paste.ee API key -set(Launcher_PASTE_EE_API_KEY "utLvciUouSURFzfjPxLBf5W4ISsUX4pwBDF7N1AfZ" CACHE STRING "API key you can get from paste.ee when you register an account") - # Imgur API Client ID set(Launcher_IMGUR_CLIENT_ID "5b97b0713fba4a3" CACHE STRING "Client ID you can get from Imgur when you register an application") diff --git a/buildconfig/BuildConfig.cpp.in b/buildconfig/BuildConfig.cpp.in index af8845dc..2595f78b 100644 --- a/buildconfig/BuildConfig.cpp.in +++ b/buildconfig/BuildConfig.cpp.in @@ -42,7 +42,6 @@ Config::Config() VERSION_STR = "@Launcher_VERSION_STRING@"; NEWS_RSS_URL = "@Launcher_NEWS_RSS_URL@"; - PASTE_EE_KEY = "@Launcher_PASTE_EE_API_KEY@"; IMGUR_CLIENT_ID = "@Launcher_IMGUR_CLIENT_ID@"; MSA_CLIENT_ID = "@Launcher_MSA_CLIENT_ID@"; META_URL = "@Launcher_META_URL@"; diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 009fb2bc..d09d5288 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -67,11 +67,6 @@ public: */ QString NEWS_RSS_URL; - /** - * API key you can get from paste.ee when you register an account - */ - QString PASTE_EE_KEY; - /** * Client ID you can get from Imgur when you register an application */ diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 47c9c20e..98e3e0fc 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -14,7 +14,7 @@ #include "ui/pages/global/ProxyPage.h" #include "ui/pages/global/ExternalToolsPage.h" #include "ui/pages/global/AccountListPage.h" -#include "ui/pages/global/PasteEEPage.h" +#include "ui/pages/global/PastePage.h" #include "ui/pages/global/CustomCommandsPage.h" #include "ui/themes/ITheme.h" @@ -728,7 +728,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); - m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); } qDebug() << "<> Settings loaded."; } diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index df361447..21859cad 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -711,8 +711,8 @@ SET(LAUNCHER_SOURCES ui/pages/global/LauncherPage.h ui/pages/global/ProxyPage.cpp ui/pages/global/ProxyPage.h - ui/pages/global/PasteEEPage.cpp - ui/pages/global/PasteEEPage.h + ui/pages/global/PastePage.cpp + ui/pages/global/PastePage.h # GUI - platform pages ui/pages/modplatform/VanillaPage.cpp @@ -848,7 +848,7 @@ qt5_wrap_ui(LAUNCHER_UI ui/pages/global/AccountListPage.ui ui/pages/global/JavaPage.ui ui/pages/global/LauncherPage.ui - ui/pages/global/PasteEEPage.ui + ui/pages/global/PastePage.ui ui/pages/global/ProxyPage.ui ui/pages/global/MinecraftPage.ui ui/pages/global/ExternalToolsPage.ui diff --git a/launcher/ui/pages/global/PasteEEPage.cpp b/launcher/ui/pages/global/PastePage.cpp similarity index 81% rename from launcher/ui/pages/global/PasteEEPage.cpp rename to launcher/ui/pages/global/PastePage.cpp index 4b375d9a..3378a6ef 100644 --- a/launcher/ui/pages/global/PasteEEPage.cpp +++ b/launcher/ui/pages/global/PastePage.cpp @@ -1,4 +1,4 @@ -/* Copyright 2013-2021 MultiMC Contributors +/* Copyright 2013-2021 MultiMC & PolyMC Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "PasteEEPage.h" -#include "ui_PasteEEPage.h" +#include "PastePage.h" +#include "ui_PastePage.h" #include #include @@ -25,22 +25,22 @@ #include "tools/BaseProfiler.h" #include "Application.h" -PasteEEPage::PasteEEPage(QWidget *parent) : +PastePage::PastePage(QWidget *parent) : QWidget(parent), - ui(new Ui::PasteEEPage) + ui(new Ui::PastePage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide();\ - connect(ui->customAPIkeyEdit, &QLineEdit::textEdited, this, &PasteEEPage::textEdited); + connect(ui->customAPIkeyEdit, &QLineEdit::textEdited, this, &PastePage::textEdited); loadSettings(); } -PasteEEPage::~PasteEEPage() +PastePage::~PastePage() { delete ui; } -void PasteEEPage::loadSettings() +void PastePage::loadSettings() { auto s = APPLICATION->settings(); QString keyToUse = s->get("PasteEEAPIKey").toString(); @@ -55,7 +55,7 @@ void PasteEEPage::loadSettings() } } -void PasteEEPage::applySettings() +void PastePage::applySettings() { auto s = APPLICATION->settings(); @@ -69,13 +69,13 @@ void PasteEEPage::applySettings() s->set("PasteEEAPIKey", pasteKeyToUse); } -bool PasteEEPage::apply() +bool PastePage::apply() { applySettings(); return true; } -void PasteEEPage::textEdited(const QString& text) +void PastePage::textEdited(const QString& text) { ui->customButton->setChecked(true); } diff --git a/launcher/ui/pages/global/PasteEEPage.h b/launcher/ui/pages/global/PastePage.h similarity index 88% rename from launcher/ui/pages/global/PasteEEPage.h rename to launcher/ui/pages/global/PastePage.h index a1c7d434..3930d4ec 100644 --- a/launcher/ui/pages/global/PasteEEPage.h +++ b/launcher/ui/pages/global/PastePage.h @@ -21,16 +21,16 @@ #include namespace Ui { -class PasteEEPage; +class PastePage; } -class PasteEEPage : public QWidget, public BasePage +class PastePage : public QWidget, public BasePage { Q_OBJECT public: - explicit PasteEEPage(QWidget *parent = 0); - ~PasteEEPage(); + explicit PastePage(QWidget *parent = 0); + ~PastePage(); QString displayName() const override { @@ -58,5 +58,6 @@ private slots: void textEdited(const QString &text); private: - Ui::PasteEEPage *ui; + Ui::PastePage *ui; }; + diff --git a/launcher/ui/pages/global/PasteEEPage.ui b/launcher/ui/pages/global/PastePage.ui similarity index 61% rename from launcher/ui/pages/global/PasteEEPage.ui rename to launcher/ui/pages/global/PastePage.ui index 10883781..0bef5a22 100644 --- a/launcher/ui/pages/global/PasteEEPage.ui +++ b/launcher/ui/pages/global/PastePage.ui @@ -1,7 +1,7 @@ - PasteEEPage - + PastePage + 0 @@ -36,39 +36,9 @@ - paste.ee API key + Pastebin Site - - - - MultiMC key - 12MB &upload limit - - - pasteButtonGroup - - - - - - - &Your own key - 12MB upload limit: - - - pasteButtonGroup - - - - - - - QLineEdit::Password - - - Paste your API key here! - - - @@ -76,10 +46,24 @@ + + + + + 0x0.st + + + + + paste.polymc.org + + + + - <html><head/><body><p><a href="https://paste.ee">paste.ee</a> is used by MultiMC for log uploads. If you have a <a href="https://paste.ee">paste.ee</a> account, you can add your API key here and have your uploaded logs paired with your account.</p></body></html> + <html><head/><body><p>paste.polymc.org is a pastebin managed by PolyMC's lead maintainer. Something something trust</p></body></html> Qt::RichText @@ -116,9 +100,6 @@ tabWidget - multimcButton - customButton - customAPIkeyEdit From a606b47a22443cefc52d865df24c45ff50908f6f Mon Sep 17 00:00:00 2001 From: swirl Date: Fri, 14 Jan 2022 18:30:02 -0500 Subject: [PATCH 2/6] pastebin URL app setting --- launcher/Application.cpp | 4 ++-- launcher/ui/pages/global/PastePage.cpp | 13 +++---------- launcher/ui/pages/global/PastePage.ui | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 98e3e0fc..110b2e6b 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -714,8 +714,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_settings->registerSetting("UpdateDialogGeometry", ""); - // paste.ee API key - m_settings->registerSetting("PasteEEAPIKey", "multimc"); + // pastebin URL + m_settings->registerSetting("PastebinURL", "0x0.st"); // Init page provider { diff --git a/launcher/ui/pages/global/PastePage.cpp b/launcher/ui/pages/global/PastePage.cpp index 3378a6ef..495e9937 100644 --- a/launcher/ui/pages/global/PastePage.cpp +++ b/launcher/ui/pages/global/PastePage.cpp @@ -43,16 +43,9 @@ PastePage::~PastePage() void PastePage::loadSettings() { auto s = APPLICATION->settings(); - QString keyToUse = s->get("PasteEEAPIKey").toString(); - if(keyToUse == "multimc") - { - ui->multimcButton->setChecked(true); - } - else - { - ui->customButton->setChecked(true); - ui->customAPIkeyEdit->setText(keyToUse); - } + QString pastebin = s->get("PastebinURL"); + int index = ui->urlChoices->findText(pastebin); + ui->urlChoices->setCurrentIndex(index); } void PastePage::applySettings() diff --git a/launcher/ui/pages/global/PastePage.ui b/launcher/ui/pages/global/PastePage.ui index 0bef5a22..784ea3f4 100644 --- a/launcher/ui/pages/global/PastePage.ui +++ b/launcher/ui/pages/global/PastePage.ui @@ -47,7 +47,7 @@ - + 0x0.st From b50e58436975761fcb7b8886eb137330e5b6e29a Mon Sep 17 00:00:00 2001 From: Lenny McLennington Date: Wed, 19 Jan 2022 07:44:29 +0000 Subject: [PATCH 3/6] PasteUpload task changed to use 0x0.st's protocol - Modified PasteUpload task to upload the log file to 0x0.st and other services with the same protocol. - Modified Paste settings UI to allow the user to select a custom paste URL, simplified the settings page code. --- launcher/Application.cpp | 2 +- launcher/net/PasteUpload.cpp | 88 +++++++-------------- launcher/net/PasteUpload.h | 22 +----- launcher/ui/GuiUtil.cpp | 17 +--- launcher/ui/pages/global/PastePage.cpp | 23 ++---- launcher/ui/pages/global/PastePage.h | 3 - launcher/ui/pages/global/PastePage.ui | 17 ++-- launcher/ui/pages/instance/LogPage.ui | 2 +- launcher/ui/pages/instance/OtherLogsPage.ui | 2 +- 9 files changed, 51 insertions(+), 125 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 110b2e6b..a5b861d0 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -715,7 +715,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_settings->registerSetting("UpdateDialogGeometry", ""); // pastebin URL - m_settings->registerSetting("PastebinURL", "0x0.st"); + m_settings->registerSetting("PastebinURL", "https://0x0.st"); // Init page provider { diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 4b69b68a..6c5aa221 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -8,44 +8,34 @@ #include #include -PasteUpload::PasteUpload(QWidget *window, QString text, QString key) : m_window(window) +PasteUpload::PasteUpload(QWidget *window, QString text, QString url) : m_window(window), m_uploadUrl(url), m_text(text.toUtf8()) { - m_key = key; - QByteArray temp; - QJsonObject topLevelObj; - QJsonObject sectionObject; - sectionObject.insert("contents", text); - QJsonArray sectionArray; - sectionArray.append(sectionObject); - topLevelObj.insert("description", "Log Upload"); - topLevelObj.insert("sections", sectionArray); - QJsonDocument docOut; - docOut.setObject(topLevelObj); - m_jsonContent = docOut.toJson(); } PasteUpload::~PasteUpload() { } -bool PasteUpload::validateText() -{ - return m_jsonContent.size() <= maxSize(); -} - void PasteUpload::executeTask() { - QNetworkRequest request(QUrl("https://api.paste.ee/v1/pastes")); + QNetworkRequest request{QUrl(m_uploadUrl)}; request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); - request.setRawHeader("Content-Type", "application/json"); - request.setRawHeader("Content-Length", QByteArray::number(m_jsonContent.size())); - request.setRawHeader("X-Auth-Token", m_key.toStdString().c_str()); + QHttpMultiPart *multiPart = new QHttpMultiPart{QHttpMultiPart::FormDataType}; - QNetworkReply *rep = APPLICATION->network()->post(request, m_jsonContent); + QHttpPart filePart; + filePart.setBody(m_text); + filePart.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain"); + filePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"file\"; filename=\"log.txt\""); + + multiPart->append(filePart); + + QNetworkReply *rep = APPLICATION->network()->post(request, multiPart); + multiPart->setParent(rep); m_reply = std::shared_ptr(rep); - setStatus(tr("Uploading to paste.ee")); + setStatus(tr("Uploading to %1").arg(m_uploadUrl)); + connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress); connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished())); @@ -61,45 +51,23 @@ void PasteUpload::downloadError(QNetworkReply::NetworkError error) void PasteUpload::downloadFinished() { QByteArray data = m_reply->readAll(); - // if the download succeeded - if (m_reply->error() == QNetworkReply::NetworkError::NoError) + int statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (m_reply->error() != QNetworkReply::NetworkError::NoError) { - m_reply.reset(); - QJsonParseError jsonError; - QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed(jsonError.errorString()); - return; - } - if (!parseResult(doc)) - { - emitFailed(tr("paste.ee returned an error. Please consult the logs for more information")); - return; - } - } - // else the download failed - else - { - emitFailed(QString("Network error: %1").arg(m_reply->errorString())); + emitFailed(tr("Network error: %1").arg(m_reply->errorString())); m_reply.reset(); return; } + else if (statusCode != 200) + { + QString reasonPhrase = m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); + emitFailed(tr("Error: %1 returned unexpected status code %2 %3").arg(m_uploadUrl).arg(statusCode).arg(reasonPhrase)); + qCritical() << m_uploadUrl << " returned unexpected status code " << statusCode << " with body: " << data; + m_reply.reset(); + return; + } + + m_pasteLink = QString::fromUtf8(data); emitSucceeded(); } - -bool PasteUpload::parseResult(QJsonDocument doc) -{ - auto object = doc.object(); - auto status = object.value("success").toBool(); - if (!status) - { - qCritical() << "paste.ee reported error:" << QString(object.value("error").toString()); - return false; - } - m_pasteLink = object.value("link").toString(); - m_pasteID = object.value("id").toString(); - qDebug() << m_pasteLink; - return true; -} - diff --git a/launcher/net/PasteUpload.h b/launcher/net/PasteUpload.h index 5514e058..62b2dc36 100644 --- a/launcher/net/PasteUpload.h +++ b/launcher/net/PasteUpload.h @@ -8,37 +8,21 @@ class PasteUpload : public Task { Q_OBJECT public: - PasteUpload(QWidget *window, QString text, QString key = "public"); + PasteUpload(QWidget *window, QString text, QString url); virtual ~PasteUpload(); QString pasteLink() { return m_pasteLink; } - QString pasteID() - { - return m_pasteID; - } - int maxSize() - { - // 2MB for paste.ee - public - if(m_key == "public") - return 1024*1024*2; - // 12MB for paste.ee - with actual key - return 1024*1024*12; - } - bool validateText(); protected: virtual void executeTask(); private: - bool parseResult(QJsonDocument doc); - QString m_error; QWidget *m_window; - QString m_pasteID; QString m_pasteLink; - QString m_key; - QByteArray m_jsonContent; + QString m_uploadUrl; + QByteArray m_text; std::shared_ptr m_reply; public slots: diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index efb1a4df..9eb658e2 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -16,21 +16,8 @@ QString GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget) { ProgressDialog dialog(parentWidget); - auto APIKeySetting = APPLICATION->settings()->get("PasteEEAPIKey").toString(); - if(APIKeySetting == "multimc") - { - APIKeySetting = BuildConfig.PASTE_EE_KEY; - } - std::unique_ptr paste(new PasteUpload(parentWidget, text, APIKeySetting)); - - if (!paste->validateText()) - { - CustomMessageBox::selectable( - parentWidget, QObject::tr("Upload failed"), - QObject::tr("The log file is too big. You'll have to upload it manually."), - QMessageBox::Warning)->exec(); - return QString(); - } + auto pasteUrlSetting = APPLICATION->settings()->get("PastebinURL").toString(); + std::unique_ptr paste(new PasteUpload(parentWidget, text, pasteUrlSetting)); dialog.execWithTask(paste.get()); if (!paste->wasSuccessful()) diff --git a/launcher/ui/pages/global/PastePage.cpp b/launcher/ui/pages/global/PastePage.cpp index 495e9937..0965da77 100644 --- a/launcher/ui/pages/global/PastePage.cpp +++ b/launcher/ui/pages/global/PastePage.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "settings/SettingsObject.h" #include "tools/BaseProfiler.h" @@ -31,7 +32,6 @@ PastePage::PastePage(QWidget *parent) : { ui->setupUi(this); ui->tabWidget->tabBar()->hide();\ - connect(ui->customAPIkeyEdit, &QLineEdit::textEdited, this, &PastePage::textEdited); loadSettings(); } @@ -43,23 +43,15 @@ PastePage::~PastePage() void PastePage::loadSettings() { auto s = APPLICATION->settings(); - QString pastebin = s->get("PastebinURL"); - int index = ui->urlChoices->findText(pastebin); - ui->urlChoices->setCurrentIndex(index); + QString pastebinURL = s->get("PastebinURL").toString(); + ui->urlChoices->setCurrentText(pastebinURL); } void PastePage::applySettings() { auto s = APPLICATION->settings(); - - QString pasteKeyToUse; - if (ui->customButton->isChecked()) - pasteKeyToUse = ui->customAPIkeyEdit->text(); - else - { - pasteKeyToUse = "multimc"; - } - s->set("PasteEEAPIKey", pasteKeyToUse); + QString pastebinURL = ui->urlChoices->currentText(); + s->set("PastebinURL", pastebinURL); } bool PastePage::apply() @@ -67,8 +59,3 @@ bool PastePage::apply() applySettings(); return true; } - -void PastePage::textEdited(const QString& text) -{ - ui->customButton->setChecked(true); -} diff --git a/launcher/ui/pages/global/PastePage.h b/launcher/ui/pages/global/PastePage.h index 3930d4ec..d475dfd9 100644 --- a/launcher/ui/pages/global/PastePage.h +++ b/launcher/ui/pages/global/PastePage.h @@ -54,9 +54,6 @@ private: void loadSettings(); void applySettings(); -private slots: - void textEdited(const QString &text); - private: Ui::PastePage *ui; }; diff --git a/launcher/ui/pages/global/PastePage.ui b/launcher/ui/pages/global/PastePage.ui index 784ea3f4..fe372540 100644 --- a/launcher/ui/pages/global/PastePage.ui +++ b/launcher/ui/pages/global/PastePage.ui @@ -36,7 +36,7 @@ - Pastebin Site + Pastebin URL @@ -48,14 +48,20 @@ + + true + + + QComboBox::NoInsert + - 0x0.st + https://0x0.st - paste.polymc.org + https://paste.polymc.org @@ -63,7 +69,7 @@ - <html><head/><body><p>paste.polymc.org is a pastebin managed by PolyMC's lead maintainer. Something something trust</p></body></html> + <html><head/><body><p>Here you can choose from a predefined list, or input the URL of a different paste service, provided that it supports the same protocol as 0x0.st, that is POST a file to the URL and return a link in the response body.</p></body></html> Qt::RichText @@ -103,7 +109,4 @@ - - - diff --git a/launcher/ui/pages/instance/LogPage.ui b/launcher/ui/pages/instance/LogPage.ui index ccfc1551..31bb368c 100644 --- a/launcher/ui/pages/instance/LogPage.ui +++ b/launcher/ui/pages/instance/LogPage.ui @@ -100,7 +100,7 @@ - Upload the log to paste.ee - it will stay online for a month + Upload the log to the paste service configured in preferences Upload diff --git a/launcher/ui/pages/instance/OtherLogsPage.ui b/launcher/ui/pages/instance/OtherLogsPage.ui index 56ff3b62..77f3e647 100644 --- a/launcher/ui/pages/instance/OtherLogsPage.ui +++ b/launcher/ui/pages/instance/OtherLogsPage.ui @@ -84,7 +84,7 @@ - Upload the log to paste.ee - it will stay online for a month + Upload the log to the paste service configured in preferences. Upload From caeab926bcc8563996f7826a060966b55580376d Mon Sep 17 00:00:00 2001 From: Lenny McLennington Date: Wed, 19 Jan 2022 14:59:09 +0000 Subject: [PATCH 4/6] PasteUpload: Trim whitespace from response body --- launcher/net/PasteUpload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 6c5aa221..4efcefdd 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -68,6 +68,6 @@ void PasteUpload::downloadFinished() return; } - m_pasteLink = QString::fromUtf8(data); + m_pasteLink = QString::fromUtf8(data).trimmed(); emitSucceeded(); } From af20b5ee0e09d5c9ec36d54c80ca688c7c67012d Mon Sep 17 00:00:00 2001 From: swirl Date: Sun, 23 Jan 2022 12:54:58 -0500 Subject: [PATCH 5/6] support paste.polymc.org --- launcher/net/PasteUpload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/net/PasteUpload.cpp b/launcher/net/PasteUpload.cpp index 4efcefdd..52b82a0e 100644 --- a/launcher/net/PasteUpload.cpp +++ b/launcher/net/PasteUpload.cpp @@ -59,7 +59,7 @@ void PasteUpload::downloadFinished() m_reply.reset(); return; } - else if (statusCode != 200) + else if (statusCode != 200 && statusCode != 201) { QString reasonPhrase = m_reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); emitFailed(tr("Error: %1 returned unexpected status code %2 %3").arg(m_uploadUrl).arg(statusCode).arg(reasonPhrase)); From 0eff21a4f1ee97e4b0a484c608eac9617897446d Mon Sep 17 00:00:00 2001 From: Lenny McLennington Date: Wed, 26 Jan 2022 00:31:08 +0000 Subject: [PATCH 6/6] Validate Pastebin URL with regex --- launcher/ui/pages/global/PastePage.cpp | 2 ++ launcher/ui/pages/global/PastePage.ui | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/launcher/ui/pages/global/PastePage.cpp b/launcher/ui/pages/global/PastePage.cpp index 0965da77..7c69e1a4 100644 --- a/launcher/ui/pages/global/PastePage.cpp +++ b/launcher/ui/pages/global/PastePage.cpp @@ -30,7 +30,9 @@ PastePage::PastePage(QWidget *parent) : QWidget(parent), ui(new Ui::PastePage) { + static QRegularExpression validUrlRegExp("https?://.+"); ui->setupUi(this); + ui->urlChoices->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->urlChoices)); ui->tabWidget->tabBar()->hide();\ loadSettings(); } diff --git a/launcher/ui/pages/global/PastePage.ui b/launcher/ui/pages/global/PastePage.ui index fe372540..2d13a765 100644 --- a/launcher/ui/pages/global/PastePage.ui +++ b/launcher/ui/pages/global/PastePage.ui @@ -38,7 +38,7 @@ Pastebin URL - + @@ -46,6 +46,21 @@ + + + + + 10 + + + + <html><head/><body><p>Note: only input that starts with <span style=" font-weight:600;">http://</span> or <span style=" font-weight:600;">https://</span> will be accepted.</p></body></html> + + + false + + + @@ -69,7 +84,7 @@ - <html><head/><body><p>Here you can choose from a predefined list, or input the URL of a different paste service, provided that it supports the same protocol as 0x0.st, that is POST a file to the URL and return a link in the response body.</p></body></html> + <html><head/><body><p>Here you can choose from a predefined list of paste services, or input the URL of a different paste service of your choice, provided it supports the same protocol as 0x0.st, that is POST a file parameter to the URL and return a link in the response body.</p></body></html> Qt::RichText