mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
using pre-compiled handlebar templates
re-did static content from nancy
This commit is contained in:
parent
3720afd30d
commit
375f887539
21 changed files with 367 additions and 124 deletions
28
NzbDrone.Api/Frontend/IndexModule.cs
Normal file
28
NzbDrone.Api/Frontend/IndexModule.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using Nancy;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public class IndexModule : NancyModule
|
||||
{
|
||||
public IndexModule()
|
||||
{
|
||||
//Serve anything that doesn't have an extension
|
||||
Get[@"/(.*)"] = x => Index();
|
||||
}
|
||||
|
||||
private object Index()
|
||||
{
|
||||
if(
|
||||
Request.Path.Contains(".")
|
||||
|| Request.Path.StartsWith("/static", StringComparison.CurrentCultureIgnoreCase)
|
||||
|| Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
|
||||
return View["UI/index.html"];
|
||||
}
|
||||
}
|
||||
}
|
21
NzbDrone.Api/Frontend/StaticResourceMapper.cs
Normal file
21
NzbDrone.Api/Frontend/StaticResourceMapper.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.IO;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public interface IMapHttpRequestsToDisk
|
||||
{
|
||||
string Map(string resourceUrl);
|
||||
}
|
||||
|
||||
public class StaticResourceMapper : IMapHttpRequestsToDisk
|
||||
{
|
||||
public string Map(string resourceUrl)
|
||||
{
|
||||
var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar);
|
||||
path = path.Trim(Path.DirectorySeparatorChar).ToLower();
|
||||
|
||||
|
||||
return Path.Combine("ui", path);
|
||||
}
|
||||
}
|
||||
}
|
60
NzbDrone.Api/Frontend/StaticResourceProvider.cs
Normal file
60
NzbDrone.Api/Frontend/StaticResourceProvider.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using NzbDrone.Common;
|
||||
|
||||
namespace NzbDrone.Api.Frontend
|
||||
{
|
||||
public interface IProcessStaticResource
|
||||
{
|
||||
Response ProcessStaticResourceRequest(NancyContext context, string workingFolder);
|
||||
}
|
||||
|
||||
public class StaticResourceProvider : IProcessStaticResource
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly IMapHttpRequestsToDisk _requestMapper;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public StaticResourceProvider(DiskProvider diskProvider, IMapHttpRequestsToDisk requestMapper, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_requestMapper = requestMapper;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Response ProcessStaticResourceRequest(NancyContext context, string workingFolder)
|
||||
{
|
||||
var path = context.Request.Url.Path.ToLower();
|
||||
|
||||
if (IsStaticResource(path))
|
||||
{
|
||||
var filePath = _requestMapper.Map(path);
|
||||
|
||||
if (_diskProvider.FileExists(filePath))
|
||||
{
|
||||
return new GenericFileResponse(filePath);
|
||||
}
|
||||
|
||||
_logger.Warn("Couldn't find file [{0}] for [{1}]", filePath, path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static readonly string[] Extensions = new[] { ".css", ".js", ".html", ".htm", ".jpg", ".jpeg", ".icon", ".gif", ".png", ".woff", ".ttf" };
|
||||
|
||||
|
||||
private bool IsStaticResource(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Extensions.Any(path.EndsWith);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue