nix/files/flameshot-0x0-upload.patch

112 lines
4.6 KiB
Diff
Raw Normal View History

2024-09-17 16:58:49 +02:00
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
2024-11-08 22:02:57 +01:00
index d6748b5a..7ea3bddd 100644
2024-09-17 16:58:49 +02:00
--- 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)
2024-11-08 22:02:57 +01:00
@@ -31,26 +33,10 @@ void ImgurUploader::handleReply(QNetworkReply* reply)
{
2024-09-17 16:58:49 +02:00
spinner()->deleteLater();
m_currentImageName.clear();
2024-11-08 22:02:57 +01:00
- if (reply->error() == QNetworkReply::NoError) {
2024-09-17 16:58:49 +02:00
- 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);
- }
2024-11-08 22:02:57 +01:00
2024-09-17 16:58:49 +02:00
- // save image to history
- History history;
- m_currentImageName =
- history.packFileName("imgur", deleteToken, m_currentImageName);
- history.save(pixmap(), m_currentImageName);
2024-11-08 22:02:57 +01:00
+ if (reply->error() == QNetworkReply::NoError) {
2024-09-17 16:58:49 +02:00
+ QString img_url = QString(reply->readAll().toStdString().c_str()).trimmed();
+ setImageURL(img_url);
emit uploadOk(imageURL());
} else {
2024-11-08 22:02:57 +01:00
@@ -65,22 +51,20 @@ void ImgurUploader::upload()
2024-09-17 16:58:49 +02:00
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);
2024-11-08 22:02:57 +01:00
+ request.setHeader(QNetworkRequest::UserAgentHeader, QVariant("Flameshot/https://git.jacekpoz.pl/krizej/nix/src/branch/master/files/flameshot-0x0-upload.patch"));
+
2024-09-17 16:58:49 +02:00
+ m_NetworkAM->post(request, multiPart);
}
void ImgurUploader::deleteImage(const QString& fileName,