From 7986465cf785ca385fd1765326887e550bced033 Mon Sep 17 00:00:00 2001 From: Greenback Date: Sun, 6 Dec 2020 23:48:54 +0000 Subject: Initial upload --- Jellyfin.Api/Controllers/PluginsController.cs | 288 ++++++++++++++++++++------ 1 file changed, 220 insertions(+), 68 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 98f1bc2d2..3f366dd79 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -1,15 +1,22 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Globalization; +using System.IO; using System.Linq; +using System.Net.Mime; using System.Text.Json; using System.Threading.Tasks; +using Jellyfin.Api.Attributes; using Jellyfin.Api.Constants; using Jellyfin.Api.Models.PluginDtos; -using MediaBrowser.Common; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Json; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; +using MediaBrowser.Controller.Drawing; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Net; using MediaBrowser.Model.Plugins; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -23,22 +30,81 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.DefaultAuthorization)] public class PluginsController : BaseJellyfinApiController { - private readonly IApplicationHost _appHost; private readonly IInstallationManager _installationManager; - - private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.GetOptions(); + private readonly IPluginManager _pluginManager; + private readonly IConfigurationManager _config; + private readonly JsonSerializerOptions _serializerOptions; /// /// Initializes a new instance of the class. /// - /// Instance of the interface. /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public PluginsController( - IApplicationHost appHost, - IInstallationManager installationManager) + IInstallationManager installationManager, + IPluginManager pluginManager, + IConfigurationManager config) { - _appHost = appHost; _installationManager = installationManager; + _pluginManager = pluginManager; + _serializerOptions = JsonDefaults.GetOptions(); + _config = config; + } + + /// + /// Get plugin security info. + /// + /// Plugin security info returned. + /// Plugin security info. + [Obsolete("This endpoint should not be used.")] + [HttpGet("SecurityInfo")] + [ProducesResponseType(StatusCodes.Status200OK)] + public static ActionResult GetPluginSecurityInfo() + { + return new PluginSecurityInfo + { + IsMbSupporter = true, + SupporterKey = "IAmTotallyLegit" + }; + } + + /// + /// Gets registration status for a feature. + /// + /// Feature name. + /// Registration status returned. + /// Mb registration record. + [Obsolete("This endpoint should not be used.")] + [HttpPost("RegistrationRecords/{name}")] + [ProducesResponseType(StatusCodes.Status200OK)] + public static ActionResult GetRegistrationStatus([FromRoute, Required] string name) + { + return new MBRegistrationRecord + { + IsRegistered = true, + RegChecked = true, + TrialVersion = false, + IsValid = true, + RegError = false + }; + } + + /// + /// Gets registration status for a feature. + /// + /// Feature name. + /// Not implemented. + /// Not Implemented. + /// This endpoint is not implemented. + [Obsolete("Paid plugins are not supported")] + [HttpGet("Registrations/{name}")] + [ProducesResponseType(StatusCodes.Status501NotImplemented)] + public static ActionResult GetRegistration([FromRoute, Required] string name) + { + // TODO Once we have proper apps and plugins and decide to break compatibility with paid plugins, + // delete all these registration endpoints. They are only kept for compatibility. + throw new NotImplementedException(); } /// @@ -48,15 +114,65 @@ namespace Jellyfin.Api.Controllers /// List of currently installed plugins. [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesFile(MediaTypeNames.Application.Json)] public ActionResult> GetPlugins() { - return Ok(_appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo())); + return Ok(_pluginManager.Plugins + .OrderBy(p => p.Name) + .Select(p => p.GetPluginInfo())); + } + + /// + /// Enables a disabled plugin. + /// + /// Plugin id. + /// Plugin version. + /// Plugin enabled. + /// Plugin not found. + /// An on success, or a if the file could not be found. + [HttpPost("{pluginId}/Enable")] + [Authorize(Policy = Policies.RequiresElevation)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + { + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + { + return NotFound(); + } + + _pluginManager.EnablePlugin(plugin!); + return NoContent(); + } + + /// + /// Disable a plugin. + /// + /// Plugin id. + /// Plugin version. + /// Plugin disabled. + /// Plugin not found. + /// An on success, or a if the file could not be found. + [HttpPost("{pluginId}/Disable")] + [Authorize(Policy = Policies.RequiresElevation)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + { + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + { + return NotFound(); + } + + _pluginManager.DisablePlugin(plugin!); + return NoContent(); } /// /// Uninstalls a plugin. /// /// Plugin id. + /// Plugin version. /// Plugin uninstalled. /// Plugin not found. /// An on success, or a if the file could not be found. @@ -64,15 +180,14 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId) + public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId, Version version) { - var plugin = _appHost.Plugins.FirstOrDefault(p => p.Id == pluginId); - if (plugin == null) + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { return NotFound(); } - _installationManager.UninstallPlugin(plugin); + _installationManager.UninstallPlugin(plugin!); return NoContent(); } @@ -80,20 +195,23 @@ namespace Jellyfin.Api.Controllers /// Gets plugin configuration. /// /// Plugin id. + /// Plugin version. /// Plugin configuration returned. /// Plugin not found or plugin configuration not found. /// Plugin configuration. [HttpGet("{pluginId}/Configuration")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId) + [ProducesFile(MediaTypeNames.Application.Json)] + public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) { - if (!(_appHost.Plugins.FirstOrDefault(p => p.Id == pluginId) is IHasPluginConfiguration plugin)) + if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin) + && plugin!.Instance is IHasPluginConfiguration configPlugin) { - return NotFound(); + return configPlugin.Configuration; } - return plugin.Configuration; + return NotFound(); } /// @@ -103,6 +221,7 @@ namespace Jellyfin.Api.Controllers /// Accepts plugin configuration as JSON body. /// /// Plugin id. + /// Plugin version. /// Plugin configuration updated. /// Plugin not found or plugin does not have configuration. /// @@ -113,92 +232,125 @@ namespace Jellyfin.Api.Controllers [HttpPost("{pluginId}/Configuration")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task UpdatePluginConfiguration([FromRoute, Required] Guid pluginId) + public async Task UpdatePluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) { - if (!(_appHost.Plugins.FirstOrDefault(p => p.Id == pluginId) is IHasPluginConfiguration plugin)) + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin) + || plugin?.Instance is not IHasPluginConfiguration configPlugin) { return NotFound(); } - var configuration = (BasePluginConfiguration?)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType, _serializerOptions) + var configuration = (BasePluginConfiguration?)await JsonSerializer.DeserializeAsync(Request.Body, configPlugin.ConfigurationType, _serializerOptions) .ConfigureAwait(false); if (configuration != null) { - plugin.UpdateConfiguration(configuration); + configPlugin.UpdateConfiguration(configuration); } return NoContent(); } /// - /// Get plugin security info. + /// Gets a plugin's image. /// - /// Plugin security info returned. - /// Plugin security info. - [Obsolete("This endpoint should not be used.")] - [HttpGet("SecurityInfo")] + /// Plugin id. + /// Plugin version. + /// Plugin image returned. + /// Plugin's image. + [HttpGet("{pluginId}/Image")] [ProducesResponseType(StatusCodes.Status200OK)] - public ActionResult GetPluginSecurityInfo() + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesImageFile] + [AllowAnonymous] + public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) { - return new PluginSecurityInfo + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { - IsMbSupporter = true, - SupporterKey = "IAmTotallyLegit" - }; + return NotFound(); + } + + var imgPath = Path.Combine(plugin!.Path, plugin!.Manifest.ImageUrl ?? string.Empty); + if (((ServerConfiguration)_config.CommonConfiguration).DisablePluginImages + || plugin!.Manifest.ImageUrl == null + || !System.IO.File.Exists(imgPath)) + { + // Use a blank image. + var type = GetType(); + var stream = type.Assembly.GetManifestResourceStream(type.Namespace + ".Plugins.blank.png"); + return File(stream, "image/png"); + } + + imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl); + return PhysicalFile(imgPath, MimeTypes.GetMimeType(imgPath)); } /// - /// Updates plugin security info. + /// Gets a plugin's status image. /// - /// Plugin security info. - /// Plugin security info updated. - /// An . - [Obsolete("This endpoint should not be used.")] - [HttpPost("SecurityInfo")] - [Authorize(Policy = Policies.RequiresElevation)] - [ProducesResponseType(StatusCodes.Status204NoContent)] - public ActionResult UpdatePluginSecurityInfo([FromBody, Required] PluginSecurityInfo pluginSecurityInfo) + /// Plugin id. + /// Plugin version. + /// Plugin image returned. + /// Plugin's image. + [HttpGet("{pluginId}/StatusImage")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesImageFile] + [AllowAnonymous] + public ActionResult GetPluginStatusImage([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) { - return NoContent(); + if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + { + return NotFound(); + } + + // Icons from http://www.fatcow.com/free-icons + var status = plugin!.Manifest.Status; + + var type = _pluginManager.GetType(); + var stream = type.Assembly.GetManifestResourceStream($"{type.Namespace}.Plugins.{status}.png"); + return File(stream, "image/png"); } /// - /// Gets registration status for a feature. + /// Gets a plugin's manifest. /// - /// Feature name. - /// Registration status returned. - /// Mb registration record. - [Obsolete("This endpoint should not be used.")] - [HttpPost("RegistrationRecords/{name}")] - [ProducesResponseType(StatusCodes.Status200OK)] - public ActionResult GetRegistrationStatus([FromRoute, Required] string name) + /// Plugin id. + /// Plugin version. + /// Plugin manifest returned. + /// Plugin not found. + /// + /// A that represents the asynchronous operation to get the plugin's manifest. + /// The task result contains an indicating success, or + /// when plugin not found. + /// + [HttpPost("{pluginId}/Manifest")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesFile(MediaTypeNames.Application.Json)] + public ActionResult GetPluginManifest([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) { - return new MBRegistrationRecord + if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { - IsRegistered = true, - RegChecked = true, - TrialVersion = false, - IsValid = true, - RegError = false - }; + return Ok(plugin!.Manifest); + } + + return NotFound(); } /// - /// Gets registration status for a feature. + /// Updates plugin security info. /// - /// Feature name. - /// Not implemented. - /// Not Implemented. - /// This endpoint is not implemented. - [Obsolete("Paid plugins are not supported")] - [HttpGet("Registrations/{name}")] - [ProducesResponseType(StatusCodes.Status501NotImplemented)] - public ActionResult GetRegistration([FromRoute, Required] string name) + /// Plugin security info. + /// Plugin security info updated. + /// An . + [Obsolete("This endpoint should not be used.")] + [HttpPost("SecurityInfo")] + [Authorize(Policy = Policies.RequiresElevation)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult UpdatePluginSecurityInfo([FromBody, Required] PluginSecurityInfo pluginSecurityInfo) { - // TODO Once we have proper apps and plugins and decide to break compatibility with paid plugins, - // delete all these registration endpoints. They are only kept for compatibility. - throw new NotImplementedException(); + return NoContent(); } } } -- cgit v1.2.3 From a246a77ada21466587eb7fe02cc50033ab91c2e3 Mon Sep 17 00:00:00 2001 From: Greenback Date: Mon, 14 Dec 2020 23:08:04 +0000 Subject: Delete plugin working. --- .../Plugins/PluginManager.cs | 51 ++++++++++++++-------- Jellyfin.Api/Controllers/PackageController.cs | 3 -- Jellyfin.Api/Controllers/PluginsController.cs | 32 ++++++-------- MediaBrowser.Model/Plugins/PluginStatus.cs | 3 +- 4 files changed, 48 insertions(+), 41 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 8596dfcf8..1377c80ea 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -78,8 +78,27 @@ namespace Emby.Server.Implementations /// An IEnumerable{Assembly}. public IEnumerable LoadAssemblies() { + // Attempt to remove any deleted plugins and change any successors to be active. + for (int a = _plugins.Count - 1; a >= 0; a--) + { + var plugin = _plugins[a]; + if (plugin.Manifest.Status == PluginStatus.DeleteOnStartup && DeletePlugin(plugin)) + { + UpdateSuccessors(plugin); + } + } + + // Now load the assemblies.. foreach (var plugin in _plugins) { + CheckIfStillSuperceded(plugin); + + if (plugin.IsEnabledAndSupported == false) + { + _logger.LogInformation("Skipping disabled plugin {Version} of {Name} ", plugin.Version, plugin.Name); + continue; + } + foreach (var file in plugin.DllFiles) { try @@ -183,15 +202,13 @@ namespace Emby.Server.Implementations throw new ArgumentNullException(nameof(plugin)); } - plugin.Instance?.OnUninstalling(); - if (DeletePlugin(plugin)) { return true; } // Unable to delete, so disable. - return ChangePluginState(plugin, PluginStatus.Disabled); + return ChangePluginState(plugin, PluginStatus.DeleteOnStartup); } /// @@ -205,11 +222,18 @@ namespace Emby.Server.Implementations { if (version == null) { - // If no version is given, return the largest version number. (This is for backwards compatibility). - plugin = _plugins.Where(p => p.Id.Equals(id)).OrderByDescending(p => p.Version).FirstOrDefault(); + // If no version is given, return the current instance. + var plugins = _plugins.Where(p => p.Id.Equals(id)); + + plugin = plugins.FirstOrDefault(p => p.Instance != null); + if (plugin == null) + { + plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault(); + } } else { + // Match id and version number. plugin = _plugins.FirstOrDefault(p => p.Id.Equals(id) && p.Version.Equals(version)); } @@ -264,7 +288,6 @@ namespace Emby.Server.Implementations var predecessor = _plugins.OrderByDescending(p => p.Version) .FirstOrDefault( p => p.Id.Equals(plugin.Id) - && p.Name.Equals(plugin.Name, StringComparison.OrdinalIgnoreCase) && p.IsEnabledAndSupported && p.Version != plugin.Version); @@ -381,17 +404,6 @@ namespace Emby.Server.Implementations // Find the record for this plugin. var plugin = GetPluginByType(type); - if (plugin != null) - { - CheckIfStillSuperceded(plugin); - - if (plugin.IsEnabledAndSupported == true) - { - _logger.LogInformation("Skipping disabled plugin {Version} of {Name} ", plugin.Version, plugin.Name); - return null; - } - } - try { _logger.LogDebug("Creating instance of {Type}", type); @@ -489,6 +501,7 @@ namespace Emby.Server.Implementations { _logger.LogDebug("Deleting {Path}", plugin.Path); Directory.Delete(plugin.Path, true); + _plugins.Remove(plugin); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) @@ -661,8 +674,8 @@ namespace Emby.Server.Implementations continue; } - // Update the manifest so its not loaded next time. - manifest.Status = PluginStatus.Disabled; + manifest.Status = PluginStatus.DeleteOnStartup; + SaveManifest(manifest, entry.Path); } } diff --git a/Jellyfin.Api/Controllers/PackageController.cs b/Jellyfin.Api/Controllers/PackageController.cs index 622a0fe00..d139159aa 100644 --- a/Jellyfin.Api/Controllers/PackageController.cs +++ b/Jellyfin.Api/Controllers/PackageController.cs @@ -46,7 +46,6 @@ namespace Jellyfin.Api.Controllers /// A containing package information. [HttpGet("Packages/{name}")] [ProducesResponseType(StatusCodes.Status200OK)] - [Produces(JsonDefaults.CamelCaseMediaType)] public async Task> GetPackageInfo( [FromRoute, Required] string name, [FromQuery] Guid? assemblyGuid) @@ -73,7 +72,6 @@ namespace Jellyfin.Api.Controllers /// An containing available packages information. [HttpGet("Packages")] [ProducesResponseType(StatusCodes.Status200OK)] - [Produces(JsonDefaults.CamelCaseMediaType)] public async Task> GetPackages() { IEnumerable packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false); @@ -148,7 +146,6 @@ namespace Jellyfin.Api.Controllers /// An containing the list of package repositories. [HttpGet("Repositories")] [ProducesResponseType(StatusCodes.Status200OK)] - [Produces(JsonDefaults.CamelCaseMediaType)] public ActionResult> GetRepositories() { return _serverConfigurationManager.Configuration.PluginRepositories; diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 3f366dd79..d7a67389d 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -14,7 +14,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Json; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; -using MediaBrowser.Controller.Drawing; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Net; using MediaBrowser.Model.Plugins; @@ -130,7 +129,7 @@ namespace Jellyfin.Api.Controllers /// Plugin enabled. /// Plugin not found. /// An on success, or a if the file could not be found. - [HttpPost("{pluginId}/Enable")] + [HttpPost("{pluginId}/{version}/Enable")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] @@ -153,7 +152,7 @@ namespace Jellyfin.Api.Controllers /// Plugin disabled. /// Plugin not found. /// An on success, or a if the file could not be found. - [HttpPost("{pluginId}/Disable")] + [HttpPost("{pluginId}/{version}/Disable")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] @@ -176,11 +175,11 @@ namespace Jellyfin.Api.Controllers /// Plugin uninstalled. /// Plugin not found. /// An on success, or a if the file could not be found. - [HttpDelete("{pluginId}")] + [HttpDelete("{pluginId}/{version}")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId, Version version) + public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { @@ -195,7 +194,6 @@ namespace Jellyfin.Api.Controllers /// Gets plugin configuration. /// /// Plugin id. - /// Plugin version. /// Plugin configuration returned. /// Plugin not found or plugin configuration not found. /// Plugin configuration. @@ -203,9 +201,9 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesFile(MediaTypeNames.Application.Json)] - public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin) + if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin) && plugin!.Instance is IHasPluginConfiguration configPlugin) { return configPlugin.Configuration; @@ -221,7 +219,6 @@ namespace Jellyfin.Api.Controllers /// Accepts plugin configuration as JSON body. /// /// Plugin id. - /// Plugin version. /// Plugin configuration updated. /// Plugin not found or plugin does not have configuration. /// @@ -232,9 +229,9 @@ namespace Jellyfin.Api.Controllers [HttpPost("{pluginId}/Configuration")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task UpdatePluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public async Task UpdatePluginConfiguration([FromRoute, Required] Guid pluginId) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin) + if (!_pluginManager.TryGetPlugin(pluginId, null, out var plugin) || plugin?.Instance is not IHasPluginConfiguration configPlugin) { return NotFound(); @@ -258,12 +255,12 @@ namespace Jellyfin.Api.Controllers /// Plugin version. /// Plugin image returned. /// Plugin's image. - [HttpGet("{pluginId}/Image")] + [HttpGet("{pluginId}/{version}/Image")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesImageFile] [AllowAnonymous] - public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { @@ -292,12 +289,12 @@ namespace Jellyfin.Api.Controllers /// Plugin version. /// Plugin image returned. /// Plugin's image. - [HttpGet("{pluginId}/StatusImage")] + [HttpGet("{pluginId}/{version}/StatusImage")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesImageFile] [AllowAnonymous] - public ActionResult GetPluginStatusImage([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult GetPluginStatusImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { @@ -316,7 +313,6 @@ namespace Jellyfin.Api.Controllers /// Gets a plugin's manifest. /// /// Plugin id. - /// Plugin version. /// Plugin manifest returned. /// Plugin not found. /// @@ -328,9 +324,9 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesFile(MediaTypeNames.Application.Json)] - public ActionResult GetPluginManifest([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult GetPluginManifest([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin)) { return Ok(plugin!.Manifest); } diff --git a/MediaBrowser.Model/Plugins/PluginStatus.cs b/MediaBrowser.Model/Plugins/PluginStatus.cs index 439968ba8..a953206e8 100644 --- a/MediaBrowser.Model/Plugins/PluginStatus.cs +++ b/MediaBrowser.Model/Plugins/PluginStatus.cs @@ -12,6 +12,7 @@ namespace MediaBrowser.Model.Plugins Disabled = -1, NotSupported = -2, Malfunction = -3, - Superceded = -4 + Superceded = -4, + DeleteOnStartup = -5 } } -- cgit v1.2.3 From 1c6529c9eb195e3cb8c439df8805652090c49a0f Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 07:54:49 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index d7a67389d..3759f9f1c 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -133,7 +133,7 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { -- cgit v1.2.3 From 33385c1b8cbe46b58f19716c85a3da9ec66cd282 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 07:55:14 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 3759f9f1c..afb5dc5ff 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -156,7 +156,7 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute] Version? version) + public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { -- cgit v1.2.3 From 41466c430de6ad8b3aa2599af9e6e41f1f63c785 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 09:17:06 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index afb5dc5ff..36e37b7ad 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -113,7 +113,6 @@ namespace Jellyfin.Api.Controllers /// List of currently installed plugins. [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesFile(MediaTypeNames.Application.Json)] public ActionResult> GetPlugins() { return Ok(_pluginManager.Plugins -- cgit v1.2.3 From dddcfa6dbbca04ed69597ec335007612e2e2b8e8 Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 09:29:51 +0000 Subject: Suggested changes. --- Emby.Server.Implementations/ApplicationHost.cs | 3 +- .../Emby.Server.Implementations.csproj | 7 --- Emby.Server.Implementations/Plugins/Active.png | Bin 1422 -> 0 bytes Emby.Server.Implementations/Plugins/Disabled.png | Bin 1790 -> 0 bytes .../Plugins/Malfunction.png | Bin 2091 -> 0 bytes .../Plugins/NotSupported.png | Bin 2046 -> 0 bytes .../Plugins/PluginManager.cs | 3 -- .../Plugins/RestartRequired.png | Bin 1996 -> 0 bytes Emby.Server.Implementations/Plugins/Superceded.png | Bin 2136 -> 0 bytes Emby.Server.Implementations/Plugins/blank.png | Bin 120 -> 0 bytes Jellyfin.Api/Controllers/PluginsController.cs | 60 +++++++++++---------- 11 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 Emby.Server.Implementations/Plugins/Active.png delete mode 100644 Emby.Server.Implementations/Plugins/Disabled.png delete mode 100644 Emby.Server.Implementations/Plugins/Malfunction.png delete mode 100644 Emby.Server.Implementations/Plugins/NotSupported.png delete mode 100644 Emby.Server.Implementations/Plugins/RestartRequired.png delete mode 100644 Emby.Server.Implementations/Plugins/Superceded.png delete mode 100644 Emby.Server.Implementations/Plugins/blank.png (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 404e28bdc..17cccdaf9 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -393,8 +393,7 @@ namespace Emby.Server.Implementations if (_creatingInstances.IndexOf(type) != -1) { - Logger.LogError("DI Loop detected."); - Logger.LogError("Attempted creation of {Type}", type.FullName); + Logger.LogError("DI Loop detected in the attempted creation of {Type}", type.FullName); foreach (var entry in _creatingInstances) { Logger.LogError("Called from: {stack}", entry.FullName); diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 7e0be7899..0c94f937c 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -73,12 +73,5 @@ - - - - - - - diff --git a/Emby.Server.Implementations/Plugins/Active.png b/Emby.Server.Implementations/Plugins/Active.png deleted file mode 100644 index 3722ee520..000000000 Binary files a/Emby.Server.Implementations/Plugins/Active.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/Disabled.png b/Emby.Server.Implementations/Plugins/Disabled.png deleted file mode 100644 index eeb8ffefc..000000000 Binary files a/Emby.Server.Implementations/Plugins/Disabled.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/Malfunction.png b/Emby.Server.Implementations/Plugins/Malfunction.png deleted file mode 100644 index d4726150e..000000000 Binary files a/Emby.Server.Implementations/Plugins/Malfunction.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/NotSupported.png b/Emby.Server.Implementations/Plugins/NotSupported.png deleted file mode 100644 index a13c1f7c1..000000000 Binary files a/Emby.Server.Implementations/Plugins/NotSupported.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 07b729748..cf25ccf48 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -1,7 +1,6 @@ #nullable enable using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -23,8 +22,6 @@ namespace Emby.Server.Implementations /// public class PluginManager : IPluginManager { - private const int OffsetFromTopRightCorner = 38; - private readonly string _pluginsPath; private readonly Version _appVersion; private readonly JsonSerializerOptions _jsonOptions; diff --git a/Emby.Server.Implementations/Plugins/RestartRequired.png b/Emby.Server.Implementations/Plugins/RestartRequired.png deleted file mode 100644 index 65fd102a2..000000000 Binary files a/Emby.Server.Implementations/Plugins/RestartRequired.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/Superceded.png b/Emby.Server.Implementations/Plugins/Superceded.png deleted file mode 100644 index 251e70535..000000000 Binary files a/Emby.Server.Implementations/Plugins/Superceded.png and /dev/null differ diff --git a/Emby.Server.Implementations/Plugins/blank.png b/Emby.Server.Implementations/Plugins/blank.png deleted file mode 100644 index f81ae3243..000000000 Binary files a/Emby.Server.Implementations/Plugins/blank.png and /dev/null differ diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 36e37b7ad..c84dc6a13 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -167,7 +167,7 @@ namespace Jellyfin.Api.Controllers } /// - /// Uninstalls a plugin. + /// Uninstalls a plugin by version. /// /// Plugin id. /// Plugin version. @@ -178,7 +178,7 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) + public ActionResult UninstallPluginByVersion([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) { @@ -189,6 +189,35 @@ namespace Jellyfin.Api.Controllers return NoContent(); } + /// + /// Uninstalls a plugin. + /// + /// Plugin id. + /// Plugin uninstalled. + /// Plugin not found. + /// An on success, or a if the file could not be found. + [HttpDelete("{pluginId}")] + [Authorize(Policy = Policies.RequiresElevation)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [Obsolete("Please use the UninstallByVersion API.")] + public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId) + { + // If no version is given, return the current instance. + var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId)); + + // Select the un-instanced one first. + var plugin = plugins.FirstOrDefault(p => p.Instance != null); + if (plugin == null) + { + // Then by the status. + plugin = plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault(); + } + + _installationManager.UninstallPlugin(plugin!); + return NoContent(); + } + /// /// Gets plugin configuration. /// @@ -281,33 +310,6 @@ namespace Jellyfin.Api.Controllers return PhysicalFile(imgPath, MimeTypes.GetMimeType(imgPath)); } - /// - /// Gets a plugin's status image. - /// - /// Plugin id. - /// Plugin version. - /// Plugin image returned. - /// Plugin's image. - [HttpGet("{pluginId}/{version}/StatusImage")] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesImageFile] - [AllowAnonymous] - public ActionResult GetPluginStatusImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) - { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) - { - return NotFound(); - } - - // Icons from http://www.fatcow.com/free-icons - var status = plugin!.Manifest.Status; - - var type = _pluginManager.GetType(); - var stream = type.Assembly.GetManifestResourceStream($"{type.Namespace}.Plugins.{status}.png"); - return File(stream, "image/png"); - } - /// /// Gets a plugin's manifest. /// -- cgit v1.2.3 From 208d545cfefd5ce7a2092f4ac669e58cae115d37 Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 10:05:04 +0000 Subject: Changed as suggested. --- .../Plugins/PluginManager.cs | 27 ++++++++++-------- .../Updates/InstallationManager.cs | 3 +- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- MediaBrowser.Common/Json/JsonDefaults.cs | 1 + MediaBrowser.Model/Plugins/PluginStatus.cs | 33 ++++++++++++++++++++-- 5 files changed, 50 insertions(+), 16 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index cf25ccf48..010d2829c 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -53,9 +53,7 @@ namespace Emby.Server.Implementations _logger = loggerfactory.CreateLogger(); _pluginsPath = pluginsPath; _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); - _jsonOptions = JsonDefaults.GetOptions(); - _jsonOptions.PropertyNameCaseInsensitive = true; - _jsonOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + _jsonOptions = JsonDefaults.GetCamelCaseOptions(); _config = config; _appHost = appHost; _imagesPath = imagesPath; @@ -137,7 +135,8 @@ namespace Emby.Server.Implementations var plugin = GetPluginByType(pluginServiceRegistrator.Assembly.GetType()); if (plugin == null) { - throw new NullReferenceException(); + _logger.LogError("Unable to find plugin in assembly {Assembly}", pluginServiceRegistrator.Assembly.FullName); + continue; } CheckIfStillSuperceded(plugin); @@ -440,6 +439,7 @@ namespace Emby.Server.Implementations plugin.Instance = (IPlugin)instance; var manifest = plugin.Manifest; var pluginStr = plugin.Instance.Version.ToString(); + bool changed = false; if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal)) { // If a plugin without a manifest failed to load due to an external issue (eg config), @@ -447,10 +447,16 @@ namespace Emby.Server.Implementations manifest.Version = pluginStr; manifest.Name = plugin.Instance.Name; manifest.Description = plugin.Instance.Description; + changed = true; } + changed = changed || manifest.Status != PluginStatus.Active; manifest.Status = PluginStatus.Active; - SaveManifest(manifest, plugin.Path); + + if (changed) + { + SaveManifest(manifest, plugin.Path); + } } _logger.LogInformation("Loaded plugin: {PluginName} {PluginVersion}", plugin.Name, plugin.Version); @@ -577,8 +583,6 @@ namespace Emby.Server.Implementations } // Auto-create a plugin manifest, so we can disable it, if it fails to load. - // NOTE: This Plugin is marked as valid for two upgrades, at which point, it can be assumed the - // code base will have changed sufficiently to make it invalid. manifest = new PluginManifest { Status = PluginStatus.RestartRequired, @@ -586,7 +590,6 @@ namespace Emby.Server.Implementations AutoUpdate = false, Guid = metafile.GetMD5(), TargetAbi = _appVersion.ToString(), - MaxAbi = _nextVersion.ToString(), Version = version.ToString() }; @@ -678,9 +681,11 @@ namespace Emby.Server.Implementations continue; } - manifest.Status = PluginStatus.DeleteOnStartup; - - SaveManifest(manifest, entry.Path); + if (manifest.Status != PluginStatus.DeleteOnStartup) + { + manifest.Status = PluginStatus.DeleteOnStartup; + SaveManifest(manifest, entry.Path); + } } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 75a9ca080..b7bbbd348 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -93,8 +93,7 @@ namespace Emby.Server.Implementations.Updates _httpClientFactory = httpClientFactory; _config = config; _zipClient = zipClient; - _jsonSerializerOptions = JsonDefaults.GetOptions(); - _jsonSerializerOptions.PropertyNameCaseInsensitive = true; + _jsonSerializerOptions = JsonDefaults.GetCamelCaseOptions(); _pluginManager = pluginManager; } diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index c84dc6a13..eb6b770d6 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -47,7 +47,7 @@ namespace Jellyfin.Api.Controllers { _installationManager = installationManager; _pluginManager = pluginManager; - _serializerOptions = JsonDefaults.GetOptions(); + _serializerOptions = JsonDefaults.GetCamelCaseOptions(); _config = config; } diff --git a/MediaBrowser.Common/Json/JsonDefaults.cs b/MediaBrowser.Common/Json/JsonDefaults.cs index b76edd2bc..50393b909 100644 --- a/MediaBrowser.Common/Json/JsonDefaults.cs +++ b/MediaBrowser.Common/Json/JsonDefaults.cs @@ -56,6 +56,7 @@ namespace MediaBrowser.Common.Json { var options = GetOptions(); options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + options.PropertyNameCaseInsensitive = true; return options; } diff --git a/MediaBrowser.Model/Plugins/PluginStatus.cs b/MediaBrowser.Model/Plugins/PluginStatus.cs index a953206e8..2acc56811 100644 --- a/MediaBrowser.Model/Plugins/PluginStatus.cs +++ b/MediaBrowser.Model/Plugins/PluginStatus.cs @@ -1,5 +1,3 @@ -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable SA1602 // Enumeration items should be documented namespace MediaBrowser.Model.Plugins { /// @@ -7,12 +5,43 @@ namespace MediaBrowser.Model.Plugins /// public enum PluginStatus { + /// + /// This plugin requires a restart in order for it to load. This is a memory only status. + /// The actual status of the plugin after reload is present in the manifest. + /// eg. A disabled plugin will still be active until the next restart, and so will have a memory status of RestartRequired, + /// but a disk manifest status of Disabled. + /// RestartRequired = 1, + + /// + /// This plugin is currently running. + /// Active = 0, + + /// + /// This plugin has been marked as disabled. + /// Disabled = -1, + + /// + /// This plugin does not meet the TargetAbi / MaxAbi requirements. + /// NotSupported = -2, + + /// + /// This plugin caused an error when instantiated. (Either DI loop, or exception) + /// Malfunction = -3, + + /// + /// This plugin has been superceded by another version. + /// Superceded = -4, + + /// + /// An attempt to remove this plugin from disk will happen at every restart. + /// It will not be loaded, if unable to do so. + /// DeleteOnStartup = -5 } } -- cgit v1.2.3 From 3f1ad7f963f4d631861d8b6ac30acd7e4753ccf0 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 19:22:54 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index eb6b770d6..9b731f88a 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -200,7 +200,7 @@ namespace Jellyfin.Api.Controllers [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [Obsolete("Please use the UninstallByVersion API.")] + [Obsolete("Please use the UninstallPluginByVersion API.")] public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId) { // If no version is given, return the current instance. -- cgit v1.2.3 From 2afa963fc134853e86ab30029be3ea22e9c72366 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 19:24:39 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 9b731f88a..1e658890e 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -127,7 +127,7 @@ namespace Jellyfin.Api.Controllers /// Plugin version. /// Plugin enabled. /// Plugin not found. - /// An on success, or a if the file could not be found. + /// An on success, or a if the plugin could not be found. [HttpPost("{pluginId}/{version}/Enable")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] -- cgit v1.2.3 From e4993ae574b0b01304297770e58bb9b86e34ef6e Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 19:24:52 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 1e658890e..9a4d0c40b 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -173,7 +173,7 @@ namespace Jellyfin.Api.Controllers /// Plugin version. /// Plugin uninstalled. /// Plugin not found. - /// An on success, or a if the file could not be found. + /// An on success, or a if the plugin could not be found. [HttpDelete("{pluginId}/{version}")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] -- cgit v1.2.3 From 24ab152e9d340e041dc57cfd6dbd60d6d35f9cc9 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 19:30:23 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 9a4d0c40b..c3c9460e6 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -150,7 +150,7 @@ namespace Jellyfin.Api.Controllers /// Plugin version. /// Plugin disabled. /// Plugin not found. - /// An on success, or a if the file could not be found. + /// An on success, or a if the plugin could not be found. [HttpPost("{pluginId}/{version}/Disable")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] -- cgit v1.2.3 From aecd35d30668595b761e878265bb0ed61826ec50 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 15 Dec 2020 19:31:36 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index c3c9460e6..565bf2311 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -324,7 +324,6 @@ namespace Jellyfin.Api.Controllers [HttpPost("{pluginId}/Manifest")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesFile(MediaTypeNames.Application.Json)] public ActionResult GetPluginManifest([FromRoute, Required] Guid pluginId) { if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin)) -- cgit v1.2.3 From 00ff3b90962ff616629fab675c6e0108d3af58ae Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 19:35:26 +0000 Subject: remove attribute --- Jellyfin.Api/Controllers/PluginsController.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 565bf2311..b5976fbbd 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -228,7 +228,6 @@ namespace Jellyfin.Api.Controllers [HttpGet("{pluginId}/Configuration")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesFile(MediaTypeNames.Application.Json)] public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId) { if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin) -- cgit v1.2.3 From 532388754053957a1b3066900b7b54e1894206f3 Mon Sep 17 00:00:00 2001 From: Greenback Date: Tue, 15 Dec 2020 20:27:42 +0000 Subject: Replaced TryGetPlugin with GetPlugin --- .../Plugins/PluginManager.cs | 13 +++++---- .../Updates/InstallationManager.cs | 5 ++-- Jellyfin.Api/Controllers/PluginsController.cs | 34 +++++++++++++--------- MediaBrowser.Common/Plugins/IPluginManager.cs | 5 ++-- 4 files changed, 32 insertions(+), 25 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 944b74652..26a029f71 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -212,12 +212,13 @@ namespace Emby.Server.Implementations /// /// Attempts to find the plugin with and id of . /// - /// Id of plugin. - /// The version of the plugin to locate. - /// A if found, otherwise null. - /// Boolean value signifying the success of the search. - public bool TryGetPlugin(Guid id, Version? version, out LocalPlugin? plugin) + /// The of plugin. + /// Optional of the plugin to locate. + /// A if located, or null if not. + public LocalPlugin? GetPlugin(Guid id, Version? version = null) { + LocalPlugin? plugin; + if (version == null) { // If no version is given, return the current instance. @@ -235,7 +236,7 @@ namespace Emby.Server.Implementations plugin = _plugins.FirstOrDefault(p => p.Id.Equals(id) && p.Version.Equals(version)); } - return plugin != null; + return plugin; } /// diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index fc80bdd75..7cab77c85 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -197,10 +197,11 @@ namespace Emby.Server.Implementations.Updates { var version = package.Versions[i]; + var plugin = _pluginManager.GetPlugin(packageGuid, version.VersionNumber); // Update the manifests, if anything changes. - if (_pluginManager.TryGetPlugin(packageGuid, version.VersionNumber, out LocalPlugin? plugin)) + if (plugin != null) { - bool noChange = string.Equals(plugin!.Manifest.MaxAbi, version.MaxAbi, StringComparison.Ordinal) + bool noChange = string.Equals(plugin.Manifest.MaxAbi, version.MaxAbi, StringComparison.Ordinal) || string.Equals(plugin.Manifest.TargetAbi, version.TargetAbi, StringComparison.Ordinal); if (!noChange) { diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index b5976fbbd..49ccac137 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -134,12 +134,13 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult EnablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - _pluginManager.EnablePlugin(plugin!); + _pluginManager.EnablePlugin(plugin); return NoContent(); } @@ -157,12 +158,13 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult DisablePlugin([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - _pluginManager.DisablePlugin(plugin!); + _pluginManager.DisablePlugin(plugin); return NoContent(); } @@ -180,7 +182,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult UninstallPluginByVersion([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } @@ -230,8 +233,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult GetPluginConfiguration([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin) - && plugin!.Instance is IHasPluginConfiguration configPlugin) + var plugin = _pluginManager.GetPlugin(pluginId); + if (plugin?.Instance is IHasPluginConfiguration configPlugin) { return configPlugin.Configuration; } @@ -258,8 +261,8 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task UpdatePluginConfiguration([FromRoute, Required] Guid pluginId) { - if (!_pluginManager.TryGetPlugin(pluginId, null, out var plugin) - || plugin?.Instance is not IHasPluginConfiguration configPlugin) + var plugin = _pluginManager.GetPlugin(pluginId); + if (plugin?.Instance is not IHasPluginConfiguration configPlugin) { return NotFound(); } @@ -289,14 +292,15 @@ namespace Jellyfin.Api.Controllers [AllowAnonymous] public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute, Required] Version version) { - if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId, version); + if (plugin == null) { return NotFound(); } - var imgPath = Path.Combine(plugin!.Path, plugin!.Manifest.ImageUrl ?? string.Empty); + var imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl ?? string.Empty); if (((ServerConfiguration)_config.CommonConfiguration).DisablePluginImages - || plugin!.Manifest.ImageUrl == null + || plugin.Manifest.ImageUrl == null || !System.IO.File.Exists(imgPath)) { // Use a blank image. @@ -325,9 +329,11 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status404NotFound)] public ActionResult GetPluginManifest([FromRoute, Required] Guid pluginId) { - if (_pluginManager.TryGetPlugin(pluginId, null, out var plugin)) + var plugin = _pluginManager.GetPlugin(pluginId); + + if (plugin != null) { - return Ok(plugin!.Manifest); + return Ok(plugin.Manifest); } return NotFound(); diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs index 071b51969..7f7381b03 100644 --- a/MediaBrowser.Common/Plugins/IPluginManager.cs +++ b/MediaBrowser.Common/Plugins/IPluginManager.cs @@ -72,9 +72,8 @@ namespace MediaBrowser.Common.Plugins /// /// Id of plugin. /// The version of the plugin to locate. - /// A if found, otherwise null. - /// Boolean value signifying the success of the search. - bool TryGetPlugin(Guid id, Version? version, out LocalPlugin? plugin); + /// A if located, or null if not. + LocalPlugin? GetPlugin(Guid id, Version? version = null); /// /// Removes the plugin. -- cgit v1.2.3 From ebbb57efc3274663b515b4accc52f4a4e9920e77 Mon Sep 17 00:00:00 2001 From: Greenback Date: Wed, 16 Dec 2020 21:40:52 +0000 Subject: Change json default settings. --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 49ccac137..4f65e18e1 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -47,7 +47,7 @@ namespace Jellyfin.Api.Controllers { _installationManager = installationManager; _pluginManager = pluginManager; - _serializerOptions = JsonDefaults.GetCamelCaseOptions(); + _serializerOptions = JsonDefaults.GetOptions(); _config = config; } -- cgit v1.2.3 From 1ed25ebd9a11f3fc1838e347a34621dcde0b7bd5 Mon Sep 17 00:00:00 2001 From: Greenback Date: Wed, 16 Dec 2020 22:36:25 +0000 Subject: Corrections as recommended. --- .../Updates/InstallationManager.cs | 5 ++--- Jellyfin.Api/Controllers/PluginsController.cs | 16 +++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 7cab77c85..70424369b 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -92,7 +92,7 @@ namespace Emby.Server.Implementations.Updates _httpClientFactory = httpClientFactory; _config = config; _zipClient = zipClient; - _jsonSerializerOptions = JsonDefaults.GetCamelCaseOptions(); + _jsonSerializerOptions = JsonDefaults.GetOptions(); _pluginManager = pluginManager; } @@ -104,8 +104,7 @@ namespace Emby.Server.Implementations.Updates { try { - List? packages; - packages = await _httpClientFactory.CreateClient(NamedClient.Default) + List? packages = await _httpClientFactory.CreateClient(NamedClient.Default) .GetFromJsonAsync>(new Uri(manifest), _jsonSerializerOptions, cancellationToken).ConfigureAwait(false); if (packages == null) diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 4f65e18e1..6db74571c 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -217,8 +217,13 @@ namespace Jellyfin.Api.Controllers plugin = plugins.OrderBy(p => p.Manifest.Status).FirstOrDefault(); } - _installationManager.UninstallPlugin(plugin!); - return NoContent(); + if (plugin != null) + { + _installationManager.UninstallPlugin(plugin!); + return NoContent(); + } + + return NotFound(); } /// @@ -303,10 +308,7 @@ namespace Jellyfin.Api.Controllers || plugin.Manifest.ImageUrl == null || !System.IO.File.Exists(imgPath)) { - // Use a blank image. - var type = GetType(); - var stream = type.Assembly.GetManifestResourceStream(type.Namespace + ".Plugins.blank.png"); - return File(stream, "image/png"); + return NotFound(); } imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl); @@ -333,7 +335,7 @@ namespace Jellyfin.Api.Controllers if (plugin != null) { - return Ok(plugin.Manifest); + return plugin.Manifest; } return NotFound(); -- cgit v1.2.3 From e445c2932afe8107846f85e308941d75350be013 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Fri, 18 Dec 2020 08:23:15 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 6db74571c..5a3a3eef9 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -219,7 +219,7 @@ namespace Jellyfin.Api.Controllers if (plugin != null) { - _installationManager.UninstallPlugin(plugin!); + _installationManager.UninstallPlugin(plugin); return NoContent(); } -- cgit v1.2.3 From 5d5b198525bd3a45f6c3f61dda559597e24b7d45 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Fri, 18 Dec 2020 08:23:28 +0000 Subject: Update Jellyfin.Api/Controllers/PluginsController.cs Co-authored-by: Cody Robibero --- Jellyfin.Api/Controllers/PluginsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 5a3a3eef9..1365764fb 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -188,7 +188,7 @@ namespace Jellyfin.Api.Controllers return NotFound(); } - _installationManager.UninstallPlugin(plugin!); + _installationManager.UninstallPlugin(plugin); return NoContent(); } -- cgit v1.2.3 From 5d748c0e9f1ad87bece090934c5da6c4edacb8f7 Mon Sep 17 00:00:00 2001 From: Greenback Date: Fri, 18 Dec 2020 20:52:44 +0000 Subject: Renamed to ImagePath --- Jellyfin.Api/Controllers/PluginsController.cs | 10 +++++----- MediaBrowser.Common/Plugins/LocalPlugin.cs | 2 +- MediaBrowser.Common/Plugins/PluginManifest.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 1365764fb..365bb2248 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -303,16 +303,16 @@ namespace Jellyfin.Api.Controllers return NotFound(); } - var imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl ?? string.Empty); + var imagePath = Path.Combine(plugin.Path, plugin.Manifest.ImagePath ?? string.Empty); if (((ServerConfiguration)_config.CommonConfiguration).DisablePluginImages - || plugin.Manifest.ImageUrl == null - || !System.IO.File.Exists(imgPath)) + || plugin.Manifest.ImagePath == null + || !System.IO.File.Exists(imagePath)) { return NotFound(); } - imgPath = Path.Combine(plugin.Path, plugin.Manifest.ImageUrl); - return PhysicalFile(imgPath, MimeTypes.GetMimeType(imgPath)); + imagePath = Path.Combine(plugin.Path, plugin.Manifest.ImagePath); + return PhysicalFile(imagePath, MimeTypes.GetMimeType(imagePath)); } /// diff --git a/MediaBrowser.Common/Plugins/LocalPlugin.cs b/MediaBrowser.Common/Plugins/LocalPlugin.cs index 40ecb0a67..23b6cfa81 100644 --- a/MediaBrowser.Common/Plugins/LocalPlugin.cs +++ b/MediaBrowser.Common/Plugins/LocalPlugin.cs @@ -110,7 +110,7 @@ namespace MediaBrowser.Common.Plugins { var inst = Instance?.GetPluginInfo() ?? new PluginInfo(Manifest.Name, Version, Manifest.Description, Manifest.Id, true); inst.Status = Manifest.Status; - inst.HasImage = !string.IsNullOrEmpty(Manifest.ImageUrl); + inst.HasImage = !string.IsNullOrEmpty(Manifest.ImagePath); return inst; } diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs index 39ee450a6..755ccafda 100644 --- a/MediaBrowser.Common/Plugins/PluginManifest.cs +++ b/MediaBrowser.Common/Plugins/PluginManifest.cs @@ -80,6 +80,6 @@ namespace MediaBrowser.Common.Plugins /// Gets or sets a value indicating whether this plugin has an image. /// Image must be located in the local plugin folder. /// - public string? ImageUrl { get; set; } + public string? ImagePath { get; set; } } } -- cgit v1.2.3 From 62702fa3eb5070ce8c57dc4e39551bcc4e64fa74 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Wed, 23 Dec 2020 16:28:50 +0000 Subject: Changes as requested --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- .../Plugins/PluginManager.cs | 45 +++++++++++++++------- Jellyfin.Api/Controllers/PluginsController.cs | 16 ++------ Jellyfin.Api/Models/ConfigurationPageInfo.cs | 1 - MediaBrowser.Common/Plugins/BasePluginOfT.cs | 20 +++------- .../Plugins/IHasPluginConfiguration.cs | 6 --- MediaBrowser.Common/Plugins/IPluginManager.cs | 1 + MediaBrowser.Common/Plugins/PluginManifest.cs | 4 +- 8 files changed, 43 insertions(+), 52 deletions(-) (limited to 'Jellyfin.Api/Controllers/PluginsController.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f73cd1ea4..b91ba6b6c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -462,7 +462,7 @@ namespace Emby.Server.Implementations { // Convert to list so this isn't executed for each iteration var parts = GetExportTypes() - .Select(defaultFunc) + .Select(i => defaultFunc(i)) .Where(i => i != null) .Cast() .ToList(); diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 629975abb..c06359757 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Text.Json; +using System.Threading.Tasks; using MediaBrowser.Common; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Json; @@ -86,7 +87,8 @@ namespace Emby.Server.Implementations.Plugins var plugin = _plugins[i]; if (plugin.Manifest.Status == PluginStatus.Deleted && DeletePlugin(plugin)) { - UpdateSuccessors(plugin); + // See if there is another version, and if so make that active. + ProcessAlternative(plugin); } } @@ -208,12 +210,19 @@ namespace Emby.Server.Implementations.Plugins if (DeletePlugin(plugin)) { + ProcessAlternative(plugin); return true; } _logger.LogWarning("Unable to delete {Path}, so marking as deleteOnStartup.", plugin.Path); // Unable to delete, so disable. - return ChangePluginState(plugin, PluginStatus.Deleted); + if (ChangePluginState(plugin, PluginStatus.Deleted)) + { + ProcessAlternative(plugin); + return true; + } + + return false; } /// @@ -232,9 +241,9 @@ namespace Emby.Server.Implementations.Plugins var plugins = _plugins.Where(p => p.Id.Equals(id)).ToList(); plugin = plugins.FirstOrDefault(p => p.Instance != null); - if (plugin == null && plugins.Length > 0) + if (plugin == null) { - plugin = plugins.OrderByDescending(p => p.Version)[0]; + plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault(); } } else @@ -259,7 +268,8 @@ namespace Emby.Server.Implementations.Plugins if (ChangePluginState(plugin, PluginStatus.Active)) { - UpdateSuccessors(plugin); + // See if there is another version, and if so, supercede it. + ProcessAlternative(plugin); } } @@ -277,7 +287,8 @@ namespace Emby.Server.Implementations.Plugins // Update the manifest on disk if (ChangePluginState(plugin, PluginStatus.Disabled)) { - UpdateSuccessors(plugin); + // If there is another version, activate it. + ProcessAlternative(plugin); } } @@ -639,27 +650,33 @@ namespace Emby.Server.Implementations.Plugins /// Changes the status of the other versions of the plugin to "Superceded". /// /// The that's master. - private void UpdateSuccessors(LocalPlugin plugin) + private void ProcessAlternative(LocalPlugin plugin) { - // This value is memory only - so that the web will show restart required. - plugin.Manifest.Status = PluginStatus.Restart; - // Detect whether there is another version of this plugin that needs disabling. - var predecessor = _plugins.OrderByDescending(p => p.Version) + var previousVersion = _plugins.OrderByDescending(p => p.Version) .FirstOrDefault( p => p.Id.Equals(plugin.Id) && p.IsEnabledAndSupported && p.Version != plugin.Version); - if (predecessor == null) + if (previousVersion == null) { + // This value is memory only - so that the web will show restart required. + plugin.Manifest.Status = PluginStatus.Restart; return; } - if (predecessor.Manifest.Status == PluginStatus.Active && !ChangePluginState(predecessor, PluginStatus.Superceded)) + if (plugin.Manifest.Status == PluginStatus.Active && !ChangePluginState(previousVersion, PluginStatus.Superceded)) + { + _logger.LogError("Unable to enable version {Version} of {Name}", previousVersion.Version, previousVersion.Name); + } + else if (plugin.Manifest.Status == PluginStatus.Superceded && !ChangePluginState(previousVersion, PluginStatus.Active)) { - _logger.LogError("Unable to disable version {Version} of {Name}", predecessor.Version, predecessor.Name); + _logger.LogError("Unable to supercede version {Version} of {Name}", previousVersion.Version, previousVersion.Name); } + + // This value is memory only - so that the web will show restart required. + plugin.Manifest.Status = PluginStatus.Restart; } } } diff --git a/Jellyfin.Api/Controllers/PluginsController.cs b/Jellyfin.Api/Controllers/PluginsController.cs index 365bb2248..b73611c97 100644 --- a/Jellyfin.Api/Controllers/PluginsController.cs +++ b/Jellyfin.Api/Controllers/PluginsController.cs @@ -198,7 +198,7 @@ namespace Jellyfin.Api.Controllers /// Plugin id. /// Plugin uninstalled. /// Plugin not found. - /// An on success, or a if the file could not be found. + /// An on success, or a if the plugin could not be found. [HttpDelete("{pluginId}")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] @@ -210,7 +210,7 @@ namespace Jellyfin.Api.Controllers var plugins = _pluginManager.Plugins.Where(p => p.Id.Equals(pluginId)); // Select the un-instanced one first. - var plugin = plugins.FirstOrDefault(p => p.Instance != null); + var plugin = plugins.FirstOrDefault(p => p.Instance == null); if (plugin == null) { // Then by the status. @@ -256,11 +256,7 @@ namespace Jellyfin.Api.Controllers /// Plugin id. /// Plugin configuration updated. /// Plugin not found or plugin does not have configuration. - /// - /// A that represents the asynchronous operation to update plugin configuration. - /// The task result contains an indicating success, or - /// when plugin not found or plugin doesn't have configuration. - /// + /// An on success, or a if the plugin could not be found. [HttpPost("{pluginId}/Configuration")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] @@ -321,11 +317,7 @@ namespace Jellyfin.Api.Controllers /// Plugin id. /// Plugin manifest returned. /// Plugin not found. - /// - /// A that represents the asynchronous operation to get the plugin's manifest. - /// The task result contains an indicating success, or - /// when plugin not found. - /// + /// A on success, or a if the plugin could not be found. [HttpPost("{pluginId}/Manifest")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] diff --git a/Jellyfin.Api/Models/ConfigurationPageInfo.cs b/Jellyfin.Api/Models/ConfigurationPageInfo.cs index c15ed05d3..f56ef5976 100644 --- a/Jellyfin.Api/Models/ConfigurationPageInfo.cs +++ b/Jellyfin.Api/Models/ConfigurationPageInfo.cs @@ -23,7 +23,6 @@ namespace Jellyfin.Api.Models if (page.Plugin != null) { DisplayName = page.Plugin.Name; - // Don't use "N" because it needs to match Plugin.Id PluginId = page.Plugin.Id; } } diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs index ea05a722b..d5c780851 100644 --- a/MediaBrowser.Common/Plugins/BasePluginOfT.cs +++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs @@ -25,8 +25,6 @@ namespace MediaBrowser.Common.Plugins /// private readonly object _configurationSaveLock = new object(); - private Action _directoryCreateFn; - /// /// The configuration. /// @@ -65,11 +63,6 @@ namespace MediaBrowser.Common.Plugins assemblyPlugin.SetId(assemblyId); } } - - if (this is IHasPluginConfiguration hasPluginConfiguration) - { - hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s)); - } } /// @@ -145,13 +138,6 @@ namespace MediaBrowser.Common.Plugins /// The configuration. BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration; - /// - public void SetStartupInfo(Action directoryCreateFn) - { - // hack alert, until the .net core transition is complete - _directoryCreateFn = directoryCreateFn; - } - /// /// Saves the current configuration to the file system. /// @@ -160,7 +146,11 @@ namespace MediaBrowser.Common.Plugins { lock (_configurationSaveLock) { - _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath)); + var folder = Path.GetDirectoryName(ConfigurationFilePath); + if (!Directory.Exists(folder)) + { + Directory.CreateDirectory(folder); + } XmlSerializer.SerializeToFile(config, ConfigurationFilePath); } diff --git a/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs index 42ad85dd3..af9272caa 100644 --- a/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs +++ b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs @@ -23,11 +23,5 @@ namespace MediaBrowser.Common.Plugins /// /// The configuration. void UpdateConfiguration(BasePluginConfiguration configuration); - - /// - /// Sets the startup directory creation function. - /// - /// The directory function used to create the configuration folder. - void SetStartupInfo(Action directoryCreateFn); } } diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs index 7f7381b03..3da34d8bb 100644 --- a/MediaBrowser.Common/Plugins/IPluginManager.cs +++ b/MediaBrowser.Common/Plugins/IPluginManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; namespace MediaBrowser.Common.Plugins diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs index 334c8d908..4c724f694 100644 --- a/MediaBrowser.Common/Plugins/PluginManifest.cs +++ b/MediaBrowser.Common/Plugins/PluginManifest.cs @@ -19,14 +19,12 @@ namespace MediaBrowser.Common.Plugins Category = string.Empty; Changelog = string.Empty; Description = string.Empty; - Status = PluginStatus.Active; Id = Guid.Empty; Name = string.Empty; Owner = string.Empty; Overview = string.Empty; TargetAbi = string.Empty; Version = string.Empty; - AutoUpdate = true; } /// @@ -99,7 +97,7 @@ namespace MediaBrowser.Common.Plugins /// Gets or sets a value indicating whether this plugin should automatically update. /// [JsonPropertyName("autoUpdate")] - public bool AutoUpdate { get; set; } + public bool AutoUpdate { get; set; } = true; // DO NOT MOVE THIS INTO THE CONSTRUCTOR. /// /// Gets or sets the ImagePath -- cgit v1.2.3