From 89204b46d5a242a73f651f654afe175669a29a3b Mon Sep 17 00:00:00 2001 From: Zechiax <106590288+Zechiax@users.noreply.github.com> Date: Tue, 14 Apr 2026 20:43:06 +0200 Subject: [PATCH] Change gallery image ordering property type from int to long --- .../Endpoints/Project/IProjectEndpoint.cs | 4 +- .../Endpoints/Project/ProjectEndpoint.cs | 4 +- src/Modrinth.Net/Models/Gallery.cs | 2 +- test/Modrinth.Net.Test/RequesterTests.cs | 49 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/Modrinth.Net/Endpoints/Project/IProjectEndpoint.cs b/src/Modrinth.Net/Endpoints/Project/IProjectEndpoint.cs index 12835e8..345010f 100644 --- a/src/Modrinth.Net/Endpoints/Project/IProjectEndpoint.cs +++ b/src/Modrinth.Net/Endpoints/Project/IProjectEndpoint.cs @@ -132,7 +132,7 @@ Task SearchAsync( /// /// Thrown when the API returns an error or the request fails Task AddGalleryImageAsync(string slugOrId, string imagePath, bool featured, string? title = null, - string? description = null, int? ordering = null, CancellationToken cancellationToken = default); + string? description = null, long? ordering = null, CancellationToken cancellationToken = default); /// /// Modifies an existing gallery image @@ -147,7 +147,7 @@ Task AddGalleryImageAsync(string slugOrId, string imagePath, bool featured, stri /// /// Thrown when the API returns an error or the request fails Task ModifyGalleryImageAsync(string slugOrId, string url, bool? featured = null, string? title = null, - string? description = null, int? ordering = null, CancellationToken cancellationToken = default); + string? description = null, long? ordering = null, CancellationToken cancellationToken = default); /// /// Deletes an existing gallery image diff --git a/src/Modrinth.Net/Endpoints/Project/ProjectEndpoint.cs b/src/Modrinth.Net/Endpoints/Project/ProjectEndpoint.cs index dcc2c9b..a039489 100644 --- a/src/Modrinth.Net/Endpoints/Project/ProjectEndpoint.cs +++ b/src/Modrinth.Net/Endpoints/Project/ProjectEndpoint.cs @@ -158,7 +158,7 @@ public async Task ChangeIconAsync(string slugOrId, string iconPath, Cancellation /// public async Task AddGalleryImageAsync(string slugOrId, string imagePath, bool featured, string? title = null, - string? description = null, int? ordering = null, CancellationToken cancellationToken = default) + string? description = null, long? ordering = null, CancellationToken cancellationToken = default) { if (!File.Exists(imagePath)) throw new FileNotFoundException("Image not found", imagePath); @@ -193,7 +193,7 @@ public async Task AddGalleryImageAsync(string slugOrId, string imagePath, bool f /// public async Task ModifyGalleryImageAsync(string slugOrId, string url, bool? featured = null, string? title = null, - string? description = null, int? ordering = null, CancellationToken cancellationToken = default) + string? description = null, long? ordering = null, CancellationToken cancellationToken = default) { if (ordering < 0) throw new ArgumentOutOfRangeException(nameof(ordering), "Ordering must be greater than or equal to 0"); diff --git a/src/Modrinth.Net/Models/Gallery.cs b/src/Modrinth.Net/Models/Gallery.cs index c2e534c..beea22b 100644 --- a/src/Modrinth.Net/Models/Gallery.cs +++ b/src/Modrinth.Net/Models/Gallery.cs @@ -34,5 +34,5 @@ public class Gallery /// /// The order of the gallery image. Gallery images are sorted by this field and then alphabetically by title. /// - public int Ordering { get; set; } + public long Ordering { get; set; } } \ No newline at end of file diff --git a/test/Modrinth.Net.Test/RequesterTests.cs b/test/Modrinth.Net.Test/RequesterTests.cs index de3ceaa..f52ff63 100644 --- a/test/Modrinth.Net.Test/RequesterTests.cs +++ b/test/Modrinth.Net.Test/RequesterTests.cs @@ -2,6 +2,7 @@ using System.Text; using Modrinth.Exceptions; using Modrinth.Http; +using Modrinth.Models; namespace Modrinth.Net.Test; @@ -166,4 +167,52 @@ public async Task SendAsync_ReleasesSemaphoreAfterFailureOrCancellation() Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(handler.Calls, Is.EqualTo(2)); } + + [Test] + public async Task GetJsonAsync_GalleryOrderingAboveInt32Max_DeserializesSuccessfully() + { + const long expectedOrdering = 6844313514; + var json = + "[{\"url\":\"https://example.com/image.png\",\"featured\":false,\"title\":\"t\",\"description\":\"d\",\"created\":\"2026-01-01T00:00:00Z\",\"ordering\":" + + expectedOrdering + "}]"; + + var handler = new DelegateMessageHandler((_, _) => + Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(json, Encoding.UTF8, "application/json") + })); + + using var requester = CreateRequester(handler); + var request = new HttpRequestMessage(HttpMethod.Get, "http://test.com"); + + var galleries = await requester.GetJsonAsync(request); + + using (Assert.EnterMultipleScope()) + { + Assert.That(galleries, Has.Length.EqualTo(1)); + Assert.That(galleries[0].Ordering, Is.EqualTo(expectedOrdering)); + } + } + + [Test] + public async Task GetJsonAsync_GalleryOrderingHugeInt64_DeserializesSuccessfully() + { + const long expectedOrdering = 68541332132131350; + var json = + "[{\"url\":\"https://example.com/image.png\",\"featured\":true,\"title\":\"t\",\"description\":\"d\",\"created\":\"2026-01-01T00:00:00Z\",\"ordering\":" + + expectedOrdering + "}]"; + + var handler = new DelegateMessageHandler((_, _) => + Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(json, Encoding.UTF8, "application/json") + })); + + using var requester = CreateRequester(handler); + var request = new HttpRequestMessage(HttpMethod.Get, "http://test.com"); + + var galleries = await requester.GetJsonAsync(request); + + Assert.That(galleries[0].Ordering, Is.EqualTo(expectedOrdering)); + } } \ No newline at end of file