Added possibility to change image uploader's form body with Enviroment Variables (#1709)

This commit is contained in:
Paweł 2020-05-30 12:30:30 +02:00 committed by GitHub
parent ccdbedb93c
commit 50d669a1af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 5 deletions

View file

@ -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`

View file

@ -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))

View file

@ -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;

View file

@ -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)