Skip to content

Commit

Permalink
fix: expose width/height for IImageMetadata impl.
Browse files Browse the repository at this point in the history
- Allow manually setting the width/height for the `IImageMetadata` implementation to-be exposed in the API.
  • Loading branch information
revam committed Oct 13, 2024
1 parent 7ca0b07 commit b7d3a4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Shoko.Server/API/v3/Models/Common/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Models/Image_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private async Task<bool> CheckIsRemoteAvailableAsync()
public double AspectRatio
=> Width / Height;

private int? _width = null;
internal int? _width = null;

/// <inheritdoc/>
public virtual int Width
Expand All @@ -195,7 +195,7 @@ public virtual int Width
set { }
}

private int? _height = null;
internal int? _height = null;

/// <inheritdoc/>
public virtual int Height
Expand Down
2 changes: 2 additions & 0 deletions Shoko.Server/Models/TMDB/TMDB_Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public IImageMetadata GetImageMetadata(bool preferred = false)
{
IsEnabled = IsEnabled,
IsPreferred = preferred,
_width = Width,
_height = Height,
};

#endregion
Expand Down

0 comments on commit b7d3a4e

Please sign in to comment.