2013-04-25 07:27:49 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Nancy;
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Config
|
|
|
|
{
|
|
|
|
public class SettingsModule : NzbDroneApiModule
|
|
|
|
{
|
|
|
|
private readonly IConfigService _configService;
|
2013-05-23 08:12:01 +03:00
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2013-04-25 07:27:49 +03:00
|
|
|
|
2013-05-23 08:12:01 +03:00
|
|
|
public SettingsModule(IConfigService configService, IConfigFileProvider configFileProvider)
|
2013-04-25 07:27:49 +03:00
|
|
|
: base("/settings")
|
|
|
|
{
|
|
|
|
_configService = configService;
|
2013-05-23 08:12:01 +03:00
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
Get["/"] = x => GetGeneralSettings();
|
|
|
|
Post["/"] = x => SaveGeneralSettings();
|
|
|
|
|
|
|
|
Get["/host"] = x => GetHostSettings();
|
|
|
|
Post["/host"] = x => SaveHostSettings();
|
2013-07-24 03:35:35 +03:00
|
|
|
|
|
|
|
Get["/log"] = x => GetLogSettings();
|
|
|
|
Post["/log"] = x => SaveLogSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Response SaveLogSettings()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Response GetLogSettings()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
2013-05-23 08:12:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private Response SaveHostSettings()
|
|
|
|
{
|
|
|
|
var request = Request.Body.FromJson<Dictionary<string, object>>();
|
|
|
|
_configFileProvider.SaveConfigDictionary(request);
|
|
|
|
|
|
|
|
return GetHostSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Response GetHostSettings()
|
|
|
|
{
|
|
|
|
return _configFileProvider.GetConfigDictionary().AsResponse();
|
2013-04-25 07:27:49 +03:00
|
|
|
}
|
|
|
|
|
2013-05-23 08:12:01 +03:00
|
|
|
private Response GetGeneralSettings()
|
2013-04-25 07:27:49 +03:00
|
|
|
{
|
|
|
|
var collection = Request.Query.Collection;
|
|
|
|
|
|
|
|
if (collection.HasValue && Boolean.Parse(collection.Value))
|
|
|
|
return _configService.All().AsResponse();
|
|
|
|
|
|
|
|
return _configService.AllWithDefaults().AsResponse();
|
|
|
|
}
|
|
|
|
|
2013-05-23 08:12:01 +03:00
|
|
|
private Response SaveGeneralSettings()
|
2013-04-25 07:27:49 +03:00
|
|
|
{
|
|
|
|
var request = Request.Body.FromJson<Dictionary<string, object>>();
|
|
|
|
_configService.SaveValues(request);
|
|
|
|
|
|
|
|
|
|
|
|
return request.AsResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|