mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-27 22:57:09 -04:00
Use async requests for media cover proxy
(cherry picked from commit ad1f185330a30a2a9d27c9d3f18d384e66727c2a) Closes #9183
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Radarr.Http.Frontend.Mappers
|
||||
@@ -6,6 +7,6 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
{
|
||||
string Map(string resourceUrl);
|
||||
bool CanHandle(string resourceUrl);
|
||||
IActionResult GetResponse(string resourceUrl);
|
||||
Task<IActionResult> GetResponse(string resourceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
@@ -9,7 +10,7 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
{
|
||||
public class MediaCoverProxyMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly Regex _regex = new Regex(@"/MediaCoverProxy/(?<hash>\w+)/(?<filename>(.+)\.(jpg|png|gif))");
|
||||
private readonly Regex _regex = new (@"/MediaCoverProxy/(?<hash>\w+)/(?<filename>(.+)\.(jpg|png|gif))");
|
||||
|
||||
private readonly IMediaCoverProxy _mediaCoverProxy;
|
||||
private readonly IContentTypeProvider _mimeTypeProvider;
|
||||
@@ -30,7 +31,7 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
return resourceUrl.StartsWith("/MediaCoverProxy/", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public IActionResult GetResponse(string resourceUrl)
|
||||
public async Task<IActionResult> GetResponse(string resourceUrl)
|
||||
{
|
||||
var match = _regex.Match(resourceUrl);
|
||||
|
||||
@@ -42,7 +43,7 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
var hash = match.Groups["hash"].Value;
|
||||
var filename = match.Groups["filename"].Value;
|
||||
|
||||
var imageData = _mediaCoverProxy.GetImage(hash);
|
||||
var imageData = await _mediaCoverProxy.GetImage(hash);
|
||||
|
||||
if (!_mimeTypeProvider.TryGetContentType(filename, out var contentType))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
@@ -30,7 +31,7 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
|
||||
public abstract bool CanHandle(string resourceUrl);
|
||||
|
||||
public IActionResult GetResponse(string resourceUrl)
|
||||
public Task<IActionResult> GetResponse(string resourceUrl)
|
||||
{
|
||||
var filePath = Map(resourceUrl);
|
||||
|
||||
@@ -41,10 +42,10 @@ namespace Radarr.Http.Frontend.Mappers
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
|
||||
return new FileStreamResult(GetContentStream(filePath), new MediaTypeHeaderValue(contentType)
|
||||
return Task.FromResult<IActionResult>(new FileStreamResult(GetContentStream(filePath), new MediaTypeHeaderValue(contentType)
|
||||
{
|
||||
Encoding = contentType == "text/plain" ? Encoding.UTF8 : null
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
_logger.Warn("File {0} not found", filePath);
|
||||
|
||||
Reference in New Issue
Block a user