From a3c38ed2911e80c2a3cb1c3baf8b25c46a82cad6 Mon Sep 17 00:00:00 2001 From: krizej Date: Tue, 17 Sep 2024 16:58:49 +0200 Subject: [PATCH] flameshot 0x0.st upload patch --- files/flameshot-0x0-upload.patch | 107 ++++++++++++++++++ ...status.patch => i3status-format-fix.patch} | 0 modules/stuff/flameshot.nix | 14 ++- pkgs/default.nix | 3 +- 4 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 files/flameshot-0x0-upload.patch rename files/{i3status.patch => i3status-format-fix.patch} (100%) diff --git a/files/flameshot-0x0-upload.patch b/files/flameshot-0x0-upload.patch new file mode 100644 index 0000000..18b8bd4 --- /dev/null +++ b/files/flameshot-0x0-upload.patch @@ -0,0 +1,107 @@ +diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp +index c7eadcad..a0e27094 100644 +--- a/src/core/flameshot.cpp ++++ b/src/core/flameshot.cpp +@@ -393,14 +393,14 @@ void Flameshot::exportCapture(const QPixmap& capture, + + if (tasks & CR::UPLOAD) { + if (!ConfigHandler().uploadWithoutConfirmation()) { +- auto* dialog = new ImgUploadDialog(); +- if (dialog->exec() == QDialog::Rejected) { +- return; +- } ++ // auto* dialog = new ImgUploadDialog(); ++ // if (dialog->exec() == QDialog::Rejected) { ++ // return; ++ // } + } + + ImgUploaderBase* widget = ImgUploaderManager().uploader(capture); +- widget->show(); ++ // widget->show(); + widget->activateWindow(); + // NOTE: lambda can't capture 'this' because it might be destroyed later + CR::ExportTask tasks = tasks; +@@ -411,7 +411,8 @@ void Flameshot::exportCapture(const QPixmap& capture, + FlameshotDaemon::copyToClipboard( + url.toString(), tr("URL copied to clipboard.")); + } +- widget->showPostUploadDialog(); ++ // widget->showPostUploadDialog(); ++ widget->close(); + } + }); + } +diff --git a/src/tools/imgupload/storages/imgur/imguruploader.cpp b/src/tools/imgupload/storages/imgur/imguruploader.cpp +index d6748b5a..ae80c659 100644 +--- a/src/tools/imgupload/storages/imgur/imguruploader.cpp ++++ b/src/tools/imgupload/storages/imgur/imguruploader.cpp +@@ -16,6 +16,8 @@ + #include + #include + #include ++#include ++#include + + ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent) + : ImgUploaderBase(capture, parent) +@@ -32,25 +34,8 @@ void ImgurUploader::handleReply(QNetworkReply* reply) + spinner()->deleteLater(); + m_currentImageName.clear(); + if (reply->error() == QNetworkReply::NoError) { +- QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); +- QJsonObject json = response.object(); +- QJsonObject data = json[QStringLiteral("data")].toObject(); +- setImageURL(data[QStringLiteral("link")].toString()); +- +- auto deleteToken = data[QStringLiteral("deletehash")].toString(); +- +- // save history +- m_currentImageName = imageURL().toString(); +- int lastSlash = m_currentImageName.lastIndexOf("/"); +- if (lastSlash >= 0) { +- m_currentImageName = m_currentImageName.mid(lastSlash + 1); +- } +- +- // save image to history +- History history; +- m_currentImageName = +- history.packFileName("imgur", deleteToken, m_currentImageName); +- history.save(pixmap(), m_currentImageName); ++ QString img_url = QString(reply->readAll().toStdString().c_str()).trimmed(); ++ setImageURL(img_url); + + emit uploadOk(imageURL()); + } else { +@@ -65,22 +50,18 @@ void ImgurUploader::upload() + QBuffer buffer(&byteArray); + pixmap().save(&buffer, "PNG"); + +- QUrlQuery urlQuery; +- urlQuery.addQueryItem(QStringLiteral("title"), QStringLiteral("")); +- QString description = FileNameHandler().parsedPattern(); +- urlQuery.addQueryItem(QStringLiteral("description"), description); ++ QHttpPart fileDataPart; ++ fileDataPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"; filename=\"image.png\"")); ++ fileDataPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream")); ++ fileDataPart.setBody(byteArray); ++ ++ QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); ++ multiPart->append(fileDataPart); + +- QUrl url(QStringLiteral("https://api.imgur.com/3/image")); +- url.setQuery(urlQuery); ++ QUrl url(QStringLiteral("https://0x0.st/")); + QNetworkRequest request(url); +- request.setHeader(QNetworkRequest::ContentTypeHeader, +- "application/application/x-www-form-urlencoded"); +- request.setRawHeader("Authorization", +- QStringLiteral("Client-ID %1") +- .arg(ConfigHandler().uploadClientSecret()) +- .toUtf8()); + +- m_NetworkAM->post(request, byteArray); ++ m_NetworkAM->post(request, multiPart); + } + + void ImgurUploader::deleteImage(const QString& fileName, diff --git a/files/i3status.patch b/files/i3status-format-fix.patch similarity index 100% rename from files/i3status.patch rename to files/i3status-format-fix.patch diff --git a/modules/stuff/flameshot.nix b/modules/stuff/flameshot.nix index 8e200f9..087e353 100644 --- a/modules/stuff/flameshot.nix +++ b/modules/stuff/flameshot.nix @@ -7,12 +7,14 @@ in { enable = mkEnableOption "flameshot"; }; config = mkIf cfg.enable { - home-manager.users.${user}.services.flameshot = { - enable = true; - settings = { - General = { - disabledTrayIcon = true; - showStartupLaunchMessage = false; + home-manager.users.${user} = { + services.flameshot = { + enable = true; + settings = { + General = { + disabledTrayIcon = true; + showStartupLaunchMessage = false; + }; }; }; }; diff --git a/pkgs/default.nix b/pkgs/default.nix index a4133c6..f1eeefc 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -4,7 +4,8 @@ sddm-i3-theme = callPackage ./sddm-i3-theme.nix {}; ericw-tools-latest = callPackage ./ericw-tools-latest.nix {}; alacritty-sixel = callPackage ./alacritty-sixel.nix {}; - i3status = prevPkgs.i3status.overrideAttrs (_: { patches = [ ../files/i3status.patch ]; }); + i3status = prevPkgs.i3status.overrideAttrs (_: { patches = [ ../files/i3status-format-fix.patch ]; }); + flameshot = prevPkgs.flameshot.overrideAttrs (_: { patches = [ ../files/flameshot-0x0-upload.patch ]; }); schildichat-web = callPackage ./schildi/schildichat-web.nix {}; schildichat-desktop = callPackage ./schildi/schildichat-desktop.nix {}; vkquake_ = prevPkgs.vkquake.overrideAttrs (prev: {