mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-12-27 18:06:43 +00:00
Added an api call to pull down user configuration
This commit is contained in:
parent
0a48b5e31a
commit
6c7175e33d
18
MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs
Normal file
18
MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using MediaBrowser.Controller;
|
||||
|
||||
namespace MediaBrowser.Api.HttpHandlers
|
||||
{
|
||||
public class UserConfigurationHandler : JsonHandler
|
||||
{
|
||||
protected override object ObjectToSerialize
|
||||
{
|
||||
get
|
||||
{
|
||||
Guid userId = Guid.Parse(QueryString["userid"]);
|
||||
|
||||
return Kernel.Instance.ConfigurationController.GetUserConfiguration(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,7 @@
|
|||
<Compile Include="HttpHandlers\RecentlyAddedItemsHandler.cs" />
|
||||
<Compile Include="HttpHandlers\StudioHandler.cs" />
|
||||
<Compile Include="HttpHandlers\StudiosHandler.cs" />
|
||||
<Compile Include="HttpHandlers\UserConfigurationHandler.cs" />
|
||||
<Compile Include="HttpHandlers\UsersHandler.cs" />
|
||||
<Compile Include="ImageProcessor.cs" />
|
||||
<Compile Include="HttpHandlers\MediaHandler.cs" />
|
||||
|
|
|
@ -71,6 +71,10 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
handler = new InProgressItemsHandler();
|
||||
}
|
||||
else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
handler = new UserConfigurationHandler();
|
||||
}
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace MediaBrowser.Common.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Serves as a common base class for the Server and UI Configurations
|
||||
/// Serves as a common base class for the Server and UI application Configurations
|
||||
/// </summary>
|
||||
public class BaseConfiguration
|
||||
{
|
||||
|
|
37
MediaBrowser.Common/Configuration/ConfigurationController.cs
Normal file
37
MediaBrowser.Common/Configuration/ConfigurationController.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Json;
|
||||
|
||||
namespace MediaBrowser.Common.Configuration
|
||||
{
|
||||
public class ConfigurationController<TConfigurationType>
|
||||
where TConfigurationType : BaseConfiguration, new ()
|
||||
{
|
||||
/// <summary>
|
||||
/// The path to the configuration file
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
public TConfigurationType Configuration { get; set; }
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
if (!File.Exists(Path))
|
||||
{
|
||||
Configuration = new TConfigurationType();
|
||||
}
|
||||
else
|
||||
{
|
||||
Configuration = JsonSerializer.DeserializeFromFile<TConfigurationType>(Path);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
21
MediaBrowser.Common/Configuration/UserConfiguration.cs
Normal file
21
MediaBrowser.Common/Configuration/UserConfiguration.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Common.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// This holds settings that can be personalized on a per-user, per-device basis.
|
||||
/// </summary>
|
||||
public class UserConfiguration
|
||||
{
|
||||
public int RecentItemDays { get; set; }
|
||||
|
||||
public UserConfiguration()
|
||||
{
|
||||
RecentItemDays = 14;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,8 @@ namespace MediaBrowser.Common.Kernel
|
|||
/// <summary>
|
||||
/// Represents a shared base kernel for both the UI and server apps
|
||||
/// </summary>
|
||||
public abstract class BaseKernel<TConfigurationType>
|
||||
public abstract class BaseKernel<TConfigurationContorllerType, TConfigurationType>
|
||||
where TConfigurationContorllerType : ConfigurationController<TConfigurationType>, new()
|
||||
where TConfigurationType : BaseConfiguration, new()
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -23,7 +24,7 @@ namespace MediaBrowser.Common.Kernel
|
|||
/// <summary>
|
||||
/// Gets the current configuration
|
||||
/// </summary>
|
||||
public TConfigurationType Configuration { get; private set; }
|
||||
public TConfigurationContorllerType ConfigurationController { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Both the UI and server will have a built-in HttpServer.
|
||||
|
@ -38,19 +39,12 @@ namespace MediaBrowser.Common.Kernel
|
|||
/// </summary>
|
||||
protected KernelContext KernelContext { get { return KernelContext.Server; } }
|
||||
|
||||
protected virtual string HttpServerUrlPrefix
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/";
|
||||
}
|
||||
}
|
||||
|
||||
public BaseKernel()
|
||||
{
|
||||
ProgramDataPath = GetProgramDataPath();
|
||||
|
||||
PluginController = new PluginController() { PluginsPath = Path.Combine(ProgramDataPath, "Plugins") };
|
||||
ConfigurationController = new TConfigurationContorllerType() { Path = Path.Combine(ProgramDataPath, "config.js") };
|
||||
|
||||
Logger.LoggerInstance = new FileLogger(Path.Combine(ProgramDataPath, "Logs"));
|
||||
}
|
||||
|
@ -67,7 +61,6 @@ namespace MediaBrowser.Common.Kernel
|
|||
/// <summary>
|
||||
/// Gets the path to the application's ProgramDataFolder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string GetProgramDataPath()
|
||||
{
|
||||
string programDataPath = ConfigurationManager.AppSettings["ProgramDataPath"];
|
||||
|
@ -94,9 +87,9 @@ namespace MediaBrowser.Common.Kernel
|
|||
private void ReloadConfiguration()
|
||||
{
|
||||
// Deserialize config
|
||||
Configuration = GetConfiguration(ProgramDataPath);
|
||||
ConfigurationController.Reload();
|
||||
|
||||
Logger.LoggerInstance.LogSeverity = Configuration.LogSeverity;
|
||||
Logger.LoggerInstance.LogSeverity = ConfigurationController.Configuration.LogSeverity;
|
||||
}
|
||||
|
||||
private void ReloadHttpServer()
|
||||
|
@ -106,7 +99,7 @@ namespace MediaBrowser.Common.Kernel
|
|||
HttpServer.Dispose();
|
||||
}
|
||||
|
||||
HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
|
||||
HttpServer = new HttpServer("http://+:" + ConfigurationController.Configuration.HttpServerPortNumber + "/mediabrowser/");
|
||||
}
|
||||
|
||||
protected virtual void ReloadPlugins()
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration\BaseConfiguration.cs" />
|
||||
<Compile Include="Configuration\ConfigurationController.cs" />
|
||||
<Compile Include="Configuration\UserConfiguration.cs" />
|
||||
<Compile Include="Events\GenericItemEventArgs.cs" />
|
||||
<Compile Include="Json\JsonSerializer.cs" />
|
||||
<Compile Include="Kernel\BaseKernel.cs" />
|
||||
|
|
|
@ -1,16 +1,36 @@
|
|||
using MediaBrowser.Common.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
|
||||
namespace MediaBrowser.Controller.Configuration
|
||||
{
|
||||
public class ServerConfiguration : BaseConfiguration
|
||||
{
|
||||
public string ImagesByNamePath { get; set; }
|
||||
public int RecentItemDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default UI configuration
|
||||
/// </summary>
|
||||
public UserConfiguration DefaultUserConfiguration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a list of registered UI device names
|
||||
/// </summary>
|
||||
public List<string> DeviceNames { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets all available UIConfigurations
|
||||
/// The key contains device name and user id
|
||||
/// </summary>
|
||||
public Dictionary<string, UserConfiguration> UserConfigurations { get; set; }
|
||||
|
||||
public ServerConfiguration()
|
||||
: base()
|
||||
{
|
||||
RecentItemDays = 14;
|
||||
DefaultUserConfiguration = new UserConfiguration();
|
||||
|
||||
UserConfigurations = new Dictionary<string, UserConfiguration>();
|
||||
|
||||
DeviceNames = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
|
||||
namespace MediaBrowser.Controller.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends BaseConfigurationController by adding methods to get and set UIConfiguration data
|
||||
/// </summary>
|
||||
public class ServerConfigurationController : ConfigurationController<ServerConfiguration>
|
||||
{
|
||||
private string GetDictionaryKey(Guid userId, string deviceName)
|
||||
{
|
||||
string guidString = userId == Guid.Empty ? string.Empty : userId.ToString();
|
||||
|
||||
return deviceName + "-" + guidString;
|
||||
}
|
||||
|
||||
public UserConfiguration GetUserConfiguration(Guid userId)
|
||||
{
|
||||
return Configuration.DefaultUserConfiguration;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Kernel;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Events;
|
||||
|
@ -16,7 +17,7 @@ using MediaBrowser.Model.Users;
|
|||
|
||||
namespace MediaBrowser.Controller
|
||||
{
|
||||
public class Kernel : BaseKernel<ServerConfiguration>
|
||||
public class Kernel : BaseKernel<ServerConfigurationController, ServerConfiguration>
|
||||
{
|
||||
public static Kernel Instance { get; private set; }
|
||||
|
||||
|
@ -249,7 +250,9 @@ namespace MediaBrowser.Controller
|
|||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < Configuration.RecentItemDays);
|
||||
UserConfiguration config = ConfigurationController.GetUserConfiguration(userId);
|
||||
|
||||
return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < config.RecentItemDays);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration\ServerConfiguration.cs" />
|
||||
<Compile Include="Configuration\ServerConfigurationController.cs" />
|
||||
<Compile Include="Events\ItemResolveEventArgs.cs" />
|
||||
<Compile Include="IO\DirectoryWatchers.cs" />
|
||||
<Compile Include="IO\Shortcut.cs" />
|
||||
|
|
Loading…
Reference in a new issue