refactor: move url creation for mods to modplatform/
Moves all things related to creating the URLs of the mod platforms that go to network tasks to a single place, so that: 1. Maintaining and fixing eventual issues is more straightforward. 2. Makes it possible to factor out more common code between the different modplatform pages
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
#include "ModrinthModel.h"
|
||||
#include "ModrinthPage.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
#include <Json.h>
|
||||
|
||||
@ -11,37 +10,6 @@ ListModel::ListModel(ModrinthPage* parent) : ModPlatform::ListModel(parent) {}
|
||||
|
||||
ListModel::~ListModel() {}
|
||||
|
||||
const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
|
||||
|
||||
void ListModel::performPaginatedSearch()
|
||||
{
|
||||
QString mcVersion = ((MinecraftInstance*)((ModrinthPage*)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft");
|
||||
bool hasFabric = !((MinecraftInstance*)((ModrinthPage*)parent())->m_instance)
|
||||
->getPackProfile()
|
||||
->getComponentVersion("net.fabricmc.fabric-loader")
|
||||
.isEmpty();
|
||||
auto netJob = new NetJob("Modrinth::Search", APPLICATION->network());
|
||||
auto searchUrl = QString(
|
||||
"https://api.modrinth.com/v2/search?"
|
||||
"offset=%1&"
|
||||
"limit=25&"
|
||||
"query=%2&"
|
||||
"index=%3&"
|
||||
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
|
||||
.arg(nextSearchOffset)
|
||||
.arg(currentSearchTerm)
|
||||
.arg(sorts[currentSort])
|
||||
.arg(hasFabric ? "fabric" : "forge")
|
||||
.arg(mcVersion);
|
||||
|
||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
|
||||
jobPtr = netJob;
|
||||
jobPtr->start();
|
||||
|
||||
QObject::connect(netJob, &NetJob::succeeded, this, &Modrinth::ListModel::searchRequestFinished);
|
||||
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
|
||||
}
|
||||
|
||||
void Modrinth::ListModel::searchRequestFinished()
|
||||
{
|
||||
jobPtr.reset();
|
||||
@ -80,4 +48,11 @@ void Modrinth::ListModel::searchRequestFinished()
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
const char* sorts[5]{ "relevance", "downloads", "follows", "updated", "newest" };
|
||||
|
||||
const char** Modrinth::ListModel::getSorts() const
|
||||
{
|
||||
return sorts;
|
||||
}
|
||||
|
||||
} // namespace Modrinth
|
||||
|
Reference in New Issue
Block a user