From 66723feddcfbaab46218681acdae1f2887a841d3 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Tue, 26 Nov 2024 04:02:06 +0100 Subject: [PATCH] fix: fix setting/viewing preferred episode images --- .../API/v3/Controllers/EpisodeController.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Shoko.Server/API/v3/Controllers/EpisodeController.cs b/Shoko.Server/API/v3/Controllers/EpisodeController.cs index 8e22e1a06..462b5c6f4 100644 --- a/Shoko.Server/API/v3/Controllers/EpisodeController.cs +++ b/Shoko.Server/API/v3/Controllers/EpisodeController.cs @@ -710,13 +710,13 @@ public ActionResult GetSeriesImages([FromRoute, Range(1, int.MaxValue)] #region Default image /// - /// Get the default for the given for the . + /// Get the default for the given for the . /// - /// Series ID + /// Episode ID /// Poster, Banner, Fanart /// [HttpGet("{episodeID}/Images/{imageType}")] - public ActionResult GetSeriesDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, + public ActionResult GetEpisodeDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, [FromRoute] Image.ImageType imageType) { if (!_allowedImageTypes.Contains(imageType)) @@ -738,27 +738,28 @@ public ActionResult GetSeriesDefaultImageForType([FromRoute, Range(1, int if (preferredImage != null) return new Image(preferredImage); - var images = episode.GetImages().ToDto(); + var images = episode.GetImages().ToDto(includeThumbnails: true); return imageEntityType switch { ImageEntityType.Poster => images.Posters.FirstOrDefault(), ImageEntityType.Banner => images.Banners.FirstOrDefault(), ImageEntityType.Backdrop => images.Backdrops.FirstOrDefault(), ImageEntityType.Logo => images.Logos.FirstOrDefault(), + ImageEntityType.Thumbnail => images.Thumbnails.FirstOrDefault(), _ => null }; } /// - /// Set the default for the given for the . + /// Set the default for the given for the . /// - /// Series ID + /// Episode ID /// Poster, Banner, Fanart /// The body containing the source and id used to set. /// [HttpPut("{episodeID}/Images/{imageType}")] - public ActionResult SetSeriesDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, + public ActionResult SetEpisodeDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, [FromRoute] Image.ImageType imageType, [FromBody] Image.Input.DefaultImageBody body) { if (!_allowedImageTypes.Contains(imageType)) @@ -768,11 +769,11 @@ public ActionResult SetSeriesDefaultImageForType([FromRoute, Range(1, int if (episode == null) return NotFound(EpisodeNotFoundWithEpisodeID); - var series = episode.AnimeSeries; - if (series is null) + var anime = episode.AnimeSeries?.AniDB_Anime; + if (anime is null) return InternalError(EpisodeNoSeriesForEpisodeID); - if (!User.AllowedSeries(series)) + if (!User.AllowedAnime(anime)) return Forbid(EpisodeForbiddenForUser); // Check if the id is valid for the given type and source. @@ -786,7 +787,7 @@ public ActionResult SetSeriesDefaultImageForType([FromRoute, Range(1, int // Create or update the entry. var defaultImage = RepoFactory.AniDB_Episode_PreferredImage.GetByAnidbEpisodeIDAndType(episode.AniDB_EpisodeID, imageEntityType) ?? - new() { AnidbAnimeID = episode.AniDB_EpisodeID, ImageType = imageEntityType }; + new(anime.AnimeID, episode.AniDB_EpisodeID, imageEntityType); defaultImage.ImageID = body.ID; defaultImage.ImageSource = dataSource; RepoFactory.AniDB_Episode_PreferredImage.Save(defaultImage); @@ -795,13 +796,13 @@ public ActionResult SetSeriesDefaultImageForType([FromRoute, Range(1, int } /// - /// Unset the default for the given for the . + /// Unset the default for the given for the . /// - /// + /// Episode ID /// Poster, Banner, Fanart /// [HttpDelete("{episodeID}/Images/{imageType}")] - public ActionResult DeleteSeriesDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, [FromRoute] Image.ImageType imageType) + public ActionResult DeleteEpisodeDefaultImageForType([FromRoute, Range(1, int.MaxValue)] int episodeID, [FromRoute] Image.ImageType imageType) { if (!_allowedImageTypes.Contains(imageType)) return NotFound();