mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Secret Dev Settings Page
This commit is contained in:
51
src/Readarr.Api.V1/Config/DevelopmentConfigController.cs
Normal file
51
src/Readarr.Api.V1/Config/DevelopmentConfigController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Http.REST.Attributes;
|
||||
using Readarr.Http;
|
||||
using Readarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Config
|
||||
{
|
||||
[V1ApiController("config/development")]
|
||||
public class DevelopmentConfigController : RestController<DevelopmentConfigResource>
|
||||
{
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public DevelopmentConfigController(IConfigFileProvider configFileProvider,
|
||||
IConfigService configService)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
public override DevelopmentConfigResource GetResourceById(int id)
|
||||
{
|
||||
return GetDevelopmentConfig();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public DevelopmentConfigResource GetDevelopmentConfig()
|
||||
{
|
||||
var resource = DevelopmentConfigResourceMapper.ToResource(_configFileProvider, _configService);
|
||||
resource.Id = 1;
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
[RestPutById]
|
||||
public ActionResult<DevelopmentConfigResource> SaveDevelopmentConfig(DevelopmentConfigResource resource)
|
||||
{
|
||||
var dictionary = resource.GetType()
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.ToDictionary(prop => prop.Name, prop => prop.GetValue(resource, null));
|
||||
|
||||
_configFileProvider.SaveConfigDictionary(dictionary);
|
||||
_configService.SaveConfigDictionary(dictionary);
|
||||
|
||||
return Accepted(resource.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/Readarr.Api.V1/Config/DevelopmentConfigResource.cs
Normal file
27
src/Readarr.Api.V1/Config/DevelopmentConfigResource.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Readarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Config
|
||||
{
|
||||
public class DevelopmentConfigResource : RestResource
|
||||
{
|
||||
public string ConsoleLogLevel { get; set; }
|
||||
public bool LogSql { get; set; }
|
||||
public int LogRotate { get; set; }
|
||||
public bool FilterSentryEvents { get; set; }
|
||||
}
|
||||
|
||||
public static class DevelopmentConfigResourceMapper
|
||||
{
|
||||
public static DevelopmentConfigResource ToResource(this IConfigFileProvider model, IConfigService configService)
|
||||
{
|
||||
return new DevelopmentConfigResource
|
||||
{
|
||||
ConsoleLogLevel = model.ConsoleLogLevel,
|
||||
LogSql = model.LogSql,
|
||||
LogRotate = model.LogRotate,
|
||||
FilterSentryEvents = model.FilterSentryEvents
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ namespace Readarr.Api.V1.Config
|
||||
[HttpGet]
|
||||
public HostConfigResource GetHostConfig()
|
||||
{
|
||||
var resource = _configFileProvider.ToResource(_configService);
|
||||
var resource = HostConfigResourceMapper.ToResource(_configFileProvider, _configService);
|
||||
resource.Id = 1;
|
||||
|
||||
var user = _userService.FindUser();
|
||||
|
||||
Reference in New Issue
Block a user