geode/loader/src/server/Server.hpp

82 lines
2.3 KiB
C++
Raw Normal View History

2024-02-26 15:14:53 -05:00
#pragma once
#include <Geode/DefaultInclude.hpp>
#include <Geode/utils/Promise.hpp>
#include <Geode/utils/web2.hpp>
using namespace geode::prelude;
namespace server {
struct ServerDeveloper {
std::string username;
std::string displayName;
};
struct ServerModVersion {
ModMetadata metadata;
std::string downloadURL;
std::string hash;
size_t downloadCount;
static Result<ServerModVersion> parse(matjson::Value const& json);
};
struct ServerModMetadata {
std::string id;
bool featured;
size_t downloadCount;
std::vector<ServerDeveloper> developers;
std::vector<ServerModVersion> versions;
std::unordered_set<std::string> tags;
std::optional<std::string> about;
std::optional<std::string> changelog;
static Result<ServerModMetadata> parse(matjson::Value const& json);
};
struct ServerModsList {
std::vector<ServerModMetadata> mods;
size_t totalModCount = 0;
static Result<ServerModsList> parse(matjson::Value const& json);
};
enum class ModsSort {
Downloads,
RecentlyUpdated,
RecentlyPublished,
};
static const char* sortToString(ModsSort sorting);
struct ModsQuery {
std::optional<std::string> query;
std::unordered_set<PlatformID> platforms = { GEODE_PLATFORM_TARGET };
std::unordered_set<std::string> tags;
2024-02-26 17:55:33 -05:00
std::optional<bool> featured;
2024-02-26 15:14:53 -05:00
ModsSort sorting = ModsSort::Downloads;
std::optional<std::string> developer;
size_t page = 0;
size_t pageSize = 10;
};
struct ServerError {
std::string details;
ServerError() = default;
template <class... Args>
ServerError(
fmt::string_view format,
Args&&... args
) : details(fmt::vformat(format, fmt::make_format_args(args...))) {}
};
template <class T>
using ServerPromise = Promise<T, ServerError>;
std::string getServerAPIBaseURL();
2024-02-26 20:36:38 -05:00
std::string getServerUserAgent();
2024-02-26 15:14:53 -05:00
ServerPromise<ServerModsList> getMods(ModsQuery query);
2024-02-26 17:55:33 -05:00
ServerPromise<ByteVector> getModLogo(std::string const& id);
2024-02-26 15:14:53 -05:00
}