flameshot 0x0.st upload patch

This commit is contained in:
krizej 2024-09-17 16:58:49 +02:00
parent 79bad31c5d
commit a3c38ed291
4 changed files with 117 additions and 7 deletions

View file

@ -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 <QNetworkRequest>
#include <QShortcut>
#include <QUrlQuery>
+#include <QHttpPart>
+#include <QHttpMultiPart>
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,

View file

@ -7,7 +7,8 @@ in {
enable = mkEnableOption "flameshot"; enable = mkEnableOption "flameshot";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home-manager.users.${user}.services.flameshot = { home-manager.users.${user} = {
services.flameshot = {
enable = true; enable = true;
settings = { settings = {
General = { General = {
@ -17,4 +18,5 @@ in {
}; };
}; };
}; };
};
} }

View file

@ -4,7 +4,8 @@
sddm-i3-theme = callPackage ./sddm-i3-theme.nix {}; sddm-i3-theme = callPackage ./sddm-i3-theme.nix {};
ericw-tools-latest = callPackage ./ericw-tools-latest.nix {}; ericw-tools-latest = callPackage ./ericw-tools-latest.nix {};
alacritty-sixel = callPackage ./alacritty-sixel.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-web = callPackage ./schildi/schildichat-web.nix {};
schildichat-desktop = callPackage ./schildi/schildichat-desktop.nix {}; schildichat-desktop = callPackage ./schildi/schildichat-desktop.nix {};
vkquake_ = prevPkgs.vkquake.overrideAttrs (prev: { vkquake_ = prevPkgs.vkquake.overrideAttrs (prev: {