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 {
|
2024-03-02 17:28:06 -05:00
|
|
|
struct ServerDateTime final {
|
|
|
|
using Clock = std::chrono::system_clock;
|
|
|
|
using Value = std::chrono::time_point<Clock>;
|
|
|
|
|
|
|
|
Value value;
|
|
|
|
|
|
|
|
std::string toAgoString() const;
|
|
|
|
|
|
|
|
static Result<ServerDateTime> parse(std::string const& str);
|
|
|
|
};
|
|
|
|
|
2024-02-26 15:14:53 -05:00
|
|
|
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;
|
2024-03-02 17:28:06 -05:00
|
|
|
std::optional<ServerDateTime> createdAt;
|
|
|
|
std::optional<ServerDateTime> updatedAt;
|
2024-02-26 15:14:53 -05:00
|
|
|
|
|
|
|
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 {
|
2024-03-02 14:57:40 -05:00
|
|
|
int code;
|
2024-02-26 15:14:53 -05:00
|
|
|
std::string details;
|
|
|
|
|
|
|
|
ServerError() = default;
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
ServerError(
|
2024-03-02 14:57:40 -05:00
|
|
|
int code,
|
2024-02-26 15:14:53 -05:00
|
|
|
fmt::string_view format,
|
|
|
|
Args&&... args
|
2024-03-02 14:57:40 -05:00
|
|
|
) : code(code), details(fmt::vformat(format, fmt::make_format_args(args...))) {}
|
2024-02-26 15:14:53 -05:00
|
|
|
};
|
|
|
|
template <class T>
|
|
|
|
using ServerPromise = Promise<T, ServerError>;
|
|
|
|
|
|
|
|
std::string getServerAPIBaseURL();
|
2024-02-26 20:36:38 -05:00
|
|
|
std::string getServerUserAgent();
|
2024-02-27 18:30:39 -05:00
|
|
|
ServerPromise<ServerModsList> getMods(ModsQuery const& query);
|
2024-03-02 14:57:40 -05:00
|
|
|
ServerPromise<ServerModMetadata> getMod(std::string const& id);
|
2024-02-26 17:55:33 -05:00
|
|
|
ServerPromise<ByteVector> getModLogo(std::string const& id);
|
2024-02-26 15:14:53 -05:00
|
|
|
}
|