|
|
@ -1,6 +1,7 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
|
using NzbDrone.Core.MediaCover;
|
|
|
|
using NzbDrone.Core.MediaCover;
|
|
|
@ -9,7 +10,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class MediaCoverProxyMapper : IMapHttpRequestsToDisk
|
|
|
|
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 IMediaCoverProxy _mediaCoverProxy;
|
|
|
|
private readonly IContentTypeProvider _mimeTypeProvider;
|
|
|
|
private readonly IContentTypeProvider _mimeTypeProvider;
|
|
|
@ -30,7 +31,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|
|
|
return resourceUrl.StartsWith("/MediaCoverProxy/", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
return resourceUrl.StartsWith("/MediaCoverProxy/", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult GetResponse(string resourceUrl)
|
|
|
|
public async Task<IActionResult> GetResponse(string resourceUrl)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var match = _regex.Match(resourceUrl);
|
|
|
|
var match = _regex.Match(resourceUrl);
|
|
|
|
|
|
|
|
|
|
|
@ -42,7 +43,7 @@ namespace Sonarr.Http.Frontend.Mappers
|
|
|
|
var hash = match.Groups["hash"].Value;
|
|
|
|
var hash = match.Groups["hash"].Value;
|
|
|
|
var filename = match.Groups["filename"].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))
|
|
|
|
if (!_mimeTypeProvider.TryGetContentType(filename, out var contentType))
|
|
|
|
{
|
|
|
|
{
|
|
|
|