KShare/uploaders/default/imguruploader.cpp
ArsenArsen 34624e5762 Redesigned uploaders a bit to support more stuff.
Added a functionality of uploading byte arrays and even files. Created RecordingFormat, which allows me to create states, I guess??, for RecordingContex's. Needed for, eg. gifs, which are horrible and I strongly suggest against, which will actually be stored as files per frame which are QImages encoded with QImage::Format_RGB888 (confirmation needed).
2017-06-04 22:58:29 +02:00

26 lines
1.1 KiB
C++

#include "imguruploader.hpp"
#include <QBuffer>
#include <QJsonObject>
#include <QJsonValue>
#include <io/ioutils.hpp>
#include <notifications.hpp>
#include <screenshotutil.hpp>
void ImgurUploader::doUpload(QByteArray byteArray) {
if (byteArray.size() > 1e+7) {
notifications::notify("KShare imgur Uploader ", "Failed upload! Image too big");
return;
}
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"),
byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) {
QString result = res.object()["data"].toObject()["link"].toString();
screenshotutil::toClipboard(result);
notifications::notify("KShare imgur Uploader ",
result.isEmpty() ? "Failed upload!" : "Uploaded to imgur!");
});
}