@ -13,11 +13,13 @@ namespace NzbDrone.Api.Frontend.Mappers
private static readonly Regex RegexResizedImage = new Regex ( @"-\d+\.jpg($|\?)" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
private static readonly Regex RegexResizedImage = new Regex ( @"-\d+\.jpg($|\?)" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
private readonly IAppFolderInfo _appFolderInfo ;
private readonly IAppFolderInfo _appFolderInfo ;
private readonly IDiskProvider _diskProvider ;
public MediaCoverMapper ( IAppFolderInfo appFolderInfo , IDiskProvider diskProvider , Logger logger )
public MediaCoverMapper ( IAppFolderInfo appFolderInfo , IDiskProvider diskProvider , Logger logger )
: base ( diskProvider , logger )
: base ( diskProvider , logger )
{
{
_appFolderInfo = appFolderInfo ;
_appFolderInfo = appFolderInfo ;
_diskProvider = diskProvider ;
}
}
public override string Map ( string resourceUrl )
public override string Map ( string resourceUrl )
@ -25,25 +27,18 @@ namespace NzbDrone.Api.Frontend.Mappers
var path = resourceUrl . Replace ( '/' , Path . DirectorySeparatorChar ) ;
var path = resourceUrl . Replace ( '/' , Path . DirectorySeparatorChar ) ;
path = path . Trim ( Path . DirectorySeparatorChar ) ;
path = path . Trim ( Path . DirectorySeparatorChar ) ;
return Path . Combine ( _appFolderInfo . GetAppDataPath ( ) , path ) ;
var resourcePath = 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.
if ( ! _diskProvider . FileExists ( resourcePath ) | | _diskProvider . GetFileSize ( resourcePath ) = = 0 )
// TODO: This code can be removed later once everyone had the update for a while.
if ( result is NotFoundResponse )
{
{
var baseResource Url = RegexResizedImage . Replace ( resourceUrl , ".jpg$1" ) ;
var baseResourcePath = RegexResizedImage . Replace ( resourcePath , ".jpg$1" ) ;
if ( baseResource Url ! = resourceUrl )
if ( baseResourcePath ! = resourcePath )
{
{
result = base . GetResponse ( baseResourceUrl ) ;
return baseResourcePath ;
}
}
}
}
return res ult ;
return res ourcePath ;
}
}
public override bool CanHandle ( string resourceUrl )
public override bool CanHandle ( string resourceUrl )