BuildConfig: Make Technic API base URL and build constants

This commit is contained in:
Jamie Mansfield 2022-01-09 23:02:32 +00:00
parent 7f2615b2a5
commit b6e722a048
No known key found for this signature in database
GPG Key ID: 36F61598F39F67B0
3 changed files with 16 additions and 6 deletions

View File

@ -140,6 +140,12 @@ public:
QString ATL_DOWNLOAD_SERVER_URL = "https://download.nodecdn.net/containers/atl/"; QString ATL_DOWNLOAD_SERVER_URL = "https://download.nodecdn.net/containers/atl/";
QString TECHNIC_API_BASE_URL = "https://api.technicpack.net/";
/**
* The build that is reported to the Technic API.
*/
QString TECHNIC_API_BUILD = "multimc";
/** /**
* \brief Converts the Version to a string. * \brief Converts the Version to a string.
* \return The version number in string format (major.minor.revision.build). * \return The version number in string format (major.minor.revision.build).

View File

@ -35,6 +35,7 @@
#include "TechnicModel.h" #include "TechnicModel.h"
#include "Application.h" #include "Application.h"
#include "BuildConfig.h"
#include "Json.h" #include "Json.h"
#include <QIcon> #include <QIcon>
@ -114,21 +115,23 @@ void Technic::ListModel::performSearch()
NetJob *netJob = new NetJob("Technic::Search", APPLICATION->network()); NetJob *netJob = new NetJob("Technic::Search", APPLICATION->network());
QString searchUrl = ""; QString searchUrl = "";
if (currentSearchTerm.isEmpty()) { if (currentSearchTerm.isEmpty()) {
searchUrl = "https://api.technicpack.net/trending?build=multimc"; searchUrl = QString("%1trending?build=%2")
.arg(BuildConfig.TECHNIC_API_BASE_URL, BuildConfig.TECHNIC_API_BUILD);
searchMode = List; searchMode = List;
} }
else if (currentSearchTerm.startsWith("http://api.technicpack.net/modpack/")) { else if (currentSearchTerm.startsWith("http://api.technicpack.net/modpack/")) {
searchUrl = QString("https://%1?build=multimc").arg(currentSearchTerm.mid(7)); searchUrl = QString("https://%1?build=%2")
.arg(currentSearchTerm.mid(7), BuildConfig.TECHNIC_API_BUILD);
searchMode = Single; searchMode = Single;
} }
else if (currentSearchTerm.startsWith("https://api.technicpack.net/modpack/")) { else if (currentSearchTerm.startsWith("https://api.technicpack.net/modpack/")) {
searchUrl = QString("%1?build=multimc").arg(currentSearchTerm); searchUrl = QString("%1?build=%2").arg(currentSearchTerm, BuildConfig.TECHNIC_API_BUILD);
searchMode = Single; searchMode = Single;
} }
else { else {
searchUrl = QString( searchUrl = QString(
"https://api.technicpack.net/search?build=multimc&q=%1" "%1search?build=%2&q=%3"
).arg(currentSearchTerm); ).arg(BuildConfig.TECHNIC_API_BASE_URL, BuildConfig.TECHNIC_API_BUILD, currentSearchTerm);
searchMode = List; searchMode = List;
} }
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));

View File

@ -40,6 +40,7 @@
#include "ui/dialogs/NewInstanceDialog.h" #include "ui/dialogs/NewInstanceDialog.h"
#include "BuildConfig.h"
#include "TechnicModel.h" #include "TechnicModel.h"
#include "modplatform/technic/SingleZipPackInstallTask.h" #include "modplatform/technic/SingleZipPackInstallTask.h"
#include "modplatform/technic/SolderPackInstallTask.h" #include "modplatform/technic/SolderPackInstallTask.h"
@ -142,7 +143,7 @@ void TechnicPage::suggestCurrent()
NetJob *netJob = new NetJob(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network()); NetJob *netJob = new NetJob(QString("Technic::PackMeta(%1)").arg(current.name), APPLICATION->network());
QString slug = current.slug; QString slug = current.slug;
netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.technicpack.net/modpack/%1?build=multimc").arg(slug), &response)); netJob->addNetAction(Net::Download::makeByteArray(QString("%1modpack/%2?build=%3").arg(BuildConfig.TECHNIC_API_BASE_URL, slug, BuildConfig.TECHNIC_API_BUILD), &response));
QObject::connect(netJob, &NetJob::succeeded, this, [this, slug] QObject::connect(netJob, &NetJob::succeeded, this, [this, slug]
{ {
jobPtr.reset(); jobPtr.reset();