diff --git a/back/src/Kyoo.Abstractions/Controllers/IThumbnailsManager.cs b/back/src/Kyoo.Abstractions/Controllers/IThumbnailsManager.cs index 715fbedc..f6da3f3b 100644 --- a/back/src/Kyoo.Abstractions/Controllers/IThumbnailsManager.cs +++ b/back/src/Kyoo.Abstractions/Controllers/IThumbnailsManager.cs @@ -23,56 +23,17 @@ using Kyoo.Abstractions.Models; namespace Kyoo.Abstractions.Controllers; -/// -/// Download images and retrieve the path of those images for a resource. -/// public interface IThumbnailsManager { - /// - /// Download images of a specified item. - /// If no images is available to download, do nothing and silently return. - /// - /// - /// The item to cache images. - /// - /// The type of the item - /// A representing the asynchronous operation. Task DownloadImages(T item) where T : IThumbnails; - /// - /// Retrieve the local path of an image of the given item. - /// - /// The item to retrieve the poster from. - /// The ID of the image. - /// The quality of the image - /// The type of the item - /// The path of the image for the given resource or null if it does not exists. - string GetImagePath(T item, string image, ImageQuality quality) - where T : IThumbnails; + string GetImagePath(Guid imageId, ImageQuality quality); - /// - /// Delete images associated with the item. - /// - /// - /// The item with cached images. - /// - /// The type of the item - /// A representing the asynchronous operation. Task DeleteImages(T item) where T : IThumbnails; - /// - /// Set the user's profile picture - /// - /// The id of the user. - /// The byte stream of the image. Null if no image exist. Task GetUserImage(Guid userId); - /// - /// Set the user's profile picture - /// - /// The id of the user. - /// The byte stream of the image. Null to delete the image. Task SetUserImage(Guid userId, Stream? image); } diff --git a/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs index 4a3ee1f3..9a7682ef 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs @@ -20,7 +20,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Utils; using Kyoo.Postgresql; diff --git a/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs b/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs index c9ba209a..0ec1d154 100644 --- a/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs +++ b/back/src/Kyoo.Core/Controllers/ThumbnailsManager.cs @@ -42,8 +42,6 @@ public class ThumbnailsManager( Lazy> users ) : IThumbnailsManager { - private static readonly Dictionary> _downloading = []; - private static async Task _WriteTo(SKBitmap bitmap, string path, int quality) { SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, quality); @@ -52,12 +50,16 @@ public class ThumbnailsManager( await reader.CopyToAsync(file); } - private async Task _DownloadImage(Image? image, string localPath, string what) + private async Task _DownloadImage(Image? image, string what) { if (image == null) return; try { + if (image.Id == Guid.Empty) + image.Id = new Guid(); + string localPath = $"/metadata/{image.Id}"; + logger.LogInformation("Downloading image {What}", what); HttpClient client = clientFactory.CreateClient(); @@ -119,86 +121,24 @@ public class ThumbnailsManager( { string name = item is IResource res ? res.Slug : "???"; - string posterPath = - $"{_GetBaseImagePath(item, "poster")}.{ImageQuality.High.ToString().ToLowerInvariant()}.webp"; - bool duplicated = false; - TaskCompletionSource? sync = null; - try - { - lock (_downloading) - { - if (_downloading.ContainsKey(posterPath)) - { - duplicated = true; - sync = _downloading.GetValueOrDefault(posterPath); - } - else - { - sync = new(); - _downloading.Add(posterPath, sync); - } - } - if (duplicated) - { - object? dup = sync != null ? await sync.Task : null; - if (dup != null) - throw new DuplicatedItemException(dup); - } - - await _DownloadImage( - item.Poster, - _GetBaseImagePath(item, "poster"), - $"The poster of {name}" - ); - await _DownloadImage( - item.Thumbnail, - _GetBaseImagePath(item, "thumbnail"), - $"The poster of {name}" - ); - await _DownloadImage( - item.Logo, - _GetBaseImagePath(item, "logo"), - $"The poster of {name}" - ); - } - finally - { - if (!duplicated) - { - lock (_downloading) - { - _downloading.Remove(posterPath); - sync!.SetResult(item); - } - } - } - } - - private static string _GetBaseImagePath(T item, string image) - { - string directory = item switch - { - IResource res - => Path.Combine("/metadata", item.GetType().Name.ToLowerInvariant(), res.Slug), - _ => Path.Combine("/metadata", typeof(T).Name.ToLowerInvariant()) - }; - Directory.CreateDirectory(directory); - return Path.Combine(directory, image); + await _DownloadImage(item.Poster, $"The poster of {name}"); + await _DownloadImage(item.Thumbnail, $"The thumbnail of {name}"); + await _DownloadImage(item.Logo, $"The logo of {name}"); } /// - public string GetImagePath(T item, string image, ImageQuality quality) - where T : IThumbnails + public string GetImagePath(Guid imageId, ImageQuality quality) { - return $"{_GetBaseImagePath(item, image)}.{quality.ToString().ToLowerInvariant()}.webp"; + return $"/metadata/{imageId}.{quality.ToString().ToLowerInvariant()}.webp"; } /// public Task DeleteImages(T item) where T : IThumbnails { - IEnumerable images = new[] { "poster", "thumbnail", "logo" } - .SelectMany(x => _GetBaseImagePath(item, x)) + IEnumerable images = new[] {item.Poster?.Id, item.Thumbnail?.Id, item.Logo?.Id} + .Where(x => x is not null) + .SelectMany(x => $"/metadata/{x}") .SelectMany(x => new[] { diff --git a/back/src/Kyoo.Core/Views/Watch/ProxyApi.cs b/back/src/Kyoo.Core/Views/Content/ProxyApi.cs similarity index 100% rename from back/src/Kyoo.Core/Views/Watch/ProxyApi.cs rename to back/src/Kyoo.Core/Views/Content/ProxyApi.cs diff --git a/back/src/Kyoo.Core/Views/Content/ThumbnailsApi.cs b/back/src/Kyoo.Core/Views/Content/ThumbnailsApi.cs new file mode 100644 index 00000000..e10e4095 --- /dev/null +++ b/back/src/Kyoo.Core/Views/Content/ThumbnailsApi.cs @@ -0,0 +1,59 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + +using System; +using System.IO; +using Kyoo.Abstractions.Controllers; +using Kyoo.Abstractions.Models; +using Kyoo.Abstractions.Models.Permissions; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Kyoo.Core.Api; + +[ApiController] +public class ThumbnailsApi(IThumbnailsManager thumbs) : BaseApi +{ + /// + /// Get Image + /// + /// + /// Get an image from it's id. You can select a specefic quality. + /// + /// The ID of the image to retrive. + /// The quality of the image to retrieve. + /// The image asked. + /// + /// The image does not exists on kyoo. + /// + [HttpGet("{identifier:id}/poster")] + [PartialPermission(Kind.Read)] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public IActionResult GetPoster(Guid id, [FromQuery] ImageQuality? quality) + { + string path = thumbs.GetImagePath(id, quality ?? ImageQuality.High); + if (!System.IO.File.Exists(path)) + return NotFound(); + + // Allow clients to cache the image for 6 month. + Response.Headers.CacheControl = $"public, max-age={60 * 60 * 24 * 31 * 6}"; + return PhysicalFile(Path.GetFullPath(path), "image/webp", true); + } +} + diff --git a/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs b/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs index 6ec2470c..20201b5e 100644 --- a/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs +++ b/back/src/Kyoo.Core/Views/Helper/CrudThumbsApi.cs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . -using System.IO; +using System; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; @@ -28,14 +28,8 @@ using static Kyoo.Abstractions.Models.Utils.Constants; namespace Kyoo.Core.Api; -/// -/// A base class to handle CRUD operations and services thumbnails for -/// a specific resource type . -/// -/// The type of resource to make CRUD and thumbnails apis for. [ApiController] -public class CrudThumbsApi(IRepository repository, IThumbnailsManager thumbs) - : CrudApi(repository) +public class CrudThumbsApi(IRepository repository) : CrudApi(repository) where T : class, IResource, IThumbnails, IQuery { private async Task _GetImage( @@ -50,18 +44,18 @@ public class CrudThumbsApi(IRepository repository, IThumbnailsManager thum ); if (resource == null) return NotFound(); - string path = thumbs.GetImagePath(resource, image, quality ?? ImageQuality.High); - if (!System.IO.File.Exists(path)) + + Image? img = image switch + { + "poster" => resource.Poster, + "thumbnail" => resource.Thumbnail, + "logo" => resource.Logo, + _ => throw new ArgumentException(nameof(image)), + }; + if (img is null) return NotFound(); - if (!identifier.Match(id => false, slug => slug == "random")) - { - // Allow clients to cache the image for 6 month. - Response.Headers.CacheControl = $"public, max-age={60 * 60 * 24 * 31 * 6}"; - } - else - Response.Headers.CacheControl = $"public, no-store"; - return PhysicalFile(Path.GetFullPath(path), "image/webp", true); + return Redirect($"/thumbnails/{img.Id}"); } /// @@ -78,7 +72,7 @@ public class CrudThumbsApi(IRepository repository, IThumbnailsManager thum /// [HttpGet("{identifier:id}/poster")] [PartialPermission(Kind.Read)] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status302Found)] [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetPoster(Identifier identifier, [FromQuery] ImageQuality? quality) { @@ -99,7 +93,7 @@ public class CrudThumbsApi(IRepository repository, IThumbnailsManager thum /// [HttpGet("{identifier:id}/logo")] [PartialPermission(Kind.Read)] - [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status302Found)] [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetLogo(Identifier identifier, [FromQuery] ImageQuality? quality) { @@ -120,6 +114,8 @@ public class CrudThumbsApi(IRepository repository, IThumbnailsManager thum /// [HttpGet("{identifier:id}/thumbnail")] [HttpGet("{identifier:id}/backdrop", Order = AlternativeRoute)] + [ProducesResponseType(StatusCodes.Status302Found)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public Task GetBackdrop(Identifier identifier, [FromQuery] ImageQuality? quality) { return _GetImage(identifier, "thumbnail", quality); diff --git a/back/src/Kyoo.Core/Views/Helper/Transcoder.cs b/back/src/Kyoo.Core/Views/Helper/Transcoder.cs index b6220fe5..337f437b 100644 --- a/back/src/Kyoo.Core/Views/Helper/Transcoder.cs +++ b/back/src/Kyoo.Core/Views/Helper/Transcoder.cs @@ -35,8 +35,7 @@ public static class Transcoder Environment.GetEnvironmentVariable("TRANSCODER_URL") ?? "http://transcoder:7666"; } -public abstract class TranscoderApi(IRepository repository, IThumbnailsManager thumbs) - : CrudThumbsApi(repository, thumbs) +public abstract class TranscoderApi(IRepository repository) : CrudThumbsApi(repository) where T : class, IResource, IThumbnails, IQuery { private Task _Proxy(string route, (string path, string route) info) diff --git a/back/src/Kyoo.Core/Views/Resources/CollectionApi.cs b/back/src/Kyoo.Core/Views/Resources/CollectionApi.cs index c40b1bc6..24acee4a 100644 --- a/back/src/Kyoo.Core/Views/Resources/CollectionApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/CollectionApi.cs @@ -40,25 +40,13 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission(nameof(Collection))] [ApiDefinition("Collections", Group = ResourcesGroup)] -public class CollectionApi : CrudThumbsApi +public class CollectionApi( + IRepository movies, + IRepository shows, + CollectionRepository collections, + LibraryItemRepository items +) : CrudThumbsApi(collections) { - private readonly ILibraryManager _libraryManager; - private readonly CollectionRepository _collections; - private readonly LibraryItemRepository _items; - - public CollectionApi( - ILibraryManager libraryManager, - CollectionRepository collections, - LibraryItemRepository items, - IThumbnailsManager thumbs - ) - : base(libraryManager.Collections, thumbs) - { - _libraryManager = libraryManager; - _collections = collections; - _items = items; - } - /// /// Add a movie /// @@ -79,14 +67,14 @@ public class CollectionApi : CrudThumbsApi public async Task AddMovie(Identifier identifier, Identifier movie) { Guid collectionId = await identifier.Match( - async id => (await _libraryManager.Collections.Get(id)).Id, - async slug => (await _libraryManager.Collections.Get(slug)).Id + async id => (await collections.Get(id)).Id, + async slug => (await collections.Get(slug)).Id ); Guid movieId = await movie.Match( - async id => (await _libraryManager.Movies.Get(id)).Id, - async slug => (await _libraryManager.Movies.Get(slug)).Id + async id => (await movies.Get(id)).Id, + async slug => (await movies.Get(slug)).Id ); - await _collections.AddMovie(collectionId, movieId); + await collections.AddMovie(collectionId, movieId); return NoContent(); } @@ -110,14 +98,14 @@ public class CollectionApi : CrudThumbsApi public async Task AddShow(Identifier identifier, Identifier show) { Guid collectionId = await identifier.Match( - async id => (await _libraryManager.Collections.Get(id)).Id, - async slug => (await _libraryManager.Collections.Get(slug)).Id + async id => (await collections.Get(id)).Id, + async slug => (await collections.Get(slug)).Id ); Guid showId = await show.Match( - async id => (await _libraryManager.Shows.Get(id)).Id, - async slug => (await _libraryManager.Shows.Get(slug)).Id + async id => (await shows.Get(id)).Id, + async slug => (await shows.Get(slug)).Id ); - await _collections.AddShow(collectionId, showId); + await collections.AddShow(collectionId, showId); return NoContent(); } @@ -151,9 +139,9 @@ public class CollectionApi : CrudThumbsApi { Guid collectionId = await identifier.Match( id => Task.FromResult(id), - async slug => (await _libraryManager.Collections.Get(slug)).Id + async slug => (await collections.Get(slug)).Id ); - ICollection resources = await _items.GetAllOfCollection( + ICollection resources = await items.GetAllOfCollection( collectionId, filter, sortBy == new Sort.Default() @@ -165,8 +153,7 @@ public class CollectionApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Collections.GetOrDefault(identifier.IsSame()) - == null + && await collections.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -200,7 +187,7 @@ public class CollectionApi : CrudThumbsApi [FromQuery] Include? fields ) { - ICollection resources = await _libraryManager.Shows.GetAll( + ICollection resources = await shows.GetAll( Filter.And(filter, identifier.IsContainedIn(x => x.Collections)), sortBy == new Sort.Default() ? new Sort.By(x => x.AirDate) : sortBy, fields, @@ -209,8 +196,7 @@ public class CollectionApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Collections.GetOrDefault(identifier.IsSame()) - == null + && await collections.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -244,7 +230,7 @@ public class CollectionApi : CrudThumbsApi [FromQuery] Include? fields ) { - ICollection resources = await _libraryManager.Movies.GetAll( + ICollection resources = await movies.GetAll( Filter.And(filter, identifier.IsContainedIn(x => x.Collections)), sortBy == new Sort.Default() ? new Sort.By(x => x.AirDate) : sortBy, fields, @@ -253,8 +239,7 @@ public class CollectionApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Collections.GetOrDefault(identifier.IsSame()) - == null + && await collections.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); diff --git a/back/src/Kyoo.Core/Views/Resources/EpisodeApi.cs b/back/src/Kyoo.Core/Views/Resources/EpisodeApi.cs index f44cdf6e..93b3063c 100644 --- a/back/src/Kyoo.Core/Views/Resources/EpisodeApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/EpisodeApi.cs @@ -38,8 +38,8 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission(nameof(Episode))] [ApiDefinition("Episodes", Group = ResourcesGroup)] -public class EpisodeApi(ILibraryManager libraryManager, IThumbnailsManager thumbnails) - : TranscoderApi(libraryManager.Episodes, thumbnails) +public class EpisodeApi(ILibraryManager libraryManager) + : TranscoderApi(libraryManager.Episodes) { /// /// Get episode's show diff --git a/back/src/Kyoo.Core/Views/Resources/LibraryItemApi.cs b/back/src/Kyoo.Core/Views/Resources/LibraryItemApi.cs index 9e203375..37f28c26 100644 --- a/back/src/Kyoo.Core/Views/Resources/LibraryItemApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/LibraryItemApi.cs @@ -34,23 +34,5 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission("LibraryItem")] [ApiDefinition("Items", Group = ResourcesGroup)] -public class LibraryItemApi : CrudThumbsApi -{ - /// - /// The library item repository used to modify or retrieve information in the data store. - /// - private readonly IRepository _libraryItems; - - /// - /// Create a new . - /// - /// - /// The library item repository used to modify or retrieve information in the data store. - /// - /// Thumbnail manager to retrieve images. - public LibraryItemApi(IRepository libraryItems, IThumbnailsManager thumbs) - : base(libraryItems, thumbs) - { - _libraryItems = libraryItems; - } -} +public class LibraryItemApi(IRepository libraryItems) + : CrudThumbsApi(libraryItems) { } diff --git a/back/src/Kyoo.Core/Views/Resources/MovieApi.cs b/back/src/Kyoo.Core/Views/Resources/MovieApi.cs index fddc00b0..03f07822 100644 --- a/back/src/Kyoo.Core/Views/Resources/MovieApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/MovieApi.cs @@ -40,8 +40,8 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission(nameof(Show))] [ApiDefinition("Shows", Group = ResourcesGroup)] -public class MovieApi(ILibraryManager libraryManager, IThumbnailsManager thumbs) - : TranscoderApi(libraryManager.Movies, thumbs) +public class MovieApi(ILibraryManager libraryManager) + : TranscoderApi(libraryManager.Movies) { /// /// Get studio that made the show diff --git a/back/src/Kyoo.Core/Views/Resources/NewsApi.cs b/back/src/Kyoo.Core/Views/Resources/NewsApi.cs index 56153d6b..84aa8f3b 100644 --- a/back/src/Kyoo.Core/Views/Resources/NewsApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/NewsApi.cs @@ -33,8 +33,4 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission("LibraryItem")] [ApiDefinition("News", Group = ResourcesGroup)] -public class NewsApi : CrudThumbsApi -{ - public NewsApi(IRepository news, IThumbnailsManager thumbs) - : base(news, thumbs) { } -} +public class NewsApi(IRepository news) : CrudThumbsApi(news) { } diff --git a/back/src/Kyoo.Core/Views/Resources/SeasonApi.cs b/back/src/Kyoo.Core/Views/Resources/SeasonApi.cs index d12c2273..8df85291 100644 --- a/back/src/Kyoo.Core/Views/Resources/SeasonApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/SeasonApi.cs @@ -38,26 +38,9 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission(nameof(Season))] [ApiDefinition("Seasons", Group = ResourcesGroup)] -public class SeasonApi : CrudThumbsApi +public class SeasonApi(ILibraryManager libraryManager) + : CrudThumbsApi(libraryManager.Seasons) { - /// - /// The library manager used to modify or retrieve information in the data store. - /// - private readonly ILibraryManager _libraryManager; - - /// - /// Create a new . - /// - /// - /// The library manager used to modify or retrieve information in the data store. - /// - /// The thumbnail manager used to retrieve images paths. - public SeasonApi(ILibraryManager libraryManager, IThumbnailsManager thumbs) - : base(libraryManager.Seasons, thumbs) - { - _libraryManager = libraryManager; - } - /// /// Get episodes in the season /// @@ -86,7 +69,7 @@ public class SeasonApi : CrudThumbsApi [FromQuery] Include fields ) { - ICollection resources = await _libraryManager.Episodes.GetAll( + ICollection resources = await libraryManager.Episodes.GetAll( Filter.And(filter, identifier.Matcher(x => x.SeasonId, x => x.Season!.Slug)), sortBy, fields, @@ -95,7 +78,7 @@ public class SeasonApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Seasons.GetOrDefault(identifier.IsSame()) == null + && await libraryManager.Seasons.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -120,7 +103,7 @@ public class SeasonApi : CrudThumbsApi [FromQuery] Include fields ) { - Show? ret = await _libraryManager.Shows.GetOrDefault( + Show? ret = await libraryManager.Shows.GetOrDefault( identifier.IsContainedIn(x => x.Seasons!), fields ); diff --git a/back/src/Kyoo.Core/Views/Resources/ShowApi.cs b/back/src/Kyoo.Core/Views/Resources/ShowApi.cs index 0946e2c8..54138ac9 100644 --- a/back/src/Kyoo.Core/Views/Resources/ShowApi.cs +++ b/back/src/Kyoo.Core/Views/Resources/ShowApi.cs @@ -40,26 +40,8 @@ namespace Kyoo.Core.Api; [ApiController] [PartialPermission(nameof(Show))] [ApiDefinition("Shows", Group = ResourcesGroup)] -public class ShowApi : CrudThumbsApi +public class ShowApi(ILibraryManager libraryManager) : CrudThumbsApi(libraryManager.Shows) { - /// - /// The library manager used to modify or retrieve information in the data store. - /// - private readonly ILibraryManager _libraryManager; - - /// - /// Create a new . - /// - /// - /// The library manager used to modify or retrieve information about the data store. - /// - /// The thumbnail manager used to retrieve images paths. - public ShowApi(ILibraryManager libraryManager, IThumbnailsManager thumbs) - : base(libraryManager.Shows, thumbs) - { - _libraryManager = libraryManager; - } - /// /// Get seasons of this show /// @@ -88,7 +70,7 @@ public class ShowApi : CrudThumbsApi [FromQuery] Include fields ) { - ICollection resources = await _libraryManager.Seasons.GetAll( + ICollection resources = await libraryManager.Seasons.GetAll( Filter.And(filter, identifier.Matcher(x => x.ShowId, x => x.Show!.Slug)), sortBy, fields, @@ -97,7 +79,7 @@ public class ShowApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null + && await libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -131,7 +113,7 @@ public class ShowApi : CrudThumbsApi [FromQuery] Include fields ) { - ICollection resources = await _libraryManager.Episodes.GetAll( + ICollection resources = await libraryManager.Episodes.GetAll( Filter.And(filter, identifier.Matcher(x => x.ShowId, x => x.Show!.Slug)), sortBy, fields, @@ -140,7 +122,7 @@ public class ShowApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null + && await libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -165,7 +147,7 @@ public class ShowApi : CrudThumbsApi [FromQuery] Include fields ) { - return await _libraryManager.Studios.Get( + return await libraryManager.Studios.Get( identifier.IsContainedIn(x => x.Shows!), fields ); @@ -199,7 +181,7 @@ public class ShowApi : CrudThumbsApi [FromQuery] Include fields ) { - ICollection resources = await _libraryManager.Collections.GetAll( + ICollection resources = await libraryManager.Collections.GetAll( Filter.And(filter, identifier.IsContainedIn(x => x.Shows!)), sortBy, fields, @@ -208,7 +190,7 @@ public class ShowApi : CrudThumbsApi if ( !resources.Any() - && await _libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null + && await libraryManager.Shows.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); @@ -233,9 +215,9 @@ public class ShowApi : CrudThumbsApi { Guid id = await identifier.Match( id => Task.FromResult(id), - async slug => (await _libraryManager.Shows.Get(slug)).Id + async slug => (await libraryManager.Shows.Get(slug)).Id ); - return await _libraryManager.WatchStatus.GetShowStatus(id, User.GetIdOrThrow()); + return await libraryManager.WatchStatus.GetShowStatus(id, User.GetIdOrThrow()); } /// @@ -260,9 +242,9 @@ public class ShowApi : CrudThumbsApi { Guid id = await identifier.Match( id => Task.FromResult(id), - async slug => (await _libraryManager.Shows.Get(slug)).Id + async slug => (await libraryManager.Shows.Get(slug)).Id ); - return await _libraryManager.WatchStatus.SetShowStatus(id, User.GetIdOrThrow(), status); + return await libraryManager.WatchStatus.SetShowStatus(id, User.GetIdOrThrow(), status); } /// @@ -283,8 +265,8 @@ public class ShowApi : CrudThumbsApi { Guid id = await identifier.Match( id => Task.FromResult(id), - async slug => (await _libraryManager.Shows.Get(slug)).Id + async slug => (await libraryManager.Shows.Get(slug)).Id ); - await _libraryManager.WatchStatus.DeleteShowStatus(id, User.GetIdOrThrow()); + await libraryManager.WatchStatus.DeleteShowStatus(id, User.GetIdOrThrow()); } }