Fixed: Posters not always showing when searching for new authors

(cherry picked from commit 10dc884fa87a8337e9f0622c269adede0b262029)

Co-authored-by: optimous012

Closes #145
This commit is contained in:
Taloth Saldono
2020-01-12 22:26:29 +01:00
committed by Bogdan
parent 52c3a95e63
commit bb5ad605fd
11 changed files with 184 additions and 34 deletions

View File

@@ -6,6 +6,6 @@ namespace Readarr.Http.Frontend.Mappers
{
string Map(string resourceUrl);
bool CanHandle(string resourceUrl);
FileStreamResult GetResponse(string resourceUrl);
IActionResult GetResponse(string resourceUrl);
}
}

View File

@@ -43,7 +43,7 @@ namespace Readarr.Http.Frontend.Mappers
public override bool CanHandle(string resourceUrl)
{
return resourceUrl.StartsWith("/MediaCover", StringComparison.InvariantCultureIgnoreCase);
return resourceUrl.StartsWith("/MediaCover/", StringComparison.InvariantCultureIgnoreCase);
}
}
}

View File

@@ -0,0 +1,55 @@
using System;
using System.Net;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using NzbDrone.Core.MediaCover;
namespace Readarr.Http.Frontend.Mappers
{
public class MediaCoverProxyMapper : IMapHttpRequestsToDisk
{
private readonly Regex _regex = new Regex(@"/MediaCoverProxy/(?<hash>\w+)/(?<filename>(.+)\.(jpg|png|gif))");
private readonly IMediaCoverProxy _mediaCoverProxy;
private readonly IContentTypeProvider _mimeTypeProvider;
public MediaCoverProxyMapper(IMediaCoverProxy mediaCoverProxy)
{
_mediaCoverProxy = mediaCoverProxy;
_mimeTypeProvider = new FileExtensionContentTypeProvider();
}
public string Map(string resourceUrl)
{
return null;
}
public bool CanHandle(string resourceUrl)
{
return resourceUrl.StartsWith("/MediaCoverProxy/", StringComparison.InvariantCultureIgnoreCase);
}
public IActionResult GetResponse(string resourceUrl)
{
var match = _regex.Match(resourceUrl);
if (!match.Success)
{
return new StatusCodeResult((int)HttpStatusCode.NotFound);
}
var hash = match.Groups["hash"].Value;
var filename = match.Groups["filename"].Value;
var imageData = _mediaCoverProxy.GetImage(hash);
if (!_mimeTypeProvider.TryGetContentType(filename, out var contentType))
{
contentType = "application/octet-stream";
}
return new FileContentResult(imageData, contentType);
}
}
}

View File

@@ -30,7 +30,7 @@ namespace Readarr.Http.Frontend.Mappers
public abstract bool CanHandle(string resourceUrl);
public FileStreamResult GetResponse(string resourceUrl)
public IActionResult GetResponse(string resourceUrl)
{
var filePath = Map(resourceUrl);

View File

@@ -57,7 +57,7 @@ namespace Readarr.Http.Frontend
if (result != null)
{
if (result.ContentType == "text/html")
if ((result as FileResult)?.ContentType == "text/html")
{
Response.Headers.DisableCache();
}