Skip to content

Commit

Permalink
fix: order APIv3 Images DTO before sending
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Sep 29, 2024
1 parent 1ea4c41 commit a2c0340
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Shoko.Server/API/v3/Helpers/APIv3_Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public static Images ToDto(this IEnumerable<IImageMetadata> imageList, IReadOnly
if (includeThumbnails)
SetPreferredOrDefaultImage(images.Thumbnails!, randomizeImages);
}
else
{
images.Posters = OrderImages(images.Posters);
images.Backdrops = OrderImages(images.Backdrops);
images.Banners = OrderImages(images.Banners);
images.Logos = OrderImages(images.Logos);
if (includeThumbnails)
images.Thumbnails = OrderImages(images.Thumbnails!);
}

return images;
}
Expand All @@ -97,6 +106,13 @@ private static void SetPreferredOrDefaultImage(List<Image> images, bool randomiz
images.Add(poster);
}

private static List<Image> OrderImages(List<Image> images)
=> images
.OrderByDescending(image => image.Preferred)
.ThenBy(image => string.IsNullOrEmpty(image.LanguageCode))
.ThenBy(image => (image.LanguageCode, image.Source, image.ID))
.ToList();

public static IReadOnlyList<Title> ToDto(this IEnumerable<TMDB_Title> titles, string? mainTitle = null, TMDB_Title? preferredTitle = null, IReadOnlySet<TitleLanguage>? language = null)
{
if (language != null && language.Count > 0)
Expand Down

0 comments on commit a2c0340

Please sign in to comment.