aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/modrinth
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-12-20 12:15:17 -0300
committerflow <flowlnlnln@gmail.com>2023-01-13 16:23:07 -0300
commit36571c5e2237c98e194cff326480ebe3e661c586 (patch)
tree7a7bb0f1df380ded2ed6be227f61ef01e86c6e77 /launcher/modplatform/modrinth
parentc8eca4fb8508a22b9d4819d57627dd684f8d98c5 (diff)
downloadPrismLauncher-36571c5e2237c98e194cff326480ebe3e661c586.tar.gz
PrismLauncher-36571c5e2237c98e194cff326480ebe3e661c586.tar.bz2
PrismLauncher-36571c5e2237c98e194cff326480ebe3e661c586.zip
refactor(RD): clear up sorting methods
This refactors the sorting methods to join every bit of it into a single list, easing maintanance. It also removes the weird index contraint on the list of methods by adding an index field to the DS that holds the method. Lastly, it puts the available methods on their respective API, so other resources on the same API can re-use them later on. Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/modplatform/modrinth')
-rw-r--r--launcher/modplatform/modrinth/ModrinthAPI.cpp12
-rw-r--r--launcher/modplatform/modrinth/ModrinthAPI.h4
2 files changed, 15 insertions, 1 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthAPI.cpp b/launcher/modplatform/modrinth/ModrinthAPI.cpp
index 8e64be09..8d7e3acf 100644
--- a/launcher/modplatform/modrinth/ModrinthAPI.cpp
+++ b/launcher/modplatform/modrinth/ModrinthAPI.cpp
@@ -112,3 +112,15 @@ NetJob::Ptr ModrinthAPI::getProjects(QStringList addonIds, QByteArray* response)
return netJob;
}
+
+// https://docs.modrinth.com/api-spec/#tag/projects/operation/searchProjects
+static QList<ResourceAPI::SortingMethod> s_sorts = { { 1, "relevance", QObject::tr("Sort by Relevance") },
+ { 2, "downloads", QObject::tr("Sort by Downloads") },
+ { 3, "follows", QObject::tr("Sort by Follows") },
+ { 4, "newest", QObject::tr("Sort by Last Updated") },
+ { 5, "updated", QObject::tr("Sort by Newest") } };
+
+QList<ResourceAPI::SortingMethod> ModrinthAPI::getSortingMethods() const
+{
+ return s_sorts;
+}
diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h
index ec38d9ee..949fc46e 100644
--- a/launcher/modplatform/modrinth/ModrinthAPI.h
+++ b/launcher/modplatform/modrinth/ModrinthAPI.h
@@ -49,6 +49,8 @@ class ModrinthAPI : public NetworkResourceAPI {
NetJob::Ptr getProjects(QStringList addonIds, QByteArray* response) const override;
public:
+ [[nodiscard]] auto getSortingMethods() const -> QList<ResourceAPI::SortingMethod> override;
+
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };
static auto getModLoaderStrings(const ModLoaderTypes types) -> const QStringList
@@ -116,7 +118,7 @@ class ModrinthAPI : public NetworkResourceAPI {
if (args.search.has_value())
get_arguments.append(QString("query=%1").arg(args.search.value()));
if (args.sorting.has_value())
- get_arguments.append(QString("index=%1").arg(args.sorting.value()));
+ get_arguments.append(QString("index=%1").arg(args.sorting.value().name));
get_arguments.append(QString("facets=%1").arg(createFacets(args)));
return BuildConfig.MODRINTH_PROD_URL + "/search?" + get_arguments.join('&');