mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
110 lines
3.6 KiB
C#
110 lines
3.6 KiB
C#
using MediaBrowser.Common.Extensions;
|
|
using MediaBrowser.Common.IO;
|
|
using MediaBrowser.Controller.Configuration;
|
|
using MediaBrowser.Controller.Providers;
|
|
using MediaBrowser.Model.Configuration;
|
|
using MediaBrowser.Model.Serialization;
|
|
using ServiceStack;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MediaBrowser.Api
|
|
{
|
|
/// <summary>
|
|
/// Class GetConfiguration
|
|
/// </summary>
|
|
[Route("/System/Configuration", "GET")]
|
|
[Api(("Gets application configuration"))]
|
|
public class GetConfiguration : IReturn<ServerConfiguration>
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Class UpdateConfiguration
|
|
/// </summary>
|
|
[Route("/System/Configuration", "POST")]
|
|
[Api(("Updates application configuration"))]
|
|
public class UpdateConfiguration : ServerConfiguration, IReturnVoid
|
|
{
|
|
}
|
|
|
|
[Route("/System/Configuration/MetadataOptions/Default", "GET")]
|
|
[Api(("Gets a default MetadataOptions object"))]
|
|
public class GetDefaultMetadataOptions : IReturn<MetadataOptions>
|
|
{
|
|
|
|
}
|
|
|
|
[Route("/System/Configuration/MetadataPlugins", "GET")]
|
|
[Api(("Gets all available metadata plugins"))]
|
|
public class GetMetadataPlugins : IReturn<List<MetadataPluginSummary>>
|
|
{
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
public ConfigurationService(IJsonSerializer jsonSerializer, IServerConfigurationManager configurationManager, IFileSystem fileSystem, IProviderManager providerManager)
|
|
{
|
|
_jsonSerializer = jsonSerializer;
|
|
_configurationManager = configurationManager;
|
|
_fileSystem = fileSystem;
|
|
_providerManager = providerManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the specified request.
|
|
/// </summary>
|
|
/// <param name="request">The request.</param>
|
|
/// <returns>System.Object.</returns>
|
|
public object Get(GetConfiguration request)
|
|
{
|
|
var configPath = _configurationManager.ApplicationPaths.SystemConfigurationFilePath;
|
|
|
|
var dateModified = _fileSystem.GetLastWriteTimeUtc(configPath);
|
|
|
|
var cacheKey = (configPath + dateModified.Ticks).GetMD5();
|
|
|
|
return ToOptimizedResultUsingCache(cacheKey, dateModified, null, () => _configurationManager.Configuration);
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
|
|
public object Get(GetDefaultMetadataOptions request)
|
|
{
|
|
return ToOptimizedSerializedResultUsingCache(new MetadataOptions());
|
|
}
|
|
|
|
public object Get(GetMetadataPlugins request)
|
|
{
|
|
return ToOptimizedSerializedResultUsingCache(_providerManager.GetAllMetadataPlugins().ToList());
|
|
}
|
|
}
|
|
}
|