nix/files/flameshot-0x0-upload.patch
2024-11-09 16:46:50 +01:00

111 lines
4.6 KiB
Diff

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..7ea3bddd 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)
@@ -31,26 +33,10 @@ 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);
+ if (reply->error() == QNetworkReply::NoError) {
+ QString img_url = QString(reply->readAll().toStdString().c_str()).trimmed();
+ setImageURL(img_url);
emit uploadOk(imageURL());
} else {
@@ -65,22 +51,20 @@ 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);
+ request.setHeader(QNetworkRequest::UserAgentHeader, QVariant("Flameshot/https://git.jacekpoz.pl/krizej/nix/src/branch/master/files/flameshot-0x0-upload.patch"));
+
+ m_NetworkAM->post(request, multiPart);
}
void ImgurUploader::deleteImage(const QString& fileName,