#pragma once #include #include #include using namespace geode::prelude; namespace server { struct ServerDateTime final { using Clock = std::chrono::system_clock; using Value = std::chrono::time_point; Value value; std::string toAgoString() const; static Result parse(std::string const& str); }; struct ServerDeveloper final { std::string username; std::string displayName; }; struct ServerModVersion final { ModMetadata metadata; std::string downloadURL; std::string hash; size_t downloadCount; bool operator==(ServerModVersion const&) const = default; static Result parse(matjson::Value const& json); }; struct ServerModUpdate final { std::string id; VersionInfo version; static Result parse(matjson::Value const& json); static Result> parseList(matjson::Value const& json); bool hasUpdateForInstalledMod() const; }; struct ServerModMetadata final { std::string id; bool featured; size_t downloadCount; std::vector developers; std::vector versions; std::unordered_set tags; std::optional about; std::optional changelog; std::optional repository; std::optional createdAt; std::optional updatedAt; static Result parse(matjson::Value const& json); ModMetadata latestVersion() const; bool hasUpdateForInstalledMod() const; }; struct ServerModsList final { std::vector mods; size_t totalModCount = 0; static Result parse(matjson::Value const& json); }; enum class ModsSort { Downloads, RecentlyUpdated, RecentlyPublished, }; static const char* sortToString(ModsSort sorting); struct ModsQuery final { std::optional query; std::unordered_set platforms = { GEODE_PLATFORM_TARGET }; std::unordered_set tags; std::optional featured; ModsSort sorting = ModsSort::Downloads; std::optional developer; size_t page = 0; size_t pageSize = 10; bool operator==(ModsQuery const& other) const = default; }; struct ServerError final { int code; std::string details; ServerError() = default; template ServerError( int code, fmt::string_view format, Args&&... args ) : code(code), details(fmt::vformat(format, fmt::make_format_args(args...))) {} }; struct ServerProgress { std::string message; std::optional percentage; ServerProgress() = default; ServerProgress(std::string const& msg) : message(msg) {} ServerProgress(auto msg, uint8_t percentage) : message(msg), percentage(percentage) {} }; template using ServerRequest = Task, ServerProgress>; 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; std::string getServerAPIBaseURL(); std::string getServerUserAgent(); ServerRequest getMods(ModsQuery const& query, bool useCache = true); ServerRequest getMod(std::string const& id, bool useCache = true); ServerRequest getModVersion(std::string const& id, ModVersion const& version = ModVersionLatest(), bool useCache = true); ServerRequest getModLogo(std::string const& id, bool useCache = true); ServerRequest> getTags(bool useCache = true); ServerRequest> checkUpdates(Mod* mod); ServerRequest> checkAllUpdates(bool useCache = true); void clearServerCaches(bool clearGlobalCaches = false); }