Posters/Banners/Fanart served from App_Data

pull/6/head
Mark McDowall 12 years ago
parent 16e00d77ca
commit 16e13e0c24

@ -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
}
}

@ -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; } }
}
}

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

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using NLog; using NLog;
using Nancy; using Nancy;
@ -14,13 +16,13 @@ namespace NzbDrone.Api.Frontend
public class StaticResourceProvider : IProcessStaticResource public class StaticResourceProvider : IProcessStaticResource
{ {
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IMapHttpRequestsToDisk _requestMapper; private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
private readonly Logger _logger; private readonly Logger _logger;
public StaticResourceProvider(IDiskProvider diskProvider, IMapHttpRequestsToDisk requestMapper, Logger logger) public StaticResourceProvider(IDiskProvider diskProvider, IEnumerable<IMapHttpRequestsToDisk> requestMappers, Logger logger)
{ {
_diskProvider = diskProvider; _diskProvider = diskProvider;
_requestMapper = requestMapper; _requestMappers = requestMappers;
_logger = logger; _logger = logger;
} }
@ -28,9 +30,21 @@ namespace NzbDrone.Api.Frontend
{ {
var path = context.Request.Url.Path.ToLower(); 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)) if (IsStaticResource(path))
{ {
var filePath = _requestMapper.Map(path); var filePath = _requestMappers.Single(r => r.IHandle == RequestType.StaticResources).Map(path);
if (_diskProvider.FileExists(filePath)) if (_diskProvider.FileExists(filePath))
{ {

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

@ -75,7 +75,7 @@ namespace NzbDrone.Core.MediaCover
private string GetSeriesCoverPath(int seriesId) private string GetSeriesCoverPath(int seriesId)
{ {
return Path.Combine(_coverRootFolder, seriesId.ToString("0000")); return Path.Combine(_coverRootFolder, seriesId.ToString());
} }
} }
} }

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

Loading…
Cancel
Save