From 1feb63052020db941a3c1a10d14c9a4791169c1a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Wed, 1 Mar 2023 09:54:49 +0000 Subject: [PATCH 1/9] Allow custom Modrinth API token Signed-off-by: TheKodeToad --- launcher/Application.cpp | 15 ++++++++-- launcher/Application.h | 2 ++ launcher/net/Download.cpp | 7 ++++- launcher/net/Upload.cpp | 6 ++++ launcher/ui/pages/global/APIPage.cpp | 5 ++++ launcher/ui/pages/global/APIPage.ui | 45 ++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index caaa74c8..d6de6236 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -7,6 +7,7 @@ * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Lenny McLennington * Copyright (C) 2022 Tayou + * Copyright (C) 2023 TheKodeToad * * 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 @@ -225,7 +226,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_serverToJoin = parser.value("server"); m_profileToUse = parser.value("profile"); m_liveCheck = parser.isSet("alive"); - + m_instanceIdToShowWindowOf = parser.value("show"); for (auto zip_path : parser.values("import")){ @@ -346,7 +347,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) import.command = "import"; import.args.insert("path", zip_url.toString()); m_peerInstance->sendMessage(import.serialize(), timeout); - } + } } } else @@ -657,6 +658,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_settings->set("FlameKeyOverride", flameKey); m_settings->reset("CFKeyOverride"); } + m_settings->registerSetting("ModrinthToken", ""); m_settings->registerSetting("UserAgentOverride", ""); // Init page provider @@ -1545,6 +1547,15 @@ QString Application::getFlameAPIKey() 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 uaOverride = m_settings->get("UserAgentOverride").toString(); diff --git a/launcher/Application.h b/launcher/Application.h index 1b3dc499..91c5fc63 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -3,6 +3,7 @@ * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2022 Tayou + * Copyright (C) 2023 TheKodeToad * * 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 @@ -177,6 +178,7 @@ public: QString getMSAClientID(); QString getFlameAPIKey(); + QString getModrinthAPIToken(); QString getUserAgent(); QString getUserAgentUncached(); diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index 5982c8c9..0816e926 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -3,6 +3,7 @@ * PolyMC - Minecraft Launcher * Copyright (c) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2023 TheKodeToad * * 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 @@ -116,7 +117,11 @@ void Download::executeTask() if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host().contains("api.curseforge.com")) { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); - }; + } else if (request.url().host().contains("api.modrinth.com")) { + QString token = APPLICATION->getModrinthAPIToken(); + if (!token.isNull()) + request.setRawHeader("Authorization", token.toUtf8()); + } QNetworkReply* rep = m_network->get(request); diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp index 79b6af8d..36d50c1e 100644 --- a/launcher/net/Upload.cpp +++ b/launcher/net/Upload.cpp @@ -3,6 +3,7 @@ * PolyMC - Minecraft Launcher * Copyright (c) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2023 TheKodeToad * * 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 @@ -219,7 +220,12 @@ namespace Net { if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host().contains("api.curseforge.com")) { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); + } else if (request.url().host().contains("api.modrinth.com")) { + QString token = APPLICATION->getModrinthAPIToken(); + if (!token.isNull()) + request.setRawHeader("Authorization", token.toUtf8()); } + //TODO other types of post requests ? request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QNetworkReply* rep = m_network->post(request, m_post_data); diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index e3d30475..ac74b3a1 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -4,6 +4,7 @@ * Copyright (C) 2022 Sefa Eyeoglu * Copyright (c) 2022 Jamie Mansfield * Copyright (c) 2022 Lenny McLennington + * Copyright (C) 2023 TheKodeToad * * 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 @@ -147,6 +148,8 @@ void APIPage::loadSettings() ui->metaURL->setText(metaURL); QString flameKey = s->get("FlameKeyOverride").toString(); ui->flameKey->setText(flameKey); + QString modrinthToken = s->get("ModrinthToken").toString(); + ui->modrinthToken->setText(modrinthToken); QString customUserAgent = s->get("UserAgentOverride").toString(); ui->userAgentLineEdit->setText(customUserAgent); } @@ -177,6 +180,8 @@ void APIPage::applySettings() s->set("MetaURLOverride", metaURL); QString flameKey = ui->flameKey->text(); s->set("FlameKeyOverride", flameKey); + QString modrinthToken = ui->modrinthToken->text(); + s->set("ModrinthToken", modrinthToken); s->set("UserAgentOverride", ui->userAgentLineEdit->text()); } diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index d56a9ef6..b09a86ee 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -240,6 +240,51 @@ + + + + true + + + &Modrinth API + + + + + + Note: you only need to set this to access private data. + + + + + + + Enter a custom API token for Modrinth here. + + + Qt::RichText + + + true + + + true + + + + + + + true + + + (None) + + + + + + From a7b80922967744efa6c9ffba457ac6850d4f660a Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Wed, 1 Mar 2023 14:41:13 +0000 Subject: [PATCH 2/9] Add link Signed-off-by: TheKodeToad --- launcher/ui/pages/global/APIPage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index b09a86ee..431fd8c6 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -252,7 +252,7 @@ - Note: you only need to set this to access private data. + <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"><span style=" text-decoration: underline; color:#0000ff;">documentation</span></a> for more information.</p></body></html> From 1f3d18ec12bb7a971962101570cbad8e18788614 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 2 Mar 2023 09:26:00 +0000 Subject: [PATCH 3/9] Replace with exact match and add TODO to improve Signed-off-by: TheKodeToad --- launcher/net/Download.cpp | 5 +++-- launcher/net/Upload.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index 0816e926..adb3d6fa 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -114,10 +114,11 @@ void Download::executeTask() } request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); + // TODO remove duplication and use constant if (APPLICATION->capabilities() & Application::SupportsFlame - && request.url().host().contains("api.curseforge.com")) { + && request.url().host() == "api.curseforge.com") { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); - } else if (request.url().host().contains("api.modrinth.com")) { + } else if (request.url().host() == "api.modrinth.com") { QString token = APPLICATION->getModrinthAPIToken(); if (!token.isNull()) request.setRawHeader("Authorization", token.toUtf8()); diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp index 36d50c1e..cd0de945 100644 --- a/launcher/net/Upload.cpp +++ b/launcher/net/Upload.cpp @@ -217,10 +217,11 @@ namespace Net { } request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); + // TODO remove duplication and use constant if (APPLICATION->capabilities() & Application::SupportsFlame - && request.url().host().contains("api.curseforge.com")) { + && request.url().host() == "api.curseforge.com") { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); - } else if (request.url().host().contains("api.modrinth.com")) { + } else if (request.url().host() == "api.modrinth.com") { QString token = APPLICATION->getModrinthAPIToken(); if (!token.isNull()) request.setRawHeader("Authorization", token.toUtf8()); From cbe6eff2fa917401b913a96c551429caad852b3b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 2 Mar 2023 09:28:14 +0000 Subject: [PATCH 4/9] Move Modrinth before CurseForge for consistency Signed-off-by: TheKodeToad --- launcher/ui/pages/global/APIPage.ui | 90 ++++++++++++++--------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 431fd8c6..8c515f3a 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -195,51 +195,6 @@ - - - - true - - - &CurseForge Core API - - - - - - Note: you probably don't need to set this if CurseForge already works. - - - - - - - Enter a custom API Key for CurseForge here. - - - Qt::RichText - - - true - - - true - - - - - - - true - - - (Default) - - - - - - @@ -285,6 +240,51 @@ + + + + true + + + &CurseForge Core API + + + + + + Note: you probably don't need to set this if CurseForge already works. + + + + + + + Enter a custom API Key for CurseForge here. + + + Qt::RichText + + + true + + + true + + + + + + + true + + + (Default) + + + + + + From 4efbf22089bc1fc49409cb31bfffe26cdb9b6b36 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 2 Mar 2023 10:19:26 +0000 Subject: [PATCH 5/9] Prism-ify more license headers Signed-off-by: TheKodeToad --- launcher/net/Download.cpp | 2 +- launcher/net/Upload.cpp | 2 +- launcher/ui/pages/global/APIPage.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index adb3d6fa..f199c0b2 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2023 TheKodeToad diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp index cd0de945..b90c71ba 100644 --- a/launcher/net/Upload.cpp +++ b/launcher/net/Upload.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (c) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu * Copyright (C) 2023 TheKodeToad diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index ac74b3a1..f662ee1c 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu * Copyright (c) 2022 Jamie Mansfield * Copyright (c) 2022 Lenny McLennington From 76f66148db09b6110d2d916da5c9f9f4dae139b8 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 5 Mar 2023 18:21:24 +0000 Subject: [PATCH 6/9] Apply flowln's suggestion Signed-off-by: TheKodeToad --- launcher/net/Download.cpp | 8 ++++---- launcher/net/Upload.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp index f199c0b2..e8a1d0b0 100644 --- a/launcher/net/Download.cpp +++ b/launcher/net/Download.cpp @@ -114,11 +114,11 @@ void Download::executeTask() } request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); - // TODO remove duplication and use constant - if (APPLICATION->capabilities() & Application::SupportsFlame - && request.url().host() == "api.curseforge.com") { + // TODO remove duplication + if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); - } else if (request.url().host() == "api.modrinth.com") { + } 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()); diff --git a/launcher/net/Upload.cpp b/launcher/net/Upload.cpp index b90c71ba..ccf43c2d 100644 --- a/launcher/net/Upload.cpp +++ b/launcher/net/Upload.cpp @@ -217,11 +217,11 @@ namespace Net { } request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8()); - // TODO remove duplication and use constant - if (APPLICATION->capabilities() & Application::SupportsFlame - && request.url().host() == "api.curseforge.com") { + // TODO remove duplication + if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) { request.setRawHeader("x-api-key", APPLICATION->getFlameAPIKey().toUtf8()); - } else if (request.url().host() == "api.modrinth.com") { + } 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()); From 088be050b245dc60e799e677369cb4d9d941c0fe Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 7 Mar 2023 20:46:27 +0000 Subject: [PATCH 7/9] Apply flowln's suggestion :) Co-authored-by: flow Signed-off-by: TheKodeToad --- launcher/ui/pages/global/APIPage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 8c515f3a..91f867e0 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -207,7 +207,7 @@ - <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"><span style=" text-decoration: underline; color:#0000ff;">documentation</span></a> for more information.</p></body></html> + <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> From 59cf8f678f6e3448dae1af99a59eb4d0157408c9 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 7 Mar 2023 20:50:19 +0000 Subject: [PATCH 8/9] (hopefully) Fix duplicates names Signed-off-by: TheKodeToad --- launcher/ui/pages/global/APIPage.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index 91f867e0..d866d7f9 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -250,14 +250,14 @@ - + Note: you probably don't need to set this if CurseForge already works. - + Enter a custom API Key for CurseForge here. From 59b15c5f08e00e2da0f77b9544881e93158320ed Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 7 Mar 2023 21:03:09 +0000 Subject: [PATCH 9/9] Fix another duplicate name :facepalm: Signed-off-by: TheKodeToad --- launcher/ui/pages/global/APIPage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index d866d7f9..40b89d91 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -248,7 +248,7 @@ &CurseForge Core API - +