Add in return_{ap,pre}pend

This commit is contained in:
ArsenArsen 2017-07-20 00:40:39 +02:00
parent f0dfe3d391
commit e55185da05
2 changed files with 10 additions and 5 deletions

View File

@ -130,6 +130,8 @@ CustomUploader::CustomUploader(QString absFilePath) {
base64 = bool64.toBool(); base64 = bool64.toBool();
if (rFormat == RequestFormat::JSON && !base64) error(absFilePath, "base64 required with json"); if (rFormat == RequestFormat::JSON && !base64) error(absFilePath, "base64 required with json");
} }
urlPrepend = obj["return_prepend"].toString();
urlAppend = obj["return_append"].toString();
} }
QString CustomUploader::name() { QString CustomUploader::name() {
@ -191,6 +193,8 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
return ""; return "";
else if (val.isString()) else if (val.isString())
return val.toString(); return val.toString();
else if (val.isArray())
val = val.toArray()[fields.at(i).toInt()];
else if (!val.isObject()) else if (!val.isObject())
return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson()); return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
else else
@ -206,9 +210,9 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
return ""; return "";
} }
void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name) { void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name, QString urlPrepend, QString urlAppend) {
if (result.isObject()) { if (result.isObject()) {
QString url = parsePathspec(result, returnPathspec); QString url = urlPrepend + parsePathspec(result, returnPathspec) + urlAppend;
if (!url.isEmpty()) { if (!url.isEmpty()) {
QApplication::clipboard()->setText(url); QApplication::clipboard()->setText(url);
notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!"); notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
@ -340,13 +344,13 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) { [&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
for (auto buffer : buffersToDelete) buffer->deleteLater(); for (auto buffer : buffersToDelete) buffer->deleteLater();
for (auto arr : arraysToDelete) delete arr; for (auto arr : arraysToDelete) delete arr;
parseResult(result, data, returnPathspec, name()); parseResult(result, data, returnPathspec, name(), urlPrepend, urlPrepend);
}); });
} }
break; break;
} }
return; return;
} break; }
} }
if (limit > 0 && data.size() > limit) { if (limit > 0 && data.size() > limit) {
notifications::notify("KShare Custom Uploader " + name(), "File limit exceeded!"); notifications::notify("KShare Custom Uploader " + name(), "File limit exceeded!");
@ -361,7 +365,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
}); });
} else { } else {
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) { ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
parseResult(result, data, returnPathspec, name()); parseResult(result, data, returnPathspec, name(), urlPrepend, urlPrepend);
}); });
} }
break; break;

View File

@ -28,6 +28,7 @@ private:
QJsonObject headers; QJsonObject headers;
bool base64 = false; bool base64 = false;
QString returnPathspec; QString returnPathspec;
QString urlPrepend, urlAppend;
}; };
#endif // CUSTOMUPLOADER_HPP #endif // CUSTOMUPLOADER_HPP