From 20c393321c894adb4cb938a3f865f331c985cda9 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 1 Jul 2021 19:24:29 +0100 Subject: [PATCH] NOISSUE Use constants for user agents Here lies yet another early-stage move to debrand the MultiMC codebase, as well as reducing the burden of updating strings across the codebase for a future MultiMC6. --- api/logic/net/Download.cpp | 3 ++- api/logic/net/PasteUpload.cpp | 3 ++- api/logic/screenshots/ImgurAlbumCreation.cpp | 2 +- api/logic/screenshots/ImgurUpload.cpp | 2 +- buildconfig/BuildConfig.h | 5 +++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/logic/net/Download.cpp b/api/logic/net/Download.cpp index 340f8657..3f183b7d 100644 --- a/api/logic/net/Download.cpp +++ b/api/logic/net/Download.cpp @@ -15,6 +15,7 @@ #include "Download.h" +#include "BuildConfig.h" #include #include #include @@ -94,7 +95,7 @@ void Download::start() return; } - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT); QNetworkReply *rep = ENV.qnam().get(request); diff --git a/api/logic/net/PasteUpload.cpp b/api/logic/net/PasteUpload.cpp index 3526e207..cb470c49 100644 --- a/api/logic/net/PasteUpload.cpp +++ b/api/logic/net/PasteUpload.cpp @@ -5,6 +5,7 @@ #include #include #include +#include PasteUpload::PasteUpload(QWidget *window, QString text, QString key) : m_window(window) { @@ -34,7 +35,7 @@ bool PasteUpload::validateText() void PasteUpload::executeTask() { QNetworkRequest request(QUrl("https://api.paste.ee/v1/pastes")); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setRawHeader("Content-Type", "application/json"); request.setRawHeader("Content-Length", QByteArray::number(m_jsonContent.size())); diff --git a/api/logic/screenshots/ImgurAlbumCreation.cpp b/api/logic/screenshots/ImgurAlbumCreation.cpp index ff9ec6fd..07ae6fe1 100644 --- a/api/logic/screenshots/ImgurAlbumCreation.cpp +++ b/api/logic/screenshots/ImgurAlbumCreation.cpp @@ -20,7 +20,7 @@ void ImgurAlbumCreation::start() { m_status = Job_InProgress; QNetworkRequest request(m_url); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); diff --git a/api/logic/screenshots/ImgurUpload.cpp b/api/logic/screenshots/ImgurUpload.cpp index 1585b061..062c589f 100644 --- a/api/logic/screenshots/ImgurUpload.cpp +++ b/api/logic/screenshots/ImgurUpload.cpp @@ -23,7 +23,7 @@ void ImgurUpload::start() finished = false; m_status = Job_InProgress; QNetworkRequest request(m_url); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 66d05ae0..07d7a23a 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -31,6 +31,11 @@ public: /// URL for the updater's channel QString CHANLIST_URL; + /// User-Agent to use. + QString USER_AGENT = "MultiMC/5.0"; + /// User-Agent to use for uncached requests. + QString USER_AGENT_UNCACHED = "MultiMC/5.0 (Uncached)"; + /// Google analytics ID QString ANALYTICS_ID;