aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/modrinth
diff options
context:
space:
mode:
authorflow <thiagodonato300@gmail.com>2022-03-02 23:01:23 -0300
committerflow <thiagodonato300@gmail.com>2022-03-02 23:13:04 -0300
commit2d68308d4920be4c28a73d7646814765eee7b7a2 (patch)
treeac0c9abf5a1f33bc13b8f885070904e7e7bfe43d /launcher/modplatform/modrinth
parent0dd1c26cf3cd68cd83f5d9da6cf34d4aa3f30db2 (diff)
downloadPrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.tar.gz
PrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.tar.bz2
PrismLauncher-2d68308d4920be4c28a73d7646814765eee7b7a2.zip
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
Diffstat (limited to 'launcher/modplatform/modrinth')
-rw-r--r--launcher/modplatform/modrinth/ModrinthAPI.h25
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.cpp5
2 files changed, 29 insertions, 1 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h
new file mode 100644
index 00000000..4ae8b8f9
--- /dev/null
+++ b/launcher/modplatform/modrinth/ModrinthAPI.h
@@ -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; };
+};
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
index a59186f7..02aac34d 100644
--- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
@@ -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);
}