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:
12
launcher/modplatform/ModAPI.h
Normal file
12
launcher/modplatform/ModAPI.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
class ModAPI {
|
||||
public:
|
||||
virtual ~ModAPI() = default;
|
||||
|
||||
inline virtual QString getModSearchURL(int, QString, QString, bool, QString) const { return ""; };
|
||||
inline virtual QString getVersionsURL(const QString& addonId) const { return ""; };
|
||||
inline virtual QString getAuthorURL(const QString& name) const { return ""; };
|
||||
};
|
27
launcher/modplatform/flame/FlameAPI.h
Normal file
27
launcher/modplatform/flame/FlameAPI.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "modplatform/ModAPI.h"
|
||||
|
||||
class FlameAPI : public ModAPI {
|
||||
public:
|
||||
inline QString getModSearchURL(int index, QString searchFilter, QString sort, bool fabricCompatible, QString version) const override
|
||||
{
|
||||
return QString("https://addons-ecs.forgesvc.net/api/v2/addon/search?"
|
||||
"gameId=432&" "categoryId=0&" "sectionId=6&"
|
||||
|
||||
"index=%1&" "pageSize=25&" "searchFilter=%2&"
|
||||
"sort=%3&" "modLoaderType=%4&" "gameVersion=%5")
|
||||
.arg(index)
|
||||
.arg(searchFilter)
|
||||
.arg(sort)
|
||||
.arg(fabricCompatible ? 4 : 1) // Enum: https://docs.curseforge.com/?http#tocS_ModLoaderType
|
||||
.arg(version);
|
||||
};
|
||||
|
||||
inline QString getVersionsURL(const QString& addonId) const override
|
||||
{
|
||||
return QString("https://addons-ecs.forgesvc.net/api/v2/addon/%1/files").arg(addonId);
|
||||
};
|
||||
|
||||
inline QString getAuthorURL(const QString& name) const override { return ""; };
|
||||
};
|
25
launcher/modplatform/modrinth/ModrinthAPI.h
Normal file
25
launcher/modplatform/modrinth/ModrinthAPI.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "modplatform/ModAPI.h"
|
||||
|
||||
class ModrinthAPI : public ModAPI {
|
||||
public:
|
||||
inline QString getModSearchURL(int offset, QString query, QString sort, bool fabricCompatible, QString version) const override
|
||||
{
|
||||
return QString("https://api.modrinth.com/v2/search?"
|
||||
"offset=%1&" "limit=25&" "query=%2&" "index=%3&"
|
||||
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
|
||||
.arg(offset)
|
||||
.arg(query)
|
||||
.arg(sort)
|
||||
.arg(fabricCompatible ? "fabric" : "forge")
|
||||
.arg(version);
|
||||
};
|
||||
|
||||
inline QString getVersionsURL(const QString& addonId) const override
|
||||
{
|
||||
return QString("https://api.modrinth.com/v2/project/%1/version").arg(addonId);
|
||||
};
|
||||
|
||||
inline QString getAuthorURL(const QString& name) const override { return "https://modrinth.com/user/" + name; };
|
||||
};
|
@ -1,10 +1,13 @@
|
||||
#include "ModrinthPackIndex.h"
|
||||
#include "ModrinthAPI.h"
|
||||
|
||||
#include "Json.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
static ModrinthAPI api;
|
||||
|
||||
void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
{
|
||||
pack.addonId = Json::requireString(obj, "project_id");
|
||||
@ -17,7 +20,7 @@ void Modrinth::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
|
||||
|
||||
ModPlatform::ModpackAuthor modAuthor;
|
||||
modAuthor.name = Json::requireString(obj, "author");
|
||||
modAuthor.url = "https://modrinth.com/user/" + modAuthor.name;
|
||||
modAuthor.url = api.getAuthorURL(modAuthor.name);
|
||||
pack.authors.append(modAuthor);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user