mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07:00
API Key in UI
New: view/reset API in General Settings Fixed: API will reject unauthenticated requests
This commit is contained in:
parent
0914441de7
commit
6b423c104c
16 changed files with 1194 additions and 45 deletions
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Nancy;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
@ -12,10 +12,12 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|||
public class IndexHtmlMapper : StaticResourceMapperBase
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly string _indexPath;
|
||||
private static readonly Regex ReplaceRegex = new Regex("(?<=(?:href|src|data-main)=\").*?(?=\")", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static String API_KEY;
|
||||
private static String URL_BASE;
|
||||
|
||||
public IndexHtmlMapper(IAppFolderInfo appFolderInfo,
|
||||
IDiskProvider diskProvider,
|
||||
IConfigFileProvider configFileProvider,
|
||||
|
@ -23,8 +25,10 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|||
: base(diskProvider, logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_configFileProvider = configFileProvider;
|
||||
_indexPath = Path.Combine(appFolderInfo.StartUpFolder, "UI", "index.html");
|
||||
|
||||
API_KEY = configFileProvider.ApiKey;
|
||||
URL_BASE = configFileProvider.UrlBase;
|
||||
}
|
||||
|
||||
protected override string Map(string resourceUrl)
|
||||
|
@ -54,12 +58,12 @@ namespace NzbDrone.Api.Frontend.Mappers
|
|||
{
|
||||
var text = _diskProvider.ReadAllText(_indexPath);
|
||||
|
||||
text = ReplaceRegex.Replace(text, match => _configFileProvider.UrlBase + match.Value);
|
||||
text = ReplaceRegex.Replace(text, match => URL_BASE + match.Value);
|
||||
|
||||
text = text.Replace(".css", ".css?v=" + BuildInfo.Version);
|
||||
text = text.Replace(".js", ".js?v=" + BuildInfo.Version);
|
||||
text = text.Replace("API_ROOT", _configFileProvider.UrlBase + "/api");
|
||||
text = text.Replace("API_KEY", _configFileProvider.ApiKey);
|
||||
text = text.Replace("API_ROOT", URL_BASE + "/api");
|
||||
text = text.Replace("API_KEY", API_KEY);
|
||||
text = text.Replace("APP_VERSION", BuildInfo.Version.ToString());
|
||||
|
||||
return text;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue