mirror of
https://github.com/Readarr/Readarr
synced 2025-12-15 12:52:27 +01:00
New: Download client UI matches other settings Fixed: Prevent drone factory folder from being set to invalid paths/root path for series Fixed: Switching pages in settings will not hide changes Fixed: Test download clients Fixed: Settings are validated before saving
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Linq;
|
|
using System.Reflection;
|
|
using NzbDrone.Api.REST;
|
|
using NzbDrone.Core.Configuration;
|
|
using Omu.ValueInjecter;
|
|
|
|
namespace NzbDrone.Api.Config
|
|
{
|
|
public abstract class NzbDroneConfigModule<TResource> : NzbDroneRestModule<TResource> where TResource : RestResource, new()
|
|
{
|
|
private readonly IConfigService _configService;
|
|
|
|
protected NzbDroneConfigModule(IConfigService configService)
|
|
: this(new TResource().ResourceName.Replace("config", ""), configService)
|
|
{
|
|
}
|
|
|
|
protected NzbDroneConfigModule(string resource, IConfigService configService) :
|
|
base("config/" + resource.Trim('/'))
|
|
{
|
|
_configService = configService;
|
|
|
|
GetResourceSingle = GetConfig;
|
|
GetResourceById = GetConfig;
|
|
UpdateResource = SaveConfig;
|
|
}
|
|
|
|
private TResource GetConfig()
|
|
{
|
|
var resource = new TResource();
|
|
resource.InjectFrom(_configService);
|
|
resource.Id = 1;
|
|
|
|
return resource;
|
|
}
|
|
|
|
private TResource GetConfig(int id)
|
|
{
|
|
return GetConfig();
|
|
}
|
|
|
|
private void SaveConfig(TResource resource)
|
|
{
|
|
var dictionary = resource.GetType()
|
|
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
|
.ToDictionary(prop => prop.Name, prop => prop.GetValue(resource, null));
|
|
|
|
_configService.SaveConfigDictionary(dictionary);
|
|
}
|
|
}
|
|
}
|