Merge pull request #896 from TheKodeToad/modrinth-token
This commit is contained in:
commit
1dd96898e1
@ -7,6 +7,7 @@
|
|||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 Lenny McLennington <lenny@sneed.church>
|
* Copyright (C) 2022 Lenny McLennington <lenny@sneed.church>
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
||||||
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -225,7 +226,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
m_serverToJoin = parser.value("server");
|
m_serverToJoin = parser.value("server");
|
||||||
m_profileToUse = parser.value("profile");
|
m_profileToUse = parser.value("profile");
|
||||||
m_liveCheck = parser.isSet("alive");
|
m_liveCheck = parser.isSet("alive");
|
||||||
|
|
||||||
m_instanceIdToShowWindowOf = parser.value("show");
|
m_instanceIdToShowWindowOf = parser.value("show");
|
||||||
|
|
||||||
for (auto zip_path : parser.values("import")){
|
for (auto zip_path : parser.values("import")){
|
||||||
@ -346,7 +347,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
import.command = "import";
|
import.command = "import";
|
||||||
import.args.insert("path", zip_url.toString());
|
import.args.insert("path", zip_url.toString());
|
||||||
m_peerInstance->sendMessage(import.serialize(), timeout);
|
m_peerInstance->sendMessage(import.serialize(), timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -660,6 +661,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
m_settings->set("FlameKeyOverride", flameKey);
|
m_settings->set("FlameKeyOverride", flameKey);
|
||||||
m_settings->reset("CFKeyOverride");
|
m_settings->reset("CFKeyOverride");
|
||||||
}
|
}
|
||||||
|
m_settings->registerSetting("ModrinthToken", "");
|
||||||
m_settings->registerSetting("UserAgentOverride", "");
|
m_settings->registerSetting("UserAgentOverride", "");
|
||||||
|
|
||||||
// Init page provider
|
// Init page provider
|
||||||
@ -1548,6 +1550,15 @@ QString Application::getFlameAPIKey()
|
|||||||
return BuildConfig.FLAME_API_KEY;
|
return BuildConfig.FLAME_API_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Application::getModrinthAPIToken()
|
||||||
|
{
|
||||||
|
QString tokenOverride = m_settings->get("ModrinthToken").toString();
|
||||||
|
if (!tokenOverride.isEmpty())
|
||||||
|
return tokenOverride;
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
QString Application::getUserAgent()
|
QString Application::getUserAgent()
|
||||||
{
|
{
|
||||||
QString uaOverride = m_settings->get("UserAgentOverride").toString();
|
QString uaOverride = m_settings->get("UserAgentOverride").toString();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* Prism Launcher - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
* Copyright (C) 2022 Tayou <tayou@gmx.net>
|
||||||
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -177,6 +178,7 @@ public:
|
|||||||
|
|
||||||
QString getMSAClientID();
|
QString getMSAClientID();
|
||||||
QString getFlameAPIKey();
|
QString getFlameAPIKey();
|
||||||
|
QString getModrinthAPIToken();
|
||||||
QString getUserAgent();
|
QString getUserAgent();
|
||||||
QString getUserAgentUncached();
|
QString getUserAgentUncached();
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -113,10 +114,15 @@ void Download::executeTask()
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (APPLICATION->capabilities() & Application::SupportsFlame
|
// TODO remove duplication
|
||||||
&& request.url().host().contains("api.curseforge.com")) {
|
if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
|
||||||
};
|
} else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
|
||||||
|
request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
|
||||||
|
QString token = APPLICATION->getModrinthAPIToken();
|
||||||
|
if (!token.isNull())
|
||||||
|
request.setRawHeader("Authorization", token.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkReply* rep = m_network->get(request);
|
QNetworkReply* rep = m_network->get(request);
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -216,10 +217,16 @@ namespace Net {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (APPLICATION->capabilities() & Application::SupportsFlame
|
// TODO remove duplication
|
||||||
&& request.url().host().contains("api.curseforge.com")) {
|
if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8());
|
||||||
|
} else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
|
||||||
|
request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
|
||||||
|
QString token = APPLICATION->getModrinthAPIToken();
|
||||||
|
if (!token.isNull())
|
||||||
|
request.setRawHeader("Authorization", token.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO other types of post requests ?
|
//TODO other types of post requests ?
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply* rep = m_network->post(request, m_post_data);
|
QNetworkReply* rep = m_network->post(request, m_post_data);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
/*
|
/*
|
||||||
* PolyMC - Minecraft Launcher
|
* Prism Launcher - Minecraft Launcher
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (c) 2022 Lenny McLennington <lenny@sneed.church>
|
* Copyright (c) 2022 Lenny McLennington <lenny@sneed.church>
|
||||||
|
* Copyright (C) 2023 TheKodeToad <TheKodeToad@proton.me>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -147,6 +148,8 @@ void APIPage::loadSettings()
|
|||||||
ui->metaURL->setText(metaURL);
|
ui->metaURL->setText(metaURL);
|
||||||
QString flameKey = s->get("FlameKeyOverride").toString();
|
QString flameKey = s->get("FlameKeyOverride").toString();
|
||||||
ui->flameKey->setText(flameKey);
|
ui->flameKey->setText(flameKey);
|
||||||
|
QString modrinthToken = s->get("ModrinthToken").toString();
|
||||||
|
ui->modrinthToken->setText(modrinthToken);
|
||||||
QString customUserAgent = s->get("UserAgentOverride").toString();
|
QString customUserAgent = s->get("UserAgentOverride").toString();
|
||||||
ui->userAgentLineEdit->setText(customUserAgent);
|
ui->userAgentLineEdit->setText(customUserAgent);
|
||||||
}
|
}
|
||||||
@ -177,6 +180,8 @@ void APIPage::applySettings()
|
|||||||
s->set("MetaURLOverride", metaURL);
|
s->set("MetaURLOverride", metaURL);
|
||||||
QString flameKey = ui->flameKey->text();
|
QString flameKey = ui->flameKey->text();
|
||||||
s->set("FlameKeyOverride", flameKey);
|
s->set("FlameKeyOverride", flameKey);
|
||||||
|
QString modrinthToken = ui->modrinthToken->text();
|
||||||
|
s->set("ModrinthToken", modrinthToken);
|
||||||
s->set("UserAgentOverride", ui->userAgentLineEdit->text());
|
s->set("UserAgentOverride", ui->userAgentLineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,51 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_modrinth">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>&Modrinth API</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string><html><head/><body><p>Note: you only need to set this to access private data. Read the <a href="https://docs.modrinth.com/api-spec/#section/Authentication">documentation</a> for more information.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enter a custom API token for Modrinth here.</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLineEdit" name="modrinthToken">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>(None)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_flame">
|
<widget class="QGroupBox" name="groupBox_flame">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -203,16 +248,16 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&CurseForge Core API</string>
|
<string>&CurseForge Core API</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_8">
|
<widget class="QLabel" name="label_10">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Note: you probably don't need to set this if CurseForge already works.</string>
|
<string>Note: you probably don't need to set this if CurseForge already works.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_9">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enter a custom API Key for CurseForge here.</string>
|
<string>Enter a custom API Key for CurseForge here.</string>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user