Skip to content

Commit

Permalink
Fix client supported image formats (jellyfin#9071)
Browse files Browse the repository at this point in the history
  • Loading branch information
teobaranga authored Jan 14, 2023
1 parent 663854b commit 56ef45e
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions Jellyfin.Api/Controllers/ImageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;

namespace Jellyfin.Api.Controllers
Expand Down Expand Up @@ -2038,13 +2037,8 @@ private ImageFormat[] GetClientSupportedFormats()
}

var acceptParam = Request.Query[HeaderNames.Accept];
if (StringValues.IsNullOrEmpty(acceptParam))
{
return Array.Empty<ImageFormat>();
}

// Can't be null, checked above
var supportsWebP = SupportsFormat(supportedFormats, acceptParam!, ImageFormat.Webp, false);
var supportsWebP = SupportsFormat(supportedFormats, acceptParam, ImageFormat.Webp, false);

if (!supportsWebP)
{
Expand All @@ -2066,16 +2060,15 @@ private ImageFormat[] GetClientSupportedFormats()
formats.Add(ImageFormat.Jpg);
formats.Add(ImageFormat.Png);

// Can't be null, checked above
if (SupportsFormat(supportedFormats, acceptParam!, ImageFormat.Gif, true))
if (SupportsFormat(supportedFormats, acceptParam, ImageFormat.Gif, true))
{
formats.Add(ImageFormat.Gif);
}

return formats.ToArray();
}

private bool SupportsFormat(IReadOnlyCollection<string> requestAcceptTypes, string acceptParam, ImageFormat format, bool acceptAll)
private bool SupportsFormat(IReadOnlyCollection<string> requestAcceptTypes, string? acceptParam, ImageFormat format, bool acceptAll)
{
if (requestAcceptTypes.Contains(format.GetMimeType()))
{
Expand Down

0 comments on commit 56ef45e

Please sign in to comment.