2024-02-26 15:14:53 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Geode/DefaultInclude.hpp>
|
|
|
|
#include <Geode/utils/web2.hpp>
|
2024-03-11 05:34:04 -04:00
|
|
|
#include <Geode/loader/SettingEvent.hpp>
|
2024-02-26 15:14:53 -05:00
|
|
|
|
|
|
|
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-03-26 16:18:34 -04:00
|
|
|
struct ServerDeveloper final {
|
2024-02-26 15:14:53 -05:00
|
|
|
std::string username;
|
|
|
|
std::string displayName;
|
|
|
|
};
|
|
|
|
|
2024-03-26 16:18:34 -04:00
|
|
|
struct ServerModVersion final {
|
2024-02-26 15:14:53 -05:00
|
|
|
ModMetadata metadata;
|
|
|
|
std::string downloadURL;
|
|
|
|
std::string hash;
|
|
|
|
size_t downloadCount;
|
|
|
|
|
2024-04-23 15:24:08 -04:00
|
|
|
bool operator==(ServerModVersion const&) const = default;
|
|
|
|
|
2024-02-26 15:14:53 -05:00
|
|
|
static Result<ServerModVersion> parse(matjson::Value const& json);
|
|
|
|
};
|
|
|
|
|
2024-03-26 16:18:34 -04:00
|
|
|
struct ServerModUpdate final {
|
|
|
|
std::string id;
|
|
|
|
VersionInfo version;
|
|
|
|
|
|
|
|
static Result<ServerModUpdate> parse(matjson::Value const& json);
|
|
|
|
static Result<std::vector<ServerModUpdate>> parseList(matjson::Value const& json);
|
|
|
|
|
|
|
|
bool hasUpdateForInstalledMod() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ServerModMetadata final {
|
2024-02-26 15:14:53 -05:00
|
|
|
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-25 06:36:33 -04:00
|
|
|
std::optional<std::string> repository;
|
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);
|
2024-03-05 11:25:35 -05:00
|
|
|
|
|
|
|
ModMetadata latestVersion() const;
|
|
|
|
bool hasUpdateForInstalledMod() const;
|
2024-02-26 15:14:53 -05:00
|
|
|
};
|
|
|
|
|
2024-03-26 16:18:34 -04:00
|
|
|
struct ServerModsList final {
|
2024-02-26 15:14:53 -05:00
|
|
|
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);
|
|
|
|
|
2024-03-26 16:18:34 -04:00
|
|
|
struct ModsQuery final {
|
2024-02-26 15:14:53 -05:00
|
|
|
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;
|
2024-03-23 12:10:54 -04:00
|
|
|
|
|
|
|
bool operator==(ModsQuery const& other) const = default;
|
2024-02-26 15:14:53 -05:00
|
|
|
};
|
|
|
|
|
2024-03-26 16:18:34 -04:00
|
|
|
struct ServerError final {
|
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
|
|
|
};
|
2024-04-22 06:35:12 -04:00
|
|
|
struct ServerProgress {
|
|
|
|
std::string message;
|
|
|
|
std::optional<uint8_t> percentage;
|
|
|
|
|
|
|
|
ServerProgress() = default;
|
|
|
|
ServerProgress(std::string const& msg) : message(msg) {}
|
|
|
|
ServerProgress(auto msg, uint8_t percentage) : message(msg), percentage(percentage) {}
|
|
|
|
};
|
2024-02-26 15:14:53 -05:00
|
|
|
|
2024-04-21 17:08:10 -04:00
|
|
|
template <class T>
|
|
|
|
using ServerRequest = Task<Result<T, ServerError>, ServerProgress>;
|
|
|
|
|
2024-04-26 06:52:15 -04:00
|
|
|
struct ModVersionLatest final {
|
|
|
|
bool operator==(ModVersionLatest const&) const = default;
|
|
|
|
};
|
|
|
|
struct ModVersionMajor final {
|
|
|
|
size_t major;
|
|
|
|
bool operator==(ModVersionMajor const&) const = default;
|
|
|
|
};
|
|
|
|
using ModVersionSpecific = VersionInfo;
|
|
|
|
using ModVersion = std::variant<ModVersionLatest, ModVersionMajor, ModVersionSpecific>;
|
|
|
|
|
2024-02-26 15:14:53 -05:00
|
|
|
std::string getServerAPIBaseURL();
|
2024-02-26 20:36:38 -05:00
|
|
|
std::string getServerUserAgent();
|
2024-04-23 15:24:08 -04:00
|
|
|
|
2024-04-22 06:35:12 -04:00
|
|
|
ServerRequest<ServerModsList> getMods(ModsQuery const& query, bool useCache = true);
|
|
|
|
ServerRequest<ServerModMetadata> getMod(std::string const& id, bool useCache = true);
|
2024-04-26 06:52:15 -04:00
|
|
|
ServerRequest<ServerModVersion> getModVersion(std::string const& id, ModVersion const& version = ModVersionLatest(), bool useCache = true);
|
2024-04-22 06:35:12 -04:00
|
|
|
ServerRequest<ByteVector> getModLogo(std::string const& id, bool useCache = true);
|
|
|
|
ServerRequest<std::unordered_set<std::string>> getTags(bool useCache = true);
|
2024-04-23 15:24:08 -04:00
|
|
|
|
2024-04-22 11:41:49 -04:00
|
|
|
ServerRequest<std::optional<ServerModUpdate>> checkUpdates(Mod* mod);
|
|
|
|
ServerRequest<std::vector<ServerModUpdate>> checkAllUpdates(bool useCache = true);
|
2024-04-23 15:24:08 -04:00
|
|
|
|
2024-04-22 06:35:12 -04:00
|
|
|
void clearServerCaches(bool clearGlobalCaches = false);
|
2024-02-26 15:14:53 -05:00
|
|
|
}
|