mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Initial work on allowing extra form fields in image uploader
This commit is contained in:
parent
1d272c399b
commit
d24b903596
|
@ -358,6 +358,9 @@ public:
|
|||
QStringSetting imageUploaderLink = {"/external/imageUploader/link", ""};
|
||||
QStringSetting imageUploaderDeletionLink = {
|
||||
"/external/imageUploader/deletionLink", ""};
|
||||
ChatterinoSetting<std::vector<std::pair<QString, QString>>>
|
||||
imageUploaderExtraFormFields = {
|
||||
"/external/imageUploader/extraFormFields", {}};
|
||||
|
||||
/// Misc
|
||||
BoolSetting betaUpdates = {"/misc/beta", false};
|
||||
|
|
|
@ -149,6 +149,18 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel,
|
|||
payload->setBoundary(boundary);
|
||||
payload->append(part);
|
||||
|
||||
for (const auto &extraFormField :
|
||||
getSettings()->imageUploaderExtraFormFields.getValue())
|
||||
{
|
||||
QHttpPart extraPart;
|
||||
extraPart.setHeader(
|
||||
QNetworkRequest::ContentDispositionHeader,
|
||||
QString("form-data; name=\"%1\"").arg(extraFormField.first));
|
||||
extraPart.setBody(extraFormField.second.toUtf8());
|
||||
|
||||
payload->append(extraPart);
|
||||
}
|
||||
|
||||
NetworkRequest(url, NetworkRequestType::Post)
|
||||
.header("Content-Type", contentType)
|
||||
.headerList(extraHeaders)
|
||||
|
|
|
@ -131,6 +131,48 @@ ExternalToolsPage::ExternalToolsPage()
|
|||
groupLayout->addRow(
|
||||
"Form field: ",
|
||||
this->createLineEdit(getSettings()->imageUploaderFormField));
|
||||
{
|
||||
auto *edit = new QLineEdit(this);
|
||||
auto &setting = getSettings()->imageUploaderExtraFormFields;
|
||||
|
||||
setting.connect(
|
||||
[=](const auto &extraFormFields, auto) {
|
||||
qDebug() << "setting changed";
|
||||
QString finalString;
|
||||
for (const auto &ff : extraFormFields)
|
||||
{
|
||||
finalString +=
|
||||
QString("%1=%2|").arg(ff.first, ff.second);
|
||||
}
|
||||
edit->setText(finalString);
|
||||
},
|
||||
this->managedConnections_);
|
||||
|
||||
QObject::connect(
|
||||
edit, &QLineEdit::editingFinished, [edit, &setting]() {
|
||||
auto newValue = edit->text();
|
||||
std::vector<std::pair<QString, QString>> finalValue;
|
||||
|
||||
const auto &parts = newValue.split('|', Qt::SkipEmptyParts);
|
||||
for (const auto &part : parts)
|
||||
{
|
||||
const auto &key = part.section('=', 0, 0);
|
||||
const auto &value = part.section(
|
||||
'=', 1, -1, QString::SectionIncludeTrailingSep);
|
||||
|
||||
if (key.isEmpty() || value.isEmpty())
|
||||
{
|
||||
// Both key and value must be set
|
||||
continue;
|
||||
}
|
||||
finalValue.emplace_back(key, value);
|
||||
}
|
||||
|
||||
setting = finalValue;
|
||||
});
|
||||
|
||||
groupLayout->addRow("Extra form fields: ", edit);
|
||||
}
|
||||
groupLayout->addRow(
|
||||
"Extra Headers: ",
|
||||
this->createLineEdit(getSettings()->imageUploaderHeaders));
|
||||
|
|
Loading…
Reference in a new issue