1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Posters/Banners/Fanart served from App_Data

This commit is contained in:
Mark McDowall 2013-05-16 20:03:52 -07:00
parent 16e00d77ca
commit 16e13e0c24
7 changed files with 72 additions and 28 deletions

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Api.Frontend
{
public interface IMapHttpRequestsToDisk
{
string Map(string resourceUrl);
RequestType IHandle { get; }
}
public enum RequestType
{
StaticResources,
MediaCovers
}
}

View File

@ -0,0 +1,25 @@
using System.IO;
using NzbDrone.Common;
namespace NzbDrone.Api.Frontend
{
public class MediaCoverMapper : IMapHttpRequestsToDisk
{
private readonly IEnvironmentProvider _environmentProvider;
public MediaCoverMapper(IEnvironmentProvider environmentProvider)
{
_environmentProvider = environmentProvider;
}
public string Map(string resourceUrl)
{
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
return Path.Combine(_environmentProvider.GetAppDataPath(), path);
}
public RequestType IHandle { get { return RequestType.MediaCovers; } }
}
}

View File

@ -2,11 +2,6 @@
namespace NzbDrone.Api.Frontend
{
public interface IMapHttpRequestsToDisk
{
string Map(string resourceUrl);
}
public class StaticResourceMapper : IMapHttpRequestsToDisk
{
public string Map(string resourceUrl)
@ -17,5 +12,7 @@ public string Map(string resourceUrl)
return Path.Combine("ui", path);
}
public RequestType IHandle { get { return RequestType.StaticResources; } }
}
}

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog;
using Nancy;
@ -14,13 +16,13 @@ public interface IProcessStaticResource
public class StaticResourceProvider : IProcessStaticResource
{
private readonly IDiskProvider _diskProvider;
private readonly IMapHttpRequestsToDisk _requestMapper;
private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
private readonly Logger _logger;
public StaticResourceProvider(IDiskProvider diskProvider, IMapHttpRequestsToDisk requestMapper, Logger logger)
public StaticResourceProvider(IDiskProvider diskProvider, IEnumerable<IMapHttpRequestsToDisk> requestMappers, Logger logger)
{
_diskProvider = diskProvider;
_requestMapper = requestMapper;
_requestMappers = requestMappers;
_logger = logger;
}
@ -28,9 +30,21 @@ public Response ProcessStaticResourceRequest(NancyContext context, string workin
{
var path = context.Request.Url.Path.ToLower();
if (path.StartsWith("/mediacover"))
{
var filePath = _requestMappers.Single(r => r.IHandle == RequestType.MediaCovers).Map(path);
if (_diskProvider.FileExists(filePath))
{
return new StreamResponse(() => File.OpenRead(filePath), "image/jpeg");
}
_logger.Warn("Couldn't find file [{0}] for [{1}]", filePath, path);
}
if (IsStaticResource(path))
{
var filePath = _requestMapper.Map(path);
var filePath = _requestMappers.Single(r => r.IHandle == RequestType.StaticResources).Map(path);
if (_diskProvider.FileExists(filePath))
{

View File

@ -97,6 +97,8 @@
<Compile Include="Episodes\EpisodeModule.cs" />
<Compile Include="Episodes\EpisodeResource.cs" />
<Compile Include="Extensions\NancyJsonSerializer.cs" />
<Compile Include="Frontend\MediaCoverMapper.cs" />
<Compile Include="Frontend\IMapHttpRequestsToDisk.cs" />
<Compile Include="Frontend\IndexModule.cs" />
<Compile Include="Frontend\StaticResourceProvider.cs" />
<Compile Include="Frontend\StaticResourceMapper.cs" />

View File

@ -75,7 +75,7 @@ private string GetCoverPath(int seriesId, MediaCoverTypes coverTypes)
private string GetSeriesCoverPath(int seriesId)
{
return Path.Combine(_coverRootFolder, seriesId.ToString("0000"));
return Path.Combine(_coverRootFolder, seriesId.ToString());
}
}
}

View File

@ -21,27 +21,14 @@ define(['app', 'Quality/QualityProfileCollection', 'AddSeries/RootFolders/RootFo
return percent;
},
banner : function () {
return "/mediacover/" + this.get('id') + "/banner.jpg";
},
poster : function () {
var poster = _.find(this.get('images'), function (image) {
return image.coverType === 'poster';
});
if (poster) {
return poster.url;
}
return undefined;
return "/mediacover/" + this.get('id') + "/poster.jpg";
},
fanArt : function () {
var poster = _.find(this.get('images'), function (image) {
return image.coverType === 3;
});
if (poster) {
return poster.url;
}
return undefined;
return "/mediacover/" + this.get('id') + "/fanart.jpg";
},
traktUrl : function () {
return "http://trakt.tv/show/" + this.get('titleSlug');