2023-01-23 19:33:55 +05:30
|
|
|
// SPDX-FileCopyrightText: 2023 flowln <flowlnlnln@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
2022-03-03 07:31:23 +05:30
|
|
|
#pragma once
|
|
|
|
|
2022-04-20 05:40:12 +05:30
|
|
|
#include "modplatform/ModIndex.h"
|
2022-11-25 17:53:46 +05:30
|
|
|
#include "modplatform/helpers/NetworkResourceAPI.h"
|
2022-03-08 00:52:57 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
class FlameAPI : public NetworkResourceAPI {
|
2022-06-04 03:36:51 +05:30
|
|
|
public:
|
|
|
|
auto getModFileChangelog(int modId, int fileId) -> QString;
|
2022-07-19 20:20:38 +05:30
|
|
|
auto getModDescription(int modId) -> QString;
|
2022-06-04 03:36:51 +05:30
|
|
|
|
|
|
|
auto getLatestVersion(VersionSearchArgs&& args) -> ModPlatform::IndexedVersion;
|
|
|
|
|
2023-01-03 22:28:27 +05:30
|
|
|
Task::Ptr getProjects(QStringList addonIds, QByteArray* response) const override;
|
|
|
|
Task::Ptr matchFingerprints(const QList<uint>& fingerprints, QByteArray* response);
|
|
|
|
Task::Ptr getFiles(const QStringList& fileIds, QByteArray* response) const;
|
2022-06-19 22:59:21 +05:30
|
|
|
|
2022-12-20 20:45:17 +05:30
|
|
|
[[nodiscard]] auto getSortingMethods() const -> QList<ResourceAPI::SortingMethod> override;
|
2022-05-08 12:52:50 +05:30
|
|
|
|
2022-12-20 20:45:17 +05:30
|
|
|
private:
|
2022-11-25 17:53:46 +05:30
|
|
|
static int getClassId(ModPlatform::ResourceType type)
|
2022-05-24 20:44:08 +05:30
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
case ModPlatform::ResourceType::MOD:
|
|
|
|
return 6;
|
2022-12-17 04:56:10 +05:30
|
|
|
case ModPlatform::ResourceType::RESOURCE_PACK:
|
|
|
|
return 12;
|
2022-11-25 17:53:46 +05:30
|
|
|
}
|
|
|
|
}
|
2022-04-15 16:08:27 +05:30
|
|
|
|
2022-11-25 17:53:46 +05:30
|
|
|
static int getMappedModLoader(ModLoaderTypes loaders)
|
2022-04-15 16:08:27 +05:30
|
|
|
{
|
2022-05-19 12:10:28 +05:30
|
|
|
// https://docs.curseforge.com/?http#tocS_ModLoaderType
|
|
|
|
if (loaders & Forge)
|
|
|
|
return 1;
|
|
|
|
if (loaders & Fabric)
|
|
|
|
return 4;
|
2022-04-15 16:08:27 +05:30
|
|
|
// TODO: remove this once Quilt drops official Fabric support
|
2022-05-19 12:10:28 +05:30
|
|
|
if (loaders & Quilt) // NOTE: Most if not all Fabric mods should work *currently*
|
|
|
|
return 4; // Quilt would probably be 5
|
|
|
|
return 0;
|
2022-04-15 16:08:27 +05:30
|
|
|
}
|
2022-11-25 17:53:46 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
[[nodiscard]] std::optional<QString> getSearchURL(SearchArgs const& args) const override
|
|
|
|
{
|
|
|
|
auto gameVersionStr = args.versions.has_value() ? QString("gameVersion=%1").arg(args.versions.value().front().toString()) : QString();
|
|
|
|
|
|
|
|
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 20:45:17 +05:30
|
|
|
get_arguments.append(QString("sortField=%1").arg(args.sorting.value().index));
|
2022-11-25 17:53:46 +05:30
|
|
|
get_arguments.append("sortOrder=desc");
|
|
|
|
if (args.loaders.has_value())
|
|
|
|
get_arguments.append(QString("modLoaderType=%1").arg(getMappedModLoader(args.loaders.value())));
|
|
|
|
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
|
|
|
|
{
|
2022-12-19 00:11:46 +05:30
|
|
|
QString url{QString("https://api.curseforge.com/v1/mods/%1/files?pageSize=10000&").arg(args.pack.addonId.toString())};
|
2022-11-25 17:53:46 +05:30
|
|
|
|
|
|
|
QStringList get_parameters;
|
|
|
|
if (args.mcVersions.has_value())
|
|
|
|
get_parameters.append(QString("gameVersion=%1").arg(args.mcVersions.value().front().toString()));
|
|
|
|
if (args.loaders.has_value())
|
|
|
|
get_parameters.append(QString("modLoaderType=%1").arg(getMappedModLoader(args.loaders.value())));
|
|
|
|
|
|
|
|
return url + get_parameters.join('&');
|
|
|
|
};
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|