2013-05-20 20:30:23 +00:00
|
|
|
using System;
|
2013-03-29 23:00:38 +00:00
|
|
|
using System.IO;
|
2013-05-18 01:18:02 +00:00
|
|
|
using System.Linq;
|
2013-05-20 01:19:10 +00:00
|
|
|
using NzbDrone.Common;
|
2013-03-29 23:00:38 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Api.Frontend
|
|
|
|
{
|
|
|
|
public class StaticResourceMapper : IMapHttpRequestsToDisk
|
|
|
|
{
|
2013-05-20 01:19:10 +00:00
|
|
|
private readonly IEnvironmentProvider _environmentProvider;
|
2013-06-15 00:29:38 +00:00
|
|
|
private static readonly string[] Extensions = new[] {
|
|
|
|
".css",
|
|
|
|
".js",
|
|
|
|
".html",
|
|
|
|
".htm",
|
|
|
|
".jpg",
|
|
|
|
".jpeg",
|
|
|
|
".ico",
|
|
|
|
".icon",
|
|
|
|
".gif",
|
|
|
|
".png",
|
|
|
|
".woff",
|
|
|
|
".ttf",
|
|
|
|
".eot"
|
|
|
|
};
|
2013-05-18 01:18:02 +00:00
|
|
|
|
2013-05-20 01:19:10 +00:00
|
|
|
public StaticResourceMapper(IEnvironmentProvider environmentProvider)
|
|
|
|
{
|
|
|
|
_environmentProvider = environmentProvider;
|
|
|
|
}
|
|
|
|
|
2013-03-29 23:00:38 +00:00
|
|
|
public string Map(string resourceUrl)
|
|
|
|
{
|
|
|
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
|
|
|
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
|
|
|
|
|
|
|
|
2013-05-20 01:19:10 +00:00
|
|
|
return Path.Combine(_environmentProvider.StartUpPath, "ui", path);
|
2013-03-29 23:00:38 +00:00
|
|
|
}
|
2013-05-17 03:03:52 +00:00
|
|
|
|
2013-05-18 01:18:02 +00:00
|
|
|
public bool CanHandle(string resourceUrl)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(resourceUrl))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-20 20:30:23 +00:00
|
|
|
if (resourceUrl.StartsWith("/mediacover", StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-18 01:18:02 +00:00
|
|
|
return Extensions.Any(resourceUrl.EndsWith);
|
|
|
|
}
|
2013-03-29 23:00:38 +00:00
|
|
|
}
|
|
|
|
}
|