From bb3e912ffab3888341a10338eb3c56c142052e46 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 5 Aug 2021 22:38:21 +0200 Subject: [PATCH] Fixing episodes, people and collection images --- Kyoo.Common/Models/Resources/Episode.cs | 2 +- Kyoo/Tasks/RegisterEpisode.cs | 7 ++++ Kyoo/Views/CollectionApi.cs | 55 ++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Kyoo.Common/Models/Resources/Episode.cs b/Kyoo.Common/Models/Resources/Episode.cs index eddb86ba..dd1f62e1 100644 --- a/Kyoo.Common/Models/Resources/Episode.cs +++ b/Kyoo.Common/Models/Resources/Episode.cs @@ -111,7 +111,7 @@ namespace Kyoo.Models /// By default, the http path for the thumbnail is returned from the public API. /// This can be disabled using the internal query flag. /// - [SerializeAs("{HOST}/api/episodes/{Slug}/thumb")] + [SerializeAs("{HOST}/api/episodes/{Slug}/thumbnail")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] public string Thumb => Images?.GetValueOrDefault(Models.Images.Thumbnail); diff --git a/Kyoo/Tasks/RegisterEpisode.cs b/Kyoo/Tasks/RegisterEpisode.cs index 1876d9c5..f939b5f5 100644 --- a/Kyoo/Tasks/RegisterEpisode.cs +++ b/Kyoo/Tasks/RegisterEpisode.cs @@ -174,6 +174,13 @@ namespace Kyoo.Tasks item = await _metadataProvider.Get(item); await _thumbnailsManager.DownloadImages(item); + + if (item is Show show && show.People != null) + { + foreach (PeopleRole role in show.People) + await _thumbnailsManager.DownloadImages(role.People); + } + return await _libraryManager.CreateIfNotExists(item); } } diff --git a/Kyoo/Views/CollectionApi.cs b/Kyoo/Views/CollectionApi.cs index 783bb67b..9c26a65c 100644 --- a/Kyoo/Views/CollectionApi.cs +++ b/Kyoo/Views/CollectionApi.cs @@ -6,6 +6,7 @@ using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; using Kyoo.CommonApi; +using Kyoo.Models.Exceptions; using Kyoo.Models.Options; using Kyoo.Models.Permissions; using Microsoft.Extensions.Options; @@ -19,11 +20,18 @@ namespace Kyoo.Api public class CollectionApi : CrudApi { private readonly ILibraryManager _libraryManager; - - public CollectionApi(ILibraryManager libraryManager, IOptions options) + private readonly IFileSystem _files; + private readonly IThumbnailsManager _thumbs; + + public CollectionApi(ILibraryManager libraryManager, + IFileSystem files, + IThumbnailsManager thumbs, + IOptions options) : base(libraryManager.CollectionRepository, options.Value.PublicUrl) { _libraryManager = libraryManager; + _files = files; + _thumbs = thumbs; } [HttpGet("{id:int}/show")] @@ -129,5 +137,48 @@ namespace Kyoo.Api return BadRequest(new {Error = ex.Message}); } } + + [HttpGet("{slug}/poster")] + public async Task GetPoster(string slug) + { + try + { + Collection collection = await _libraryManager.Get(slug); + return _files.FileResult(await _thumbs.GetImagePath(collection, Images.Poster)); + } + catch (ItemNotFoundException) + { + return NotFound(); + } + } + + [HttpGet("{slug}/logo")] + public async Task GetLogo(string slug) + { + try + { + Collection collection = await _libraryManager.Get(slug); + return _files.FileResult(await _thumbs.GetImagePath(collection, Images.Logo)); + } + catch (ItemNotFoundException) + { + return NotFound(); + } + } + + [HttpGet("{slug}/backdrop")] + [HttpGet("{slug}/thumbnail")] + public async Task GetBackdrop(string slug) + { + try + { + Collection collection = await _libraryManager.Get(slug); + return _files.FileResult(await _thumbs.GetImagePath(collection, Images.Thumbnail)); + } + catch (ItemNotFoundException) + { + return NotFound(); + } + } } } \ No newline at end of file