mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-01 03:42:51 +01:00
Added new api handlers to get plugin information
This commit is contained in:
parent
6c7175e33d
commit
84af205572
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,6 @@
|
||||
<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" />
|
||||
@@ -63,7 +62,6 @@
|
||||
<Compile Include="Net\Request.cs" />
|
||||
<Compile Include="Net\RequestContext.cs" />
|
||||
<Compile Include="Net\StreamExtensions.cs" />
|
||||
<Compile Include="Plugins\BasePluginConfiguration.cs" />
|
||||
<Compile Include="Logging\BaseLogger.cs" />
|
||||
<Compile Include="Logging\FileLogger.cs" />
|
||||
<Compile Include="Logging\Logger.cs" />
|
||||
|
||||
@@ -1,49 +1,97 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Model.Plugins;
|
||||
|
||||
namespace MediaBrowser.Common.Plugins
|
||||
{
|
||||
public abstract class BasePlugin<TConfigurationType> : IPlugin
|
||||
/// <summary>
|
||||
/// Provides a BasePlugin with generics, allowing for strongly typed configuration access.
|
||||
/// </summary>
|
||||
public abstract class BaseGenericPlugin<TConfigurationType> : BasePlugin
|
||||
where TConfigurationType : BasePluginConfiguration, new()
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public TConfigurationType Configuration { get; private set; }
|
||||
public new TConfigurationType Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Configuration as TConfigurationType;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Configuration = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string ConfigurationPath
|
||||
public override void ReloadConfiguration()
|
||||
{
|
||||
if (!File.Exists(ConfigurationPath))
|
||||
{
|
||||
Configuration = new TConfigurationType();
|
||||
}
|
||||
else
|
||||
{
|
||||
Configuration = JsonSerializer.DeserializeFromFile<TConfigurationType>(ConfigurationPath);
|
||||
Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides a common base class for all plugins
|
||||
/// </summary>
|
||||
public abstract class BasePlugin
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
public string Path { get; set; }
|
||||
public Version Version { get; set; }
|
||||
|
||||
public BasePluginConfiguration Configuration { get; protected set; }
|
||||
|
||||
protected string ConfigurationPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.IO.Path.Combine(Path, "config.js");
|
||||
}
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
Configuration = GetConfiguration();
|
||||
|
||||
if (Configuration.Enabled)
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
InitInternal();
|
||||
return Configuration.Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void InitInternal();
|
||||
|
||||
private TConfigurationType GetConfiguration()
|
||||
public DateTime ConfigurationDateLastModified
|
||||
{
|
||||
if (!File.Exists(ConfigurationPath))
|
||||
get
|
||||
{
|
||||
return new TConfigurationType();
|
||||
return Configuration.DateLastModified;
|
||||
}
|
||||
|
||||
return JsonSerializer.DeserializeFromFile<TConfigurationType>(ConfigurationPath);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlugin
|
||||
{
|
||||
string Path { get; set; }
|
||||
/// <summary>
|
||||
/// Returns true or false indicating if the plugin should be downloaded and run within the UI.
|
||||
/// </summary>
|
||||
public virtual bool DownloadToUI
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ReloadConfiguration();
|
||||
|
||||
public virtual void InitInServer()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void InitInUI()
|
||||
{
|
||||
}
|
||||
|
||||
void Init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
namespace MediaBrowser.Common.Plugins
|
||||
{
|
||||
public class BasePluginConfiguration
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public BasePluginConfiguration()
|
||||
{
|
||||
Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace MediaBrowser.Common.Plugins
|
||||
/// <summary>
|
||||
/// Gets the list of currently loaded plugins
|
||||
/// </summary>
|
||||
public IEnumerable<IPlugin> Plugins { get; private set; }
|
||||
public IEnumerable<BasePlugin> Plugins { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the controller
|
||||
@@ -32,7 +32,21 @@ namespace MediaBrowser.Common.Plugins
|
||||
|
||||
Parallel.For(0, Plugins.Count(), i =>
|
||||
{
|
||||
Plugins.ElementAt(i).Init();
|
||||
var plugin = Plugins.ElementAt(i);
|
||||
|
||||
plugin.ReloadConfiguration();
|
||||
|
||||
if (plugin.Enabled)
|
||||
{
|
||||
if (context == KernelContext.Server)
|
||||
{
|
||||
plugin.InitInServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.InitInUI();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,18 +54,18 @@ namespace MediaBrowser.Common.Plugins
|
||||
/// Gets all plugins within PluginsPath
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<IPlugin> GetAllPlugins()
|
||||
private IEnumerable<BasePlugin> GetAllPlugins()
|
||||
{
|
||||
if (!Directory.Exists(PluginsPath))
|
||||
{
|
||||
Directory.CreateDirectory(PluginsPath);
|
||||
}
|
||||
|
||||
List<IPlugin> plugins = new List<IPlugin>();
|
||||
List<BasePlugin> plugins = new List<BasePlugin>();
|
||||
|
||||
foreach (string folder in Directory.GetDirectories(PluginsPath, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
IPlugin plugin = GetPluginFromDirectory(folder);
|
||||
BasePlugin plugin = GetPluginFromDirectory(folder);
|
||||
|
||||
plugin.Path = folder;
|
||||
|
||||
@@ -64,7 +78,7 @@ namespace MediaBrowser.Common.Plugins
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private IPlugin GetPluginFromDirectory(string path)
|
||||
private BasePlugin GetPluginFromDirectory(string path)
|
||||
{
|
||||
string dll = Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly).FirstOrDefault();
|
||||
|
||||
@@ -76,18 +90,22 @@ namespace MediaBrowser.Common.Plugins
|
||||
return null;
|
||||
}
|
||||
|
||||
private IPlugin GetPluginFromDll(string path)
|
||||
private BasePlugin GetPluginFromDll(string path)
|
||||
{
|
||||
return GetPluginFromDll(Assembly.Load(File.ReadAllBytes(path)));
|
||||
}
|
||||
|
||||
private IPlugin GetPluginFromDll(Assembly assembly)
|
||||
private BasePlugin GetPluginFromDll(Assembly assembly)
|
||||
{
|
||||
var plugin = assembly.GetTypes().Where(type => typeof(IPlugin).IsAssignableFrom(type)).FirstOrDefault();
|
||||
var plugin = assembly.GetTypes().Where(type => typeof(BasePlugin).IsAssignableFrom(type)).FirstOrDefault();
|
||||
|
||||
if (plugin != null)
|
||||
{
|
||||
return plugin.GetConstructor(Type.EmptyTypes).Invoke(null) as IPlugin;
|
||||
BasePlugin instance = plugin.GetConstructor(Type.EmptyTypes).Invoke(null) as BasePlugin;
|
||||
|
||||
instance.Version = assembly.GetName().Version;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user