|
|
@ -1,4 +1,6 @@
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
using Nancy;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
@ -8,6 +10,8 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class MediaCoverMapper : StaticResourceMapperBase
|
|
|
|
public class MediaCoverMapper : StaticResourceMapperBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private static readonly Regex RegexResizedImage = new Regex(@"-\d+\.jpg($|\?)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
|
|
|
|
|
|
|
|
public MediaCoverMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, Logger logger)
|
|
|
|
public MediaCoverMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, Logger logger)
|
|
|
@ -24,6 +28,24 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|
|
|
return Path.Combine(_appFolderInfo.GetAppDataPath(), path);
|
|
|
|
return Path.Combine(_appFolderInfo.GetAppDataPath(), path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override Response GetResponse(string resourceUrl)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var result = base.GetResponse(resourceUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the full sized image if someone requests a non-existing resized one.
|
|
|
|
|
|
|
|
// TODO: This code can be removed later once everyone had the update for a while.
|
|
|
|
|
|
|
|
if (result is NotFoundResponse)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var baseResourceUrl = RegexResizedImage.Replace(resourceUrl, ".jpg$1");
|
|
|
|
|
|
|
|
if (baseResourceUrl != resourceUrl)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result = base.GetResponse(baseResourceUrl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override bool CanHandle(string resourceUrl)
|
|
|
|
public override bool CanHandle(string resourceUrl)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return resourceUrl.StartsWith("/MediaCover");
|
|
|
|
return resourceUrl.StartsWith("/MediaCover");
|
|
|
|