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