2017-04-23 15:05:48 +02:00
|
|
|
#include "imguruploader.hpp"
|
|
|
|
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonValue>
|
|
|
|
#include <io/ioutils.hpp>
|
2017-04-25 22:17:36 +02:00
|
|
|
#include <notifications.hpp>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <screenshotutil.hpp>
|
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void ImgurUploader::doUpload(QPixmap *pixmap) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QByteArray byteArray;
|
|
|
|
QBuffer buffer(&byteArray);
|
|
|
|
pixmap->save(&buffer, "PNG");
|
2017-05-17 22:59:33 +02:00
|
|
|
if (buffer.size() > 1e+7) {
|
|
|
|
notifications::notify("KShare imgur Uploader ", "Failed upload! Image too big");
|
|
|
|
return;
|
|
|
|
}
|
2017-05-09 17:26:00 +02:00
|
|
|
ioutils::postJson(QUrl("https://api.imgur.com/3/image"),
|
|
|
|
QList<QPair<QString, QString>>()
|
|
|
|
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
|
2017-05-13 22:39:05 +02:00
|
|
|
byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QString result = res.object()["data"].toObject()["link"].toString();
|
|
|
|
screenshotutil::toClipboard(result);
|
|
|
|
notifications::notify("KShare imgur Uploader ",
|
2017-05-13 18:32:55 +02:00
|
|
|
result.isEmpty() ? "Failed upload!" : "Uploaded to imgur!");
|
2017-05-09 17:26:00 +02:00
|
|
|
});
|
2017-04-23 15:05:48 +02:00
|
|
|
}
|