feat: custom user-agent
This commit is contained in:
parent
04a3669fc4
commit
25ab121e42
@ -708,6 +708,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
// Custom MSA credentials
|
// Custom MSA credentials
|
||||||
m_settings->registerSetting("MSAClientIDOverride", "");
|
m_settings->registerSetting("MSAClientIDOverride", "");
|
||||||
m_settings->registerSetting("CFKeyOverride", "");
|
m_settings->registerSetting("CFKeyOverride", "");
|
||||||
|
m_settings->registerSetting("UserAgentOverride", "");
|
||||||
|
|
||||||
// Init page provider
|
// Init page provider
|
||||||
{
|
{
|
||||||
@ -1553,3 +1554,23 @@ QString Application::getCurseKey()
|
|||||||
|
|
||||||
return BuildConfig.CURSEFORGE_API_KEY;
|
return BuildConfig.CURSEFORGE_API_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Application::getUserAgent()
|
||||||
|
{
|
||||||
|
QString keyOverride = m_settings->get("UserAgentOverride").toString();
|
||||||
|
if (!keyOverride.isEmpty()) {
|
||||||
|
return keyOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BuildConfig.USER_AGENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Application::getUserAgentUncached()
|
||||||
|
{
|
||||||
|
QString keyOverride = m_settings->get("UserAgentOverride").toString();
|
||||||
|
if (!keyOverride.isEmpty()) {
|
||||||
|
return keyOverride;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BuildConfig.USER_AGENT_UNCACHED;
|
||||||
|
}
|
||||||
|
@ -156,6 +156,8 @@ public:
|
|||||||
|
|
||||||
QString getMSAClientID();
|
QString getMSAClientID();
|
||||||
QString getCurseKey();
|
QString getCurseKey();
|
||||||
|
QString getUserAgent();
|
||||||
|
QString getUserAgentUncached();
|
||||||
|
|
||||||
/// this is the root of the 'installation'. Used for automatic updates
|
/// this is the root of the 'installation'. Used for automatic updates
|
||||||
const QString &root() {
|
const QString &root() {
|
||||||
|
@ -116,7 +116,7 @@ void Download::executeTask()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (request.url().host().contains("api.curseforge.com")) {
|
if (request.url().host().contains("api.curseforge.com")) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
||||||
};
|
};
|
||||||
|
@ -71,7 +71,7 @@ void PasteUpload::executeTask()
|
|||||||
QNetworkRequest request{QUrl(m_uploadUrl)};
|
QNetworkRequest request{QUrl(m_uploadUrl)};
|
||||||
QNetworkReply *rep{};
|
QNetworkReply *rep{};
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
|
|
||||||
switch (m_pasteType) {
|
switch (m_pasteType) {
|
||||||
case NullPointer: {
|
case NullPointer: {
|
||||||
@ -91,7 +91,7 @@ void PasteUpload::executeTask()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Hastebin: {
|
case Hastebin: {
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
rep = APPLICATION->network()->post(request, m_text);
|
rep = APPLICATION->network()->post(request, m_text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ namespace Net {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (request.url().host().contains("api.curseforge.com")) {
|
if (request.url().host().contains("api.curseforge.com")) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ void ImgurAlbumCreation::executeTask()
|
|||||||
{
|
{
|
||||||
m_state = State::Running;
|
m_state = State::Running;
|
||||||
QNetworkRequest request(m_url);
|
QNetworkRequest request(m_url);
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
||||||
request.setRawHeader("Accept", "application/json");
|
request.setRawHeader("Accept", "application/json");
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "ImgurUpload.h"
|
#include "ImgurUpload.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
@ -56,7 +57,7 @@ void ImgurUpload::executeTask()
|
|||||||
finished = false;
|
finished = false;
|
||||||
m_state = Task::State::Running;
|
m_state = Task::State::Running;
|
||||||
QNetworkRequest request(m_url);
|
QNetworkRequest request(m_url);
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
||||||
request.setRawHeader("Accept", "application/json");
|
request.setRawHeader("Accept", "application/json");
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ APIPage::APIPage(QWidget *parent) :
|
|||||||
ui->tabWidget->tabBar()->hide();
|
ui->tabWidget->tabBar()->hide();
|
||||||
|
|
||||||
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
||||||
|
ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT);
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
@ -139,6 +140,8 @@ void APIPage::loadSettings()
|
|||||||
ui->metaURL->setText(metaURL);
|
ui->metaURL->setText(metaURL);
|
||||||
QString curseKey = s->get("CFKeyOverride").toString();
|
QString curseKey = s->get("CFKeyOverride").toString();
|
||||||
ui->curseKey->setText(curseKey);
|
ui->curseKey->setText(curseKey);
|
||||||
|
QString customUserAgent = s->get("UserAgentOverride").toString();
|
||||||
|
ui->userAgentLineEdit->setText(customUserAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIPage::applySettings()
|
void APIPage::applySettings()
|
||||||
@ -167,6 +170,7 @@ void APIPage::applySettings()
|
|||||||
s->set("MetaURLOverride", metaURL);
|
s->set("MetaURLOverride", metaURL);
|
||||||
QString curseKey = ui->curseKey->text();
|
QString curseKey = ui->curseKey->text();
|
||||||
s->set("CFKeyOverride", curseKey);
|
s->set("CFKeyOverride", curseKey);
|
||||||
|
s->set("UserAgentOverride", ui->userAgentLineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APIPage::apply()
|
bool APIPage::apply()
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>600</height>
|
<height>702</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
@ -220,6 +220,31 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_ua">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>User Agent</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="userAgentLineEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="userAgentLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enter a custom User Agent here. The special string ${launcher_version} will be replaced with the version of the launcher.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
Loading…
Reference in New Issue
Block a user