2017-12-14 02:46:44 +00:00
|
|
|
using System.IO;
|
2013-08-20 06:23:36 +00:00
|
|
|
using NLog;
|
2014-01-06 06:20:08 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2013-06-28 00:04:52 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2015-07-22 02:42:38 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-05-17 03:03:52 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
namespace Lidarr.Http.Frontend.Mappers
|
2013-05-17 03:03:52 +00:00
|
|
|
{
|
2013-08-20 06:23:36 +00:00
|
|
|
public class StaticResourceMapper : StaticResourceMapperBase
|
2013-05-17 03:03:52 +00:00
|
|
|
{
|
2013-07-05 04:43:28 +00:00
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
2015-07-22 02:42:38 +00:00
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2013-05-17 03:03:52 +00:00
|
|
|
|
2015-07-22 02:42:38 +00:00
|
|
|
public StaticResourceMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, IConfigFileProvider configFileProvider, Logger logger)
|
2013-08-20 06:23:36 +00:00
|
|
|
: base(diskProvider, logger)
|
2013-05-17 03:03:52 +00:00
|
|
|
{
|
2013-07-05 04:43:28 +00:00
|
|
|
_appFolderInfo = appFolderInfo;
|
2015-07-22 02:42:38 +00:00
|
|
|
_configFileProvider = configFileProvider;
|
2013-05-17 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 07:40:23 +00:00
|
|
|
public override string Map(string resourceUrl)
|
2013-05-17 03:03:52 +00:00
|
|
|
{
|
|
|
|
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
2013-07-24 06:26:10 +00:00
|
|
|
path = path.Trim(Path.DirectorySeparatorChar);
|
2013-05-17 03:03:52 +00:00
|
|
|
|
2015-07-22 02:42:38 +00:00
|
|
|
return Path.Combine(_appFolderInfo.StartUpFolder, _configFileProvider.UiFolder, path);
|
2013-05-17 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
2013-08-20 06:23:36 +00:00
|
|
|
public override bool CanHandle(string resourceUrl)
|
2013-05-18 01:18:02 +00:00
|
|
|
{
|
2017-12-14 02:46:44 +00:00
|
|
|
resourceUrl = resourceUrl.ToLowerInvariant();
|
|
|
|
|
|
|
|
if (resourceUrl.StartsWith("/content/images/icons/manifest") ||
|
|
|
|
resourceUrl.StartsWith("/content/images/icons/browserconfig"))
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:46:44 +00:00
|
|
|
return resourceUrl.StartsWith("/content") ||
|
2023-07-18 03:37:02 +00:00
|
|
|
resourceUrl.EndsWith(".js") ||
|
2015-02-03 01:18:45 +00:00
|
|
|
resourceUrl.EndsWith(".map") ||
|
2014-03-14 04:23:47 +00:00
|
|
|
resourceUrl.EndsWith(".css") ||
|
2014-05-04 07:11:43 +00:00
|
|
|
(resourceUrl.EndsWith(".ico") && !resourceUrl.Equals("/favicon.ico")) ||
|
2015-06-25 07:10:40 +00:00
|
|
|
resourceUrl.EndsWith(".swf") ||
|
|
|
|
resourceUrl.EndsWith("oauth.html");
|
2013-05-18 01:18:02 +00:00
|
|
|
}
|
2013-05-17 03:03:52 +00:00
|
|
|
}
|
2017-12-14 02:46:44 +00:00
|
|
|
}
|