mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 21:13:28 -07:00
Added API key authentication
This commit is contained in:
parent
689f27bee6
commit
57fdbe6e08
11 changed files with 114 additions and 15 deletions
|
@ -1,20 +1,28 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Api.Frontend.Mappers
|
||||
{
|
||||
public class IndexHtmlMapper : StaticResourceMapperBase
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly string _indexPath;
|
||||
|
||||
public IndexHtmlMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, Logger logger)
|
||||
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
||||
IDiskProvider diskProvider,
|
||||
IConfigFileProvider configFileProvider,
|
||||
Logger logger)
|
||||
: base(diskProvider, logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html");
|
||||
}
|
||||
|
||||
|
@ -30,7 +38,21 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|||
|
||||
public override Response GetResponse(string resourceUrl)
|
||||
{
|
||||
string content;
|
||||
var response = base.GetResponse(resourceUrl);
|
||||
var stream = new MemoryStream();
|
||||
|
||||
response.Contents.Invoke(stream);
|
||||
stream.Position = 0;
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
content = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
content = content.Replace("API_KEY", _configFileProvider.ApiKey);
|
||||
|
||||
response = new StreamResponse(() => StringToStream(content), response.ContentType);
|
||||
response.Headers["X-UA-Compatible"] = "IE=edge";
|
||||
|
||||
return response;
|
||||
|
@ -51,6 +73,5 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|||
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue