From 6a3e48a1d13da332354e64175a87b8b53c02ab91 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 10 Oct 2021 21:25:00 +0200 Subject: [PATCH] API: Fixing watch items images and previous/next handling --- src/Kyoo.Abstractions/Models/WatchItem.cs | 23 ++++++++++++++++--- .../Serializers/JsonSerializerContract.cs | 6 +++-- src/Kyoo.Core/Views/Watch/SubtitleApi.cs | 5 +++- src/Kyoo.WebApp/Front | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Kyoo.Abstractions/Models/WatchItem.cs b/src/Kyoo.Abstractions/Models/WatchItem.cs index 3af919b9..bedd5df5 100644 --- a/src/Kyoo.Abstractions/Models/WatchItem.cs +++ b/src/Kyoo.Abstractions/Models/WatchItem.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -32,7 +33,7 @@ namespace Kyoo.Abstractions.Models /// Information about tracks and display information that could be used by the player. /// This contains mostly data from an with another form. /// - public class WatchItem + public class WatchItem : CustomTypeDescriptor, IThumbnails { /// /// The ID of the episode associated with this item. @@ -101,6 +102,9 @@ namespace Kyoo.Abstractions.Models /// public bool IsMovie { get; set; } + /// + public Dictionary Images { get; set; } + /// /// The container of the video file of this episode. /// Common containers are mp4, mkv, avi and so on. @@ -147,11 +151,11 @@ namespace Kyoo.Abstractions.Models if (ep.AbsoluteNumber != null) { previous = await library.GetOrDefault( - x => x.ShowID == ep.ShowID && x.AbsoluteNumber <= ep.AbsoluteNumber, + x => x.ShowID == ep.ShowID && x.AbsoluteNumber < ep.AbsoluteNumber, new Sort(x => x.AbsoluteNumber, true) ); next = await library.GetOrDefault( - x => x.ShowID == ep.ShowID && x.AbsoluteNumber >= ep.AbsoluteNumber, + x => x.ShowID == ep.ShowID && x.AbsoluteNumber > ep.AbsoluteNumber, new Sort(x => x.AbsoluteNumber) ); } @@ -195,6 +199,7 @@ namespace Kyoo.Abstractions.Models Title = ep.Title, ReleaseDate = ep.ReleaseDate, Path = ep.Path, + Images = ep.Show.Images, Container = PathIO.GetExtension(ep.Path)![1..], Video = ep.Tracks.FirstOrDefault(x => x.Type == StreamType.Video), Audios = ep.Tracks.Where(x => x.Type == StreamType.Audio).ToArray(), @@ -232,5 +237,17 @@ namespace Kyoo.Abstractions.Models return Array.Empty(); } } + + /// + public override string GetClassName() + { + return nameof(Show); + } + + /// + public override string GetComponentName() + { + return ShowSlug; + } } } diff --git a/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs b/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs index 5e90ffdf..429c7c60 100644 --- a/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs +++ b/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs @@ -152,13 +152,15 @@ namespace Kyoo.Core.Api /// public object GetValue(object target) { - if (target is not (IThumbnails thumb and IResource res) + string slug = (target as IResource)?.Slug ?? (target as ICustomTypeDescriptor)?.GetComponentName(); + if (target is not IThumbnails thumb + || slug == null || string.IsNullOrEmpty(thumb.Images?.GetValueOrDefault(_imageIndex))) return null; string type = target is ICustomTypeDescriptor descriptor ? descriptor.GetClassName() : target.GetType().Name; - return new Uri(_host, $"/api/{type}/{res.Slug}/{Images.ImageName[_imageIndex]}".ToLower()) + return new Uri(_host, $"/api/{type}/{slug}/{Images.ImageName[_imageIndex]}".ToLower()) .ToString(); } } diff --git a/src/Kyoo.Core/Views/Watch/SubtitleApi.cs b/src/Kyoo.Core/Views/Watch/SubtitleApi.cs index 41b25063..3266af8d 100644 --- a/src/Kyoo.Core/Views/Watch/SubtitleApi.cs +++ b/src/Kyoo.Core/Views/Watch/SubtitleApi.cs @@ -17,6 +17,7 @@ // along with Kyoo. If not, see . using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -75,11 +76,13 @@ namespace Kyoo.Core.Api /// An optional extension for the subtitle file. /// The subtitle file /// No subtitle exist with the given ID or slug. - [HttpGet("{identifier:id}", Order = AlternativeRoute)] + [HttpGet("{identifier:int}", Order = AlternativeRoute)] [HttpGet("{identifier:id}.{extension}")] [PartialPermission(Kind.Read)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [SuppressMessage("ReSharper", "RouteTemplates.ParameterTypeAndConstraintsMismatch", + Justification = "An indentifier can be constructed with an int.")] public async Task GetSubtitle(Identifier identifier, string extension) { Track subtitle = await identifier.Match( diff --git a/src/Kyoo.WebApp/Front b/src/Kyoo.WebApp/Front index 7bf53b40..846dbcb2 160000 --- a/src/Kyoo.WebApp/Front +++ b/src/Kyoo.WebApp/Front @@ -1 +1 @@ -Subproject commit 7bf53b40080d1d43228f1cdcad510b302ead99ff +Subproject commit 846dbcb22ed29244a2384d240180c821ec18df2b