mirror of
https://github.com/Radarr/Radarr
synced 2024-12-27 10:19:41 +00:00
4188946395
file name sample uses HTTP GET instead of post
50 lines
No EOL
1.3 KiB
C#
50 lines
No EOL
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NLog;
|
|
using Nancy;
|
|
using NzbDrone.Api.Frontend.Mappers;
|
|
|
|
namespace NzbDrone.Api.Frontend
|
|
{
|
|
public class StaticResourceModule : NancyModule
|
|
{
|
|
private readonly IEnumerable<IMapHttpRequestsToDisk> _requestMappers;
|
|
private readonly Logger _logger;
|
|
|
|
|
|
public StaticResourceModule(IEnumerable<IMapHttpRequestsToDisk> requestMappers, Logger logger)
|
|
{
|
|
_requestMappers = requestMappers;
|
|
_logger = logger;
|
|
|
|
Get["/{resource*}"] = x => Index();
|
|
Get["/"] = x => Index();
|
|
}
|
|
|
|
private Response Index()
|
|
{
|
|
var path = Request.Url.Path;
|
|
|
|
if (
|
|
string.IsNullOrWhiteSpace(path) ||
|
|
path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase) ||
|
|
path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return new NotFoundResponse();
|
|
}
|
|
|
|
var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
|
|
|
|
|
|
if (mapper != null)
|
|
{
|
|
return mapper.GetResponse(path);
|
|
}
|
|
|
|
_logger.Warn("Couldn't find handler for {0}", path);
|
|
|
|
return new NotFoundResponse();
|
|
}
|
|
}
|
|
} |