From 50d669a1af44471f12d3d9cb9b4c91926c3d8b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= <44851575+zneix@users.noreply.github.com> Date: Sat, 30 May 2020 12:30:30 +0200 Subject: [PATCH] Added possibility to change image uploader's form body with Enviroment Variables (#1709) --- docs/ENV.md | 6 +++++- src/common/Env.cpp | 2 ++ src/common/Env.hpp | 1 + src/util/NuulsUploader.cpp | 9 +++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/ENV.md b/docs/ENV.md index 1615009e6..04944fd3d 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -20,7 +20,7 @@ Arguments: - `%1` = Emote set ID ### CHATTERINO2_IMAGE_UPLOADER_URL -Used to change the URL that Chatterino2 uses when trying to paste an image into chat. This can be used for hosting the uploaded images yourself. +Used to change the URL that Chatterino2 uses when trying to paste an image into chat. This can be used for hosting the uploaded images yourself. Default value: `https://i.nuuls.com/upload` Arguments: @@ -30,6 +30,10 @@ Notes: - If you want to host the images yourself. You need [Nuuls' filehost software](https://github.com/nuuls/filehost) - Other image hosting software is currently not supported. +### CHATTERINO2_IMAGE_UPLOADER_FORM_BODY +Used to change the name of an image form field in a request to the URL that Chatterino2 uses when trying to paste an image into chat. This can be used when your image uploading software accepts a different form field than default value. +Default value: `attachment` + ### CHATTERINO2_TWITCH_SERVER_HOST String value used to change what Twitch chat server host to connect to. Default value: `irc.chat.twitch.tv` diff --git a/src/common/Env.cpp b/src/common/Env.cpp index c1e550d7c..67fefd917 100644 --- a/src/common/Env.cpp +++ b/src/common/Env.cpp @@ -59,6 +59,8 @@ Env::Env() "https://braize.pajlada.com/chatterino/twitchemotes/set/%1/")) , imageUploaderUrl(readStringEnv("CHATTERINO2_IMAGE_UPLOADER_URL", "https://i.nuuls.com/upload")) + , imageUploaderFormBody( + readStringEnv("CHATTERINO2_IMAGE_UPLOADER_FORM_BODY", "attachment")) , twitchServerHost( readStringEnv("CHATTERINO2_TWITCH_SERVER_HOST", "irc.chat.twitch.tv")) , twitchServerPort(readPortEnv("CHATTERINO2_TWITCH_SERVER_PORT", 443)) diff --git a/src/common/Env.hpp b/src/common/Env.hpp index 29c17b6ad..c9794e94f 100644 --- a/src/common/Env.hpp +++ b/src/common/Env.hpp @@ -15,6 +15,7 @@ public: const QString linkResolverUrl; const QString twitchEmoteSetResolverUrl; const QString imageUploaderUrl; + const QString imageUploaderFormBody; const QString twitchServerHost; const uint16_t twitchServerPort; const bool twitchServerSecure; diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index 1678ff474..6c31131cc 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -43,6 +43,7 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel, const static QString contentType = QString("multipart/form-data; boundary=%1").arg(boundary); static QUrl url(Env::get().imageUploaderUrl); + static QString formBody(Env::get().imageUploaderFormBody); QHttpMultiPart *payload = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart part = QHttpPart(); @@ -51,10 +52,10 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel, QString("image/%1").arg(imageData.format)); part.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(imageData.data.length())); - part.setHeader( - QNetworkRequest::ContentDispositionHeader, - QString("form-data; name=\"attachment\"; filename=\"control_v.%1\"") - .arg(imageData.format)); + part.setHeader(QNetworkRequest::ContentDispositionHeader, + QString("form-data; name=\"%1\"; filename=\"control_v.%2\"") + .arg(formBody) + .arg(imageData.format)); payload->setBoundary(boundary); payload->append(part); NetworkRequest(url, NetworkRequestType::Post)