From b7d3a4e1f6e3b395fdcba64dfe1c1a3c95add6e9 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Mon, 14 Oct 2024 00:40:49 +0200 Subject: [PATCH] fix: expose width/height for `IImageMetadata` impl. - Allow manually setting the width/height for the `IImageMetadata` implementation to-be exposed in the API. --- Shoko.Server/API/v3/Models/Common/Image.cs | 6 ++++++ Shoko.Server/Models/Image_Base.cs | 4 ++-- Shoko.Server/Models/TMDB/TMDB_Image.cs | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Shoko.Server/API/v3/Models/Common/Image.cs b/Shoko.Server/API/v3/Models/Common/Image.cs index 3d98f41a8..0386a91eb 100644 --- a/Shoko.Server/API/v3/Models/Common/Image.cs +++ b/Shoko.Server/API/v3/Models/Common/Image.cs @@ -7,6 +7,7 @@ using Shoko.Models.Enums; using Shoko.Plugin.Abstractions.DataModels; using Shoko.Plugin.Abstractions.Enums; +using Shoko.Server.Models; using Shoko.Server.Models.TMDB; using Shoko.Server.Repositories; using Shoko.Server.Utilities; @@ -97,6 +98,11 @@ public Image(IImageMetadata imageMetadata) Width = tmdbImage.Width; Height = tmdbImage.Height; } + else if (imageMetadata is Image_Base imageBase && imageBase._width.HasValue && imageBase._height.HasValue) + { + Width = imageBase._width.Value; + Height = imageBase._height.Value; + } else if (imageMetadata.IsLocalAvailable && Utils.SettingsProvider.GetSettings().LoadImageMetadata) { Width = imageMetadata.Width; diff --git a/Shoko.Server/Models/Image_Base.cs b/Shoko.Server/Models/Image_Base.cs index 59b309b8d..727599c9b 100644 --- a/Shoko.Server/Models/Image_Base.cs +++ b/Shoko.Server/Models/Image_Base.cs @@ -178,7 +178,7 @@ private async Task CheckIsRemoteAvailableAsync() public double AspectRatio => Width / Height; - private int? _width = null; + internal int? _width = null; /// public virtual int Width @@ -195,7 +195,7 @@ public virtual int Width set { } } - private int? _height = null; + internal int? _height = null; /// public virtual int Height diff --git a/Shoko.Server/Models/TMDB/TMDB_Image.cs b/Shoko.Server/Models/TMDB/TMDB_Image.cs index 76eebede1..61887de23 100644 --- a/Shoko.Server/Models/TMDB/TMDB_Image.cs +++ b/Shoko.Server/Models/TMDB/TMDB_Image.cs @@ -314,6 +314,8 @@ public IImageMetadata GetImageMetadata(bool preferred = false) { IsEnabled = IsEnabled, IsPreferred = preferred, + _width = Width, + _height = Height, }; #endregion