mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Fix image proxy to handle binary data instead of JSON parsing
This commit is contained in:
@@ -2341,9 +2341,15 @@ public class JellyfinController : ControllerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle non-JSON responses (robots.txt, etc.)
|
// Handle non-JSON responses (images, robots.txt, etc.)
|
||||||
if (path.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
|
if (path.Contains("/Images/", StringComparison.OrdinalIgnoreCase) ||
|
||||||
path.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
|
path.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
path.EndsWith(".webp", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var fullPath = path;
|
var fullPath = path;
|
||||||
if (Request.QueryString.HasValue)
|
if (Request.QueryString.HasValue)
|
||||||
@@ -2355,14 +2361,42 @@ public class JellyfinController : ControllerBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await _proxyService.HttpClient.GetAsync(url);
|
// Forward authentication headers for image requests
|
||||||
var content = await response.Content.ReadAsStringAsync();
|
using var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
var contentType = response.Content.Headers.ContentType?.ToString() ?? "text/plain";
|
|
||||||
return Content(content, contentType);
|
// Forward auth headers from client
|
||||||
|
if (Request.Headers.TryGetValue("X-Emby-Authorization", out var embyAuth))
|
||||||
|
{
|
||||||
|
request.Headers.TryAddWithoutValidation("X-Emby-Authorization", embyAuth.ToString());
|
||||||
|
}
|
||||||
|
else if (Request.Headers.TryGetValue("Authorization", out var auth))
|
||||||
|
{
|
||||||
|
var authValue = auth.ToString();
|
||||||
|
if (authValue.Contains("MediaBrowser", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
authValue.Contains("Token=", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
request.Headers.TryAddWithoutValidation("X-Emby-Authorization", authValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.Headers.TryAddWithoutValidation("Authorization", authValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await _proxyService.HttpClient.GetAsync(request);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return StatusCode((int)response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentBytes = await response.Content.ReadAsByteArrayAsync();
|
||||||
|
var contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream";
|
||||||
|
return File(contentBytes, contentType);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(ex, "Failed to proxy non-JSON request for {Path}", path);
|
_logger.LogWarning(ex, "Failed to proxy binary request for {Path}", path);
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user