diff --git a/src/Kyoo.Abstractions/Models/LibraryItem.cs b/src/Kyoo.Abstractions/Models/LibraryItem.cs index 7dfbb4ea..fd9a5b85 100644 --- a/src/Kyoo.Abstractions/Models/LibraryItem.cs +++ b/src/Kyoo.Abstractions/Models/LibraryItem.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq.Expressions; namespace Kyoo.Abstractions.Models @@ -33,7 +34,8 @@ namespace Kyoo.Abstractions.Models Show, /// - /// The is a Movie (a with equals to true). + /// The is a Movie (a with + /// equals to true). /// Movie, @@ -47,7 +49,7 @@ namespace Kyoo.Abstractions.Models /// A type union between and . /// This is used to list content put inside a library. /// - public class LibraryItem : IResource, IThumbnails + public class LibraryItem : CustomTypeDescriptor, IResource, IThumbnails { /// public int ID { get; set; } @@ -160,5 +162,11 @@ namespace Kyoo.Abstractions.Models Images = x.Images, Type = ItemType.Collection }; + + /// + public override string GetClassName() + { + return Type.ToString(); + } } } diff --git a/src/Kyoo.Core/Tasks/MetadataProviderLoader.cs b/src/Kyoo.Core/Tasks/MetadataProviderLoader.cs index 7c004268..c9160fda 100644 --- a/src/Kyoo.Core/Tasks/MetadataProviderLoader.cs +++ b/src/Kyoo.Core/Tasks/MetadataProviderLoader.cs @@ -72,7 +72,7 @@ namespace Kyoo.Core.Tasks /// public TaskParameters GetParameters() { - return new(); + return new TaskParameters(); } /// diff --git a/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs b/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs index c272e942..0372b568 100644 --- a/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs +++ b/src/Kyoo.Core/Views/Helper/Serializers/JsonOptions.cs @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; @@ -33,21 +34,30 @@ namespace Kyoo.Core.Api /// private readonly IHttpContextAccessor _httpContextAccessor; + /// + /// The options containing the public URL of kyoo, given to . + /// + private readonly IOptions _options; + /// /// Create a new . /// /// /// The http context accessor given to the . /// - public JsonOptions(IHttpContextAccessor httpContextAccessor) + /// + /// The options containing the public URL of kyoo, given to . + /// + public JsonOptions(IHttpContextAccessor httpContextAccessor, IOptions options) { _httpContextAccessor = httpContextAccessor; + _options = options; } /// public void Configure(MvcNewtonsoftJsonOptions options) { - options.SerializerSettings.ContractResolver = new JsonSerializerContract(_httpContextAccessor); + options.SerializerSettings.ContractResolver = new JsonSerializerContract(_httpContextAccessor, _options); options.SerializerSettings.Converters.Add(new PeopleRoleConverter()); } } diff --git a/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs b/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs index 0fb6ee72..5e90ffdf 100644 --- a/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs +++ b/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs @@ -18,10 +18,13 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Reflection; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -40,13 +43,20 @@ namespace Kyoo.Core.Api /// private readonly IHttpContextAccessor _httpContextAccessor; + /// + /// The options containing the public URL of kyoo. + /// + private readonly IOptions _options; + /// /// Create a new . /// /// The http context accessor to use. - public JsonSerializerContract(IHttpContextAccessor httpContextAccessor) + /// The options containing the public URL of kyoo. + public JsonSerializerContract(IHttpContextAccessor httpContextAccessor, IOptions options) { _httpContextAccessor = httpContextAccessor; + _options = options; } /// @@ -97,7 +107,7 @@ namespace Kyoo.Core.Api IThumbnails thumb = (IThumbnails)x; return thumb.Images?.ContainsKey(id) == true; }, - ValueProvider = new ThumbnailProvider(id) + ValueProvider = new ThumbnailProvider(_options.Value.PublicUrl, id) }); } @@ -110,6 +120,11 @@ namespace Kyoo.Core.Api /// private class ThumbnailProvider : IValueProvider { + /// + /// The public address of kyoo. + /// + private readonly Uri _host; + /// /// The index/ID of the image to retrieve/set. /// @@ -118,9 +133,11 @@ namespace Kyoo.Core.Api /// /// Create a new . /// + /// The public address of kyoo. /// The index/ID of the image to retrieve/set. - public ThumbnailProvider(int imageIndex) + public ThumbnailProvider(Uri host, int imageIndex) { + _host = host; _imageIndex = imageIndex; } @@ -135,9 +152,14 @@ namespace Kyoo.Core.Api /// public object GetValue(object target) { - if (target is IThumbnails thumb) - return thumb.Images?.GetValueOrDefault(_imageIndex); - return null; + if (target is not (IThumbnails thumb and IResource res) + || 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()) + .ToString(); } } }