diff --git a/CFCoreAPI/Endpoints/Files/FilesAPI.cs b/CFCoreAPI/Endpoints/Files/FilesAPI.cs new file mode 100644 index 0000000..d5718ba --- /dev/null +++ b/CFCoreAPI/Endpoints/Files/FilesAPI.cs @@ -0,0 +1,47 @@ +using System.Text.Json; +using CFCoreAPI.Endpoints.Files.Responses; +using Microsoft.AspNetCore.WebUtilities; + +namespace CFCoreAPI.Endpoints.Files +{ + public class FilesAPI : APIBase + { + public FilesAPI(HttpClient httpClient) : base(httpClient) + { + } + + public async Task GetModFileAsync(int modId, int fileId) + { + string url = "/v1/mods/{0}/files/{1}"; + string.Format(url, modId, fileId); + HttpResponseMessage response = await httpClient.GetAsync(url); + + ModFileResponse result; + using (Stream contentStream = await response.Content.ReadAsStreamAsync()) + { + result = await JsonSerializer.DeserializeAsync(contentStream); + } + return result; + } + + public async Task GetModFilesAsync(int modId, string? gameVersion = null, ModLoaderType? modLoaderType = null, int? gameVersionTypeId = null, int? index = null, int? pageSize = null) + { + string url = "/v1/mods/{0}/files"; + string.Format(url, modId); + if (gameVersion != null) QueryHelpers.AddQueryString(url, "gameVersion", gameVersion); + if (modLoaderType != null) QueryHelpers.AddQueryString(url, "modLoaderType", ((int)modLoaderType.Value).ToString()); + if (gameVersionTypeId != null) QueryHelpers.AddQueryString(url, "gameVersionTypeId", gameVersionTypeId.ToString()); + if (index != null) QueryHelpers.AddQueryString(url, "index", index.ToString()); + if (pageSize != null) QueryHelpers.AddQueryString(url, "pageSize", pageSize.ToString()); + HttpResponseMessage response = await httpClient.GetAsync(url); + ModFilesResponse result; + + using (Stream contentStream = await response.Content.ReadAsStreamAsync()) + { + result = await JsonSerializer.DeserializeAsync(contentStream); + } + return result; + } + + } +} \ No newline at end of file diff --git a/CFCoreAPI/Endpoints/Files/Responses/ModFileResponse.cs b/CFCoreAPI/Endpoints/Files/Responses/ModFileResponse.cs new file mode 100644 index 0000000..ad41f7d --- /dev/null +++ b/CFCoreAPI/Endpoints/Files/Responses/ModFileResponse.cs @@ -0,0 +1,173 @@ +using System.Text.Json.Serialization; + +namespace CFCoreAPI.Endpoints.Files.Responses +{ + + + public struct ModFileResponse + { + [JsonConstructor] + public ModFileResponse( + DataModel data + ) + { + this.Data = data; + } + + public DataModel Data { get; } + + public struct DataModel + { + [JsonConstructor] + public DataModel( + int id, + int gameId, + int modId, + bool isAvailable, + string displayName, + string fileName, + int releaseType, + int fileStatus, + List hashes, + DateTime fileDate, + int fileLength, + int downloadCount, + string downloadUrl, + List gameVersions, + List sortableGameVersions, + List dependencies, + bool exposeAsAlternative, + int parentProjectFileId, + int alternateFileId, + bool isServerPack, + int serverPackFileId, + int fileFingerprint, + List modules + ) + { + this.Id = id; + this.GameId = gameId; + this.ModId = modId; + this.IsAvailable = isAvailable; + this.DisplayName = displayName; + this.FileName = fileName; + this.ReleaseType = releaseType; + this.FileStatus = fileStatus; + this.Hashes = hashes; + this.FileDate = fileDate; + this.FileLength = fileLength; + this.DownloadCount = downloadCount; + this.DownloadUrl = downloadUrl; + this.GameVersions = gameVersions; + this.SortableGameVersions = sortableGameVersions; + this.Dependencies = dependencies; + this.ExposeAsAlternative = exposeAsAlternative; + this.ParentProjectFileId = parentProjectFileId; + this.AlternateFileId = alternateFileId; + this.IsServerPack = isServerPack; + this.ServerPackFileId = serverPackFileId; + this.FileFingerprint = fileFingerprint; + this.Modules = modules; + } + + public int Id { get; } + public int GameId { get; } + public int ModId { get; } + public bool IsAvailable { get; } + public string DisplayName { get; } + public string FileName { get; } + public int ReleaseType { get; } + public int FileStatus { get; } + public IReadOnlyList Hashes { get; } + public DateTime FileDate { get; } + public int FileLength { get; } + public int DownloadCount { get; } + public string DownloadUrl { get; } + public IReadOnlyList GameVersions { get; } + public IReadOnlyList SortableGameVersions { get; } + public IReadOnlyList Dependencies { get; } + public bool ExposeAsAlternative { get; } + public int ParentProjectFileId { get; } + public int AlternateFileId { get; } + public bool IsServerPack { get; } + public int ServerPackFileId { get; } + public int FileFingerprint { get; } + public IReadOnlyList Modules { get; } + } + + public struct DependencyModel + { + [JsonConstructor] + public DependencyModel( + int modId, + int relationType + ) + { + this.ModId = modId; + this.RelationType = relationType; + } + + public int ModId { get; } + public int RelationType { get; } + } + + public struct HashModel + { + [JsonConstructor] + public HashModel( + string value, + int algo + ) + { + this.Value = value; + this.Algo = algo; + } + + public string Value { get; } + public int Algo { get; } + } + + public struct ModuleModel + { + [JsonConstructor] + public ModuleModel( + string name, + int fingerprint + ) + { + this.Name = name; + this.Fingerprint = fingerprint; + } + + public string Name { get; } + public int Fingerprint { get; } + } + public struct SortableGameVersionModel + { + [JsonConstructor] + public SortableGameVersionModel( + string gameVersionName, + string gameVersionPadded, + string gameVersion, + DateTime gameVersionReleaseDate, + int gameVersionTypeId + ) + { + this.GameVersionName = gameVersionName; + this.GameVersionPadded = gameVersionPadded; + this.GameVersion = gameVersion; + this.GameVersionReleaseDate = gameVersionReleaseDate; + this.GameVersionTypeId = gameVersionTypeId; + } + + public string GameVersionName { get; } + public string GameVersionPadded { get; } + public string GameVersion { get; } + public DateTime GameVersionReleaseDate { get; } + public int GameVersionTypeId { get; } + } + } + + + +} \ No newline at end of file diff --git a/CFCoreAPI/Endpoints/Files/Responses/ModFilesResponse.cs b/CFCoreAPI/Endpoints/Files/Responses/ModFilesResponse.cs new file mode 100644 index 0000000..9d2f716 --- /dev/null +++ b/CFCoreAPI/Endpoints/Files/Responses/ModFilesResponse.cs @@ -0,0 +1,197 @@ +using System.Text.Json.Serialization; + +namespace CFCoreAPI.Endpoints.Files.Responses +{ + + + public struct ModFilesResponse + { + [JsonConstructor] + public ModFilesResponse( + List data, + PaginationModel pagination + ) + { + this.Data = data; + this.Pagination = pagination; + } + + public IReadOnlyList Data { get; } + public PaginationModel Pagination { get; } + public struct DataModel + { + [JsonConstructor] + public DataModel( + int id, + int gameId, + int modId, + bool isAvailable, + string displayName, + string fileName, + int releaseType, + int fileStatus, + List hashes, + DateTime fileDate, + int fileLength, + int downloadCount, + string downloadUrl, + List gameVersions, + List sortableGameVersions, + List dependencies, + bool exposeAsAlternative, + int parentProjectFileId, + int alternateFileId, + bool isServerPack, + int serverPackFileId, + int fileFingerprint, + List modules + ) + { + this.Id = id; + this.GameId = gameId; + this.ModId = modId; + this.IsAvailable = isAvailable; + this.DisplayName = displayName; + this.FileName = fileName; + this.ReleaseType = releaseType; + this.FileStatus = fileStatus; + this.Hashes = hashes; + this.FileDate = fileDate; + this.FileLength = fileLength; + this.DownloadCount = downloadCount; + this.DownloadUrl = downloadUrl; + this.GameVersions = gameVersions; + this.SortableGameVersions = sortableGameVersions; + this.Dependencies = dependencies; + this.ExposeAsAlternative = exposeAsAlternative; + this.ParentProjectFileId = parentProjectFileId; + this.AlternateFileId = alternateFileId; + this.IsServerPack = isServerPack; + this.ServerPackFileId = serverPackFileId; + this.FileFingerprint = fileFingerprint; + this.Modules = modules; + } + + public int Id { get; } + public int GameId { get; } + public int ModId { get; } + public bool IsAvailable { get; } + public string DisplayName { get; } + public string FileName { get; } + public int ReleaseType { get; } + public int FileStatus { get; } + public IReadOnlyList Hashes { get; } + public DateTime FileDate { get; } + public int FileLength { get; } + public int DownloadCount { get; } + public string DownloadUrl { get; } + public IReadOnlyList GameVersions { get; } + public IReadOnlyList SortableGameVersions { get; } + public IReadOnlyList Dependencies { get; } + public bool ExposeAsAlternative { get; } + public int ParentProjectFileId { get; } + public int AlternateFileId { get; } + public bool IsServerPack { get; } + public int ServerPackFileId { get; } + public int FileFingerprint { get; } + public IReadOnlyList Modules { get; } + } + + public struct DependencyModel + { + [JsonConstructor] + public DependencyModel( + int modId, + int relationType + ) + { + this.ModId = modId; + this.RelationType = relationType; + } + + public int ModId { get; } + public int RelationType { get; } + } + + public struct HashModel + { + [JsonConstructor] + public HashModel( + string value, + int algo + ) + { + this.Value = value; + this.Algo = algo; + } + + public string Value { get; } + public int Algo { get; } + } + + public struct ModuleModel + { + [JsonConstructor] + public ModuleModel( + string name, + int fingerprint + ) + { + this.Name = name; + this.Fingerprint = fingerprint; + } + + public string Name { get; } + public int Fingerprint { get; } + } + + public struct PaginationModel + { + [JsonConstructor] + public PaginationModel( + int index, + int pageSize, + int resultCount, + int totalCount + ) + { + this.Index = index; + this.PageSize = pageSize; + this.ResultCount = resultCount; + this.TotalCount = totalCount; + } + + public int Index { get; } + public int PageSize { get; } + public int ResultCount { get; } + public int TotalCount { get; } + } + public struct SortableGameVersionModel + { + [JsonConstructor] + public SortableGameVersionModel( + string gameVersionName, + string gameVersionPadded, + string gameVersion, + DateTime gameVersionReleaseDate, + int gameVersionTypeId + ) + { + this.GameVersionName = gameVersionName; + this.GameVersionPadded = gameVersionPadded; + this.GameVersion = gameVersion; + this.GameVersionReleaseDate = gameVersionReleaseDate; + this.GameVersionTypeId = gameVersionTypeId; + } + + public string GameVersionName { get; } + public string GameVersionPadded { get; } + public string GameVersion { get; } + public DateTime GameVersionReleaseDate { get; } + public int GameVersionTypeId { get; } + } + } + + + +} \ No newline at end of file diff --git a/CFCoreAPI/Endpoints/Files/Responses/ModLoaderType.cs b/CFCoreAPI/Endpoints/Files/Responses/ModLoaderType.cs new file mode 100644 index 0000000..2b64d03 --- /dev/null +++ b/CFCoreAPI/Endpoints/Files/Responses/ModLoaderType.cs @@ -0,0 +1,11 @@ +namespace CFCoreAPI +{ + public enum ModLoaderType : int + { + Any = 0, + Forge = 1, + Cauldron = 2, + LiteLoader = 3, + Fabric = 4 + } +} \ No newline at end of file