2023-01-23 14:03:55 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-19 19:20:35 +01:00
|
|
|
#include <algorithm>
|
2023-06-15 20:59:41 +01:00
|
|
|
#include <memory>
|
2022-04-20 01:10:12 +01:00
|
|
|
#include "modplatform/ModIndex.h"
|
2023-06-19 19:20:35 +01:00
|
|
|
#include "modplatform/ResourceAPI.h"
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "modplatform/helpers/NetworkResourceAPI.h"
|
2022-03-07 19:22:57 +00:00
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
class FlameAPI : public NetworkResourceAPI {
|
2022-06-03 23:06:51 +01:00
|
|
|
public:
|
|
|
|
auto getModFileChangelog(int modId, int fileId) -> QString;
|
2022-07-19 15:50:38 +01:00
|
|
|
auto getModDescription(int modId) -> QString;
|
2022-06-03 23:06:51 +01:00
|
|
|
|
|
|
|
auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion;
|
|
|
|
|
2023-06-15 20:59:41 +01:00
|
|
|
Task::Ptr getProjects(QStringList addonIds, std::shared_ptr<QByteArray> response) const override;
|
|
|
|
Task::Ptr matchFingerprints(const QList<uint>& fingerprints, std::shared_ptr<QByteArray> response);
|
|
|
|
Task::Ptr getFiles(const QStringList& fileIds, std::shared_ptr<QByteArray> response) const;
|
2023-05-28 19:25:58 +01:00
|
|
|
Task::Ptr getFile(const QString& addonId, const QString& fileId, std::shared_ptr<QByteArray> response) const;
|
2022-06-19 18:29:21 +01:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
[[nodiscard]] auto getSortingMethods() const -> QList<ResourceAPI::SortingMethod> override;
|
2022-05-08 08:22:50 +01:00
|
|
|
|
2023-08-23 08:26:57 +01:00
|
|
|
static inline auto validateModLoaders(ModPlatform::ModLoaderTypes loaders) -> bool
|
|
|
|
{
|
|
|
|
return loaders & (ModPlatform::NeoForge | ModPlatform::Forge | ModPlatform::Fabric | ModPlatform::Quilt);
|
|
|
|
}
|
2023-07-08 22:03:47 +01:00
|
|
|
|
2022-12-20 15:15:17 +00:00
|
|
|
private:
|
2022-11-25 12:23:46 +00:00
|
|
|
static int getClassId(ModPlatform::ResourceType type)
|
2022-05-24 16:14:08 +01:00
|
|
|
{
|
2022-11-25 12:23:46 +00:00
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
case ModPlatform::ResourceType::MOD:
|
|
|
|
return 6;
|
2022-12-16 23:26:10 +00:00
|
|
|
case ModPlatform::ResourceType::RESOURCE_PACK:
|
|
|
|
return 12;
|
2022-11-25 12:23:46 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-15 11:38:27 +01:00
|
|
|
|
2023-08-23 18:16:51 +01:00
|
|
|
static int getMappedModLoader(ModPlatform::ModLoaderType loaders)
|
2022-04-15 11:38:27 +01:00
|
|
|
{
|
2022-05-19 07:40:28 +01:00
|
|
|
// https://docs.curseforge.com/?http#tocS_ModLoaderType
|
2023-08-23 18:16:51 +01:00
|
|
|
switch (loaders) {
|
|
|
|
case ModPlatform::Forge:
|
|
|
|
return 1;
|
|
|
|
case ModPlatform::Cauldron:
|
|
|
|
return 2;
|
|
|
|
case ModPlatform::LiteLoader:
|
|
|
|
return 3;
|
|
|
|
case ModPlatform::Fabric:
|
|
|
|
return 4;
|
|
|
|
case ModPlatform::Quilt:
|
|
|
|
return 5;
|
|
|
|
case ModPlatform::NeoForge:
|
|
|
|
return 6;
|
|
|
|
}
|
2023-08-23 19:09:32 +01:00
|
|
|
return 0;
|
2022-04-15 11:38:27 +01:00
|
|
|
}
|
2022-11-25 12:23:46 +00:00
|
|
|
|
2023-08-23 10:52:51 +01:00
|
|
|
static auto getModLoaderStrings(const ModPlatform::ModLoaderTypes types) -> const QStringList
|
|
|
|
{
|
|
|
|
QStringList l;
|
|
|
|
for (auto loader : { ModPlatform::NeoForge, ModPlatform::Forge, ModPlatform::Fabric, ModPlatform::Quilt }) {
|
|
|
|
if (types & loader) {
|
|
|
|
l << QString::number(getMappedModLoader(loader));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static auto getModLoaderFilters(ModPlatform::ModLoaderTypes types) -> const QString
|
|
|
|
{
|
|
|
|
return "[" + getModLoaderStrings(types).join(',') + "]";
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
private:
|
|
|
|
[[nodiscard]] std::optional<QString> getSearchURL(SearchArgs const& args) const override
|
|
|
|
{
|
2023-04-14 16:59:31 +01:00
|
|
|
auto gameVersionStr =
|
|
|
|
args.versions.has_value() ? QString("gameVersion=%1").arg(args.versions.value().front().toString()) : QString();
|
2022-11-25 12:23:46 +00:00
|
|
|
|
|
|
|
QStringList get_arguments;
|
|
|
|
get_arguments.append(QString("classId=%1").arg(getClassId(args.type)));
|
|
|
|
get_arguments.append(QString("index=%1").arg(args.offset));
|
|
|
|
get_arguments.append("pageSize=25");
|
|
|
|
if (args.search.has_value())
|
|
|
|
get_arguments.append(QString("searchFilter=%1").arg(args.search.value()));
|
|
|
|
if (args.sorting.has_value())
|
2022-12-20 15:15:17 +00:00
|
|
|
get_arguments.append(QString("sortField=%1").arg(args.sorting.value().index));
|
2022-11-25 12:23:46 +00:00
|
|
|
get_arguments.append("sortOrder=desc");
|
|
|
|
if (args.loaders.has_value())
|
2023-08-23 10:52:51 +01:00
|
|
|
get_arguments.append(QString("modLoaderTypes=%1").arg(getModLoaderFilters(args.loaders.value())));
|
2022-11-25 12:23:46 +00:00
|
|
|
get_arguments.append(gameVersionStr);
|
|
|
|
|
|
|
|
return "https://api.curseforge.com/v1/mods/search?gameId=432&" + get_arguments.join('&');
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<QString> getInfoURL(QString const& id) const override
|
|
|
|
{
|
|
|
|
return QString("https://api.curseforge.com/v1/mods/%1").arg(id);
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] std::optional<QString> getVersionsURL(VersionSearchArgs const& args) const override
|
|
|
|
{
|
2023-06-19 19:20:35 +01:00
|
|
|
auto addonId = args.pack.addonId.toString();
|
2023-08-23 11:28:23 +01:00
|
|
|
QString url = QString("https://api.curseforge.com/v1/mods/%1/files?pageSize=10000").arg(addonId);
|
2022-11-25 12:23:46 +00:00
|
|
|
|
|
|
|
if (args.mcVersions.has_value())
|
2023-08-23 11:28:23 +01:00
|
|
|
url += QString("&gameVersion=%1").arg(args.mcVersions.value().front().toString());
|
|
|
|
return url;
|
2022-11-25 12:23:46 +00:00
|
|
|
};
|
2023-04-14 16:59:31 +01:00
|
|
|
|
2023-04-21 16:41:40 +01:00
|
|
|
[[nodiscard]] std::optional<QString> getDependencyURL(DependencySearchArgs const& args) const override
|
2023-04-14 16:59:31 +01:00
|
|
|
{
|
2023-06-19 19:20:35 +01:00
|
|
|
auto addonId = args.dependency.addonId.toString();
|
2023-08-23 11:28:23 +01:00
|
|
|
return QString("https://api.curseforge.com/v1/mods/%1/files?pageSize=10000&gameVersion=%2").arg(addonId, args.mcVersion.toString());
|
2023-04-14 16:59:31 +01:00
|
|
|
};
|
2022-03-03 02:01:23 +00:00
|
|
|
};
|