mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-16 05:53:03 +03:00
Initial upload
This commit is contained in:
@@ -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,112 +30,26 @@ 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;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginsController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="appHost">Instance of the <see cref="IApplicationHost"/> interface.</param>
|
||||
/// <param name="installationManager">Instance of the <see cref="IInstallationManager"/> interface.</param>
|
||||
/// <param name="pluginManager">Instance of the <see cref="IPluginManager"/> interface.</param>
|
||||
/// <param name="config">Instance of the <see cref="IConfigurationManager"/> interface.</param>
|
||||
public PluginsController(
|
||||
IApplicationHost appHost,
|
||||
IInstallationManager installationManager)
|
||||
IInstallationManager installationManager,
|
||||
IPluginManager pluginManager,
|
||||
IConfigurationManager config)
|
||||
{
|
||||
_appHost = appHost;
|
||||
_installationManager = installationManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of currently installed plugins.
|
||||
/// </summary>
|
||||
/// <response code="200">Installed plugins returned.</response>
|
||||
/// <returns>List of currently installed plugins.</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public ActionResult<IEnumerable<PluginInfo>> GetPlugins()
|
||||
{
|
||||
return Ok(_appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uninstalls a plugin.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <response code="204">Plugin uninstalled.</response>
|
||||
/// <response code="404">Plugin not found.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
|
||||
[HttpDelete("{pluginId}")]
|
||||
[Authorize(Policy = Policies.RequiresElevation)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId)
|
||||
{
|
||||
var plugin = _appHost.Plugins.FirstOrDefault(p => p.Id == pluginId);
|
||||
if (plugin == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_installationManager.UninstallPlugin(plugin);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets plugin configuration.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <response code="200">Plugin configuration returned.</response>
|
||||
/// <response code="404">Plugin not found or plugin configuration not found.</response>
|
||||
/// <returns>Plugin configuration.</returns>
|
||||
[HttpGet("{pluginId}/Configuration")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult<BasePluginConfiguration> GetPluginConfiguration([FromRoute, Required] Guid pluginId)
|
||||
{
|
||||
if (!(_appHost.Plugins.FirstOrDefault(p => p.Id == pluginId) is IHasPluginConfiguration plugin))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return plugin.Configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates plugin configuration.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts plugin configuration as JSON body.
|
||||
/// </remarks>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <response code="204">Plugin configuration updated.</response>
|
||||
/// <response code="404">Plugin not found or plugin does not have configuration.</response>
|
||||
/// <returns>
|
||||
/// A <see cref="Task" /> that represents the asynchronous operation to update plugin configuration.
|
||||
/// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
|
||||
/// when plugin not found or plugin doesn't have configuration.
|
||||
/// </returns>
|
||||
[HttpPost("{pluginId}/Configuration")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> UpdatePluginConfiguration([FromRoute, Required] Guid pluginId)
|
||||
{
|
||||
if (!(_appHost.Plugins.FirstOrDefault(p => p.Id == pluginId) is IHasPluginConfiguration plugin))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var configuration = (BasePluginConfiguration?)await JsonSerializer.DeserializeAsync(Request.Body, plugin.ConfigurationType, _serializerOptions)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (configuration != null)
|
||||
{
|
||||
plugin.UpdateConfiguration(configuration);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
_pluginManager = pluginManager;
|
||||
_serializerOptions = JsonDefaults.GetOptions();
|
||||
_config = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,7 +60,7 @@ namespace Jellyfin.Api.Controllers
|
||||
[Obsolete("This endpoint should not be used.")]
|
||||
[HttpGet("SecurityInfo")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public ActionResult<PluginSecurityInfo> GetPluginSecurityInfo()
|
||||
public static ActionResult<PluginSecurityInfo> GetPluginSecurityInfo()
|
||||
{
|
||||
return new PluginSecurityInfo
|
||||
{
|
||||
@@ -148,21 +69,6 @@ namespace Jellyfin.Api.Controllers
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates plugin security info.
|
||||
/// </summary>
|
||||
/// <param name="pluginSecurityInfo">Plugin security info.</param>
|
||||
/// <response code="204">Plugin security info updated.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/>.</returns>
|
||||
[Obsolete("This endpoint should not be used.")]
|
||||
[HttpPost("SecurityInfo")]
|
||||
[Authorize(Policy = Policies.RequiresElevation)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public ActionResult UpdatePluginSecurityInfo([FromBody, Required] PluginSecurityInfo pluginSecurityInfo)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets registration status for a feature.
|
||||
/// </summary>
|
||||
@@ -172,7 +78,7 @@ namespace Jellyfin.Api.Controllers
|
||||
[Obsolete("This endpoint should not be used.")]
|
||||
[HttpPost("RegistrationRecords/{name}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public ActionResult<MBRegistrationRecord> GetRegistrationStatus([FromRoute, Required] string name)
|
||||
public static ActionResult<MBRegistrationRecord> GetRegistrationStatus([FromRoute, Required] string name)
|
||||
{
|
||||
return new MBRegistrationRecord
|
||||
{
|
||||
@@ -194,11 +100,257 @@ namespace Jellyfin.Api.Controllers
|
||||
[Obsolete("Paid plugins are not supported")]
|
||||
[HttpGet("Registrations/{name}")]
|
||||
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
|
||||
public ActionResult GetRegistration([FromRoute, Required] string name)
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of currently installed plugins.
|
||||
/// </summary>
|
||||
/// <response code="200">Installed plugins returned.</response>
|
||||
/// <returns>List of currently installed plugins.</returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesFile(MediaTypeNames.Application.Json)]
|
||||
public ActionResult<IEnumerable<PluginInfo>> GetPlugins()
|
||||
{
|
||||
return Ok(_pluginManager.Plugins
|
||||
.OrderBy(p => p.Name)
|
||||
.Select(p => p.GetPluginInfo()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables a disabled plugin.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="204">Plugin enabled.</response>
|
||||
/// <response code="404">Plugin not found.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable a plugin.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="204">Plugin disabled.</response>
|
||||
/// <response code="404">Plugin not found.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
|
||||
[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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uninstalls a plugin.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="204">Plugin uninstalled.</response>
|
||||
/// <response code="404">Plugin not found.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
|
||||
[HttpDelete("{pluginId}")]
|
||||
[Authorize(Policy = Policies.RequiresElevation)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult UninstallPlugin([FromRoute, Required] Guid pluginId, Version version)
|
||||
{
|
||||
if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_installationManager.UninstallPlugin(plugin!);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets plugin configuration.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="200">Plugin configuration returned.</response>
|
||||
/// <response code="404">Plugin not found or plugin configuration not found.</response>
|
||||
/// <returns>Plugin configuration.</returns>
|
||||
[HttpGet("{pluginId}/Configuration")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesFile(MediaTypeNames.Application.Json)]
|
||||
public ActionResult<BasePluginConfiguration> GetPluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version)
|
||||
{
|
||||
if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin)
|
||||
&& plugin!.Instance is IHasPluginConfiguration configPlugin)
|
||||
{
|
||||
return configPlugin.Configuration;
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates plugin configuration.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Accepts plugin configuration as JSON body.
|
||||
/// </remarks>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="204">Plugin configuration updated.</response>
|
||||
/// <response code="404">Plugin not found or plugin does not have configuration.</response>
|
||||
/// <returns>
|
||||
/// A <see cref="Task" /> that represents the asynchronous operation to update plugin configuration.
|
||||
/// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
|
||||
/// when plugin not found or plugin doesn't have configuration.
|
||||
/// </returns>
|
||||
[HttpPost("{pluginId}/Configuration")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> UpdatePluginConfiguration([FromRoute, Required] Guid pluginId, [FromRoute] Version? version)
|
||||
{
|
||||
if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin)
|
||||
|| plugin?.Instance is not IHasPluginConfiguration configPlugin)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var configuration = (BasePluginConfiguration?)await JsonSerializer.DeserializeAsync(Request.Body, configPlugin.ConfigurationType, _serializerOptions)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (configuration != null)
|
||||
{
|
||||
configPlugin.UpdateConfiguration(configuration);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a plugin's image.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="200">Plugin image returned.</response>
|
||||
/// <returns>Plugin's image.</returns>
|
||||
[HttpGet("{pluginId}/Image")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesImageFile]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPluginImage([FromRoute, Required] Guid pluginId, [FromRoute] Version? version)
|
||||
{
|
||||
if (!_pluginManager.TryGetPlugin(pluginId, version, out var plugin))
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a plugin's status image.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="200">Plugin image returned.</response>
|
||||
/// <returns>Plugin's image.</returns>
|
||||
[HttpGet("{pluginId}/StatusImage")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesImageFile]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPluginStatusImage([FromRoute, Required] Guid pluginId, [FromRoute] 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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a plugin's manifest.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Plugin id.</param>
|
||||
/// <param name="version">Plugin version.</param>
|
||||
/// <response code="204">Plugin manifest returned.</response>
|
||||
/// <response code="404">Plugin not found.</response>
|
||||
/// <returns>
|
||||
/// A <see cref="Task" /> that represents the asynchronous operation to get the plugin's manifest.
|
||||
/// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
|
||||
/// when plugin not found.
|
||||
/// </returns>
|
||||
[HttpPost("{pluginId}/Manifest")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesFile(MediaTypeNames.Application.Json)]
|
||||
public ActionResult<PluginManifest> GetPluginManifest([FromRoute, Required] Guid pluginId, [FromRoute] Version? version)
|
||||
{
|
||||
if (_pluginManager.TryGetPlugin(pluginId, version, out var plugin))
|
||||
{
|
||||
return Ok(plugin!.Manifest);
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates plugin security info.
|
||||
/// </summary>
|
||||
/// <param name="pluginSecurityInfo">Plugin security info.</param>
|
||||
/// <response code="204">Plugin security info updated.</response>
|
||||
/// <returns>An <see cref="NoContentResult"/>.</returns>
|
||||
[Obsolete("This endpoint should not be used.")]
|
||||
[HttpPost("SecurityInfo")]
|
||||
[Authorize(Policy = Policies.RequiresElevation)]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public ActionResult UpdatePluginSecurityInfo([FromBody, Required] PluginSecurityInfo pluginSecurityInfo)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user