2019-01-13 20:24:58 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-07-11 06:27:46 +02:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2019-01-13 20:24:58 +01:00
|
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2014-07-04 04:22:57 +02:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2014-02-02 14:36:31 +01:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2016-10-25 21:02:04 +02:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 20:24:58 +01:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2016-10-25 21:02:04 +02:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2014-02-02 14:36:31 +01:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/System/Configuration", "GET", Summary = "Gets application configuration")]
|
2014-07-08 03:41:03 +02:00
|
|
|
|
[Authenticated]
|
2014-02-02 14:36:31 +01:00
|
|
|
|
public class GetConfiguration : IReturn<ServerConfiguration>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 19:35:05 +02:00
|
|
|
|
[Route("/System/Configuration/{Key}", "GET", Summary = "Gets a named configuration")]
|
2015-08-22 19:11:14 +02:00
|
|
|
|
[Authenticated(AllowBeforeStartupWizard = true)]
|
2014-06-29 19:35:05 +02:00
|
|
|
|
public class GetNamedConfiguration
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Key", Description = "Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
}
|
2014-11-15 03:31:03 +01:00
|
|
|
|
|
2014-02-02 14:36:31 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/System/Configuration", "POST", Summary = "Updates application configuration")]
|
2014-11-15 03:31:03 +01:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-02-02 14:36:31 +01:00
|
|
|
|
public class UpdateConfiguration : ServerConfiguration, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 19:35:05 +02:00
|
|
|
|
[Route("/System/Configuration/{Key}", "POST", Summary = "Updates named configuration")]
|
2014-11-15 03:31:03 +01:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-06-29 19:35:05 +02:00
|
|
|
|
public class UpdateNamedConfiguration : IReturnVoid, IRequiresRequestStream
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Key", Description = "Key", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
|
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
|
}
|
2014-11-15 03:31:03 +01:00
|
|
|
|
|
2014-03-25 22:13:55 +01:00
|
|
|
|
[Route("/System/Configuration/MetadataOptions/Default", "GET", Summary = "Gets a default MetadataOptions object")]
|
2014-11-15 03:31:03 +01:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2014-02-02 14:36:31 +01:00
|
|
|
|
public class GetDefaultMetadataOptions : IReturn<MetadataOptions>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 19:04:18 +02:00
|
|
|
|
[Route("/System/MediaEncoder/Path", "POST", Summary = "Updates the path to the media encoder")]
|
|
|
|
|
[Authenticated(Roles = "Admin", AllowBeforeStartupWizard = true)]
|
|
|
|
|
public class UpdateMediaEncoderPath : IReturnVoid
|
|
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
|
[ApiMember(Name = "Path", Description = "Path", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2016-06-23 19:04:18 +02:00
|
|
|
|
public string Path { get; set; }
|
2018-09-12 19:26:21 +02:00
|
|
|
|
[ApiMember(Name = "PathType", Description = "PathType", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2016-06-29 07:49:31 +02:00
|
|
|
|
public string PathType { get; set; }
|
2016-06-23 19:04:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 14:36:31 +01:00
|
|
|
|
public class ConfigurationService : BaseApiService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _configuration manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IServerConfigurationManager _configurationManager;
|
|
|
|
|
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IProviderManager _providerManager;
|
2014-07-11 06:27:46 +02:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2016-06-23 19:04:18 +02:00
|
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
2014-02-02 14:36:31 +01:00
|
|
|
|
|
2016-06-23 19:04:18 +02:00
|
|
|
|
public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder)
|
2014-02-02 14:36:31 +01:00
|
|
|
|
{
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
_providerManager = providerManager;
|
2014-07-11 06:27:46 +02:00
|
|
|
|
_libraryManager = libraryManager;
|
2016-06-23 19:04:18 +02:00
|
|
|
|
_mediaEncoder = mediaEncoder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Post(UpdateMediaEncoderPath request)
|
|
|
|
|
{
|
2017-05-26 08:48:54 +02:00
|
|
|
|
_mediaEncoder.UpdateEncoderPath(request.Path, request.PathType);
|
2014-02-02 14:36:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetConfiguration request)
|
|
|
|
|
{
|
2016-01-20 20:54:06 +01:00
|
|
|
|
return ToOptimizedResult(_configurationManager.Configuration);
|
2014-02-02 14:36:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 19:35:05 +02:00
|
|
|
|
public object Get(GetNamedConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
var result = _configurationManager.GetConfiguration(request.Key);
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 14:36:31 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified configuraiton.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdateConfiguration request)
|
|
|
|
|
{
|
|
|
|
|
// Silly, but we need to serialize and deserialize or the XmlSerializer will write the xml with an element name of UpdateConfiguration
|
|
|
|
|
var json = _jsonSerializer.SerializeToString(request);
|
|
|
|
|
|
|
|
|
|
var config = _jsonSerializer.DeserializeFromString<ServerConfiguration>(json);
|
|
|
|
|
|
|
|
|
|
_configurationManager.ReplaceConfiguration(config);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
|
public async Task Post(UpdateNamedConfiguration request)
|
2014-06-29 19:35:05 +02:00
|
|
|
|
{
|
2015-01-22 17:41:34 +01:00
|
|
|
|
var key = GetPathValue(2);
|
2014-06-29 19:35:05 +02:00
|
|
|
|
|
|
|
|
|
var configurationType = _configurationManager.GetConfigurationType(key);
|
2018-09-12 19:26:21 +02:00
|
|
|
|
var configuration = await _jsonSerializer.DeserializeFromStreamAsync(request.RequestStream, configurationType).ConfigureAwait(false);
|
2014-11-15 03:31:03 +01:00
|
|
|
|
|
2014-06-29 19:35:05 +02:00
|
|
|
|
_configurationManager.SaveConfiguration(key, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 14:36:31 +01:00
|
|
|
|
public object Get(GetDefaultMetadataOptions request)
|
|
|
|
|
{
|
2018-09-12 19:26:21 +02:00
|
|
|
|
return ToOptimizedResult(new MetadataOptions());
|
2014-02-02 14:36:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|