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