2020-06-19 07:49:42 -07:00
|
|
|
|
using System;
|
2020-06-09 08:57:01 -07:00
|
|
|
|
using System.Collections.Generic;
|
2020-06-19 07:49:42 -07:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-06-09 08:57:01 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Jellyfin.Api.Constants;
|
|
|
|
|
using Jellyfin.Api.Models.PluginDtos;
|
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
|
using MediaBrowser.Common.Updates;
|
|
|
|
|
using MediaBrowser.Model.Plugins;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-20 17:02:07 -07:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2020-06-09 08:57:01 -07:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Plugins controller.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class PluginsController : BaseJellyfinApiController
|
|
|
|
|
{
|
|
|
|
|
private readonly IApplicationHost _appHost;
|
|
|
|
|
private readonly IInstallationManager _installationManager;
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
public PluginsController(
|
|
|
|
|
IApplicationHost appHost,
|
|
|
|
|
IInstallationManager installationManager)
|
|
|
|
|
{
|
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_installationManager = installationManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a list of currently installed plugins.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isAppStoreEnabled">Optional. Unused.</param>
|
|
|
|
|
/// <response code="200">Installed plugins returned.</response>
|
|
|
|
|
/// <returns>List of currently installed plugins.</returns>
|
|
|
|
|
[HttpGet]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-06-19 07:49:42 -07:00
|
|
|
|
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isAppStoreEnabled", Justification = "Imported from ServiceStack")]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult<IEnumerable<PluginInfo>> GetPlugins([FromRoute] bool? isAppStoreEnabled)
|
|
|
|
|
{
|
|
|
|
|
return Ok(_appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Uninstalls a plugin.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pluginId">Plugin id.</param>
|
2020-06-20 17:02:07 -07:00
|
|
|
|
/// <response code="204">Plugin uninstalled.</response>
|
2020-06-09 08:57:01 -07:00
|
|
|
|
/// <response code="404">Plugin not found.</response>
|
2020-06-21 08:33:40 -07:00
|
|
|
|
/// <returns>An <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the file could not be found.</returns>
|
2020-06-09 08:57:01 -07:00
|
|
|
|
[HttpDelete("{pluginId}")]
|
|
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult UninstallPlugin([FromRoute] Guid pluginId)
|
|
|
|
|
{
|
|
|
|
|
var plugin = _appHost.Plugins.FirstOrDefault(p => p.Id == pluginId);
|
|
|
|
|
if (plugin == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_installationManager.UninstallPlugin(plugin);
|
2020-06-20 17:02:07 -07:00
|
|
|
|
return NoContent();
|
2020-06-09 08:57:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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")]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult<BasePluginConfiguration> GetPluginConfiguration([FromRoute] 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>
|
2020-06-20 17:02:07 -07:00
|
|
|
|
/// <response code="204">Plugin configuration updated.</response>
|
|
|
|
|
/// <response code="404">Plugin not found or plugin does not have configuration.</response>
|
2020-06-09 08:57:01 -07:00
|
|
|
|
/// <returns>
|
|
|
|
|
/// A <see cref="Task" /> that represents the asynchronous operation to update plugin configuration.
|
2020-06-21 08:33:52 -07:00
|
|
|
|
/// The task result contains an <see cref="NoContentResult"/> indicating success, or <see cref="NotFoundResult"/>
|
2020-06-09 08:57:01 -07:00
|
|
|
|
/// when plugin not found or plugin doesn't have configuration.
|
|
|
|
|
/// </returns>
|
|
|
|
|
[HttpPost("{pluginId}/Configuration")]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public async Task<ActionResult> UpdatePluginConfiguration([FromRoute] 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)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
plugin.UpdateConfiguration(configuration);
|
2020-06-20 17:02:07 -07:00
|
|
|
|
return NoContent();
|
2020-06-09 08:57:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get plugin security info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <response code="200">Plugin security info returned.</response>
|
|
|
|
|
/// <returns>Plugin security info.</returns>
|
|
|
|
|
[Obsolete("This endpoint should not be used.")]
|
|
|
|
|
[HttpGet("SecurityInfo")]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult<PluginSecurityInfo> GetPluginSecurityInfo()
|
|
|
|
|
{
|
|
|
|
|
return new PluginSecurityInfo
|
|
|
|
|
{
|
|
|
|
|
IsMbSupporter = true,
|
|
|
|
|
SupporterKey = "IAmTotallyLegit"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates plugin security info.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pluginSecurityInfo">Plugin security info.</param>
|
2020-06-20 17:02:07 -07:00
|
|
|
|
/// <response code="204">Plugin security info updated.</response>
|
|
|
|
|
/// <returns>An <see cref="NoContentResult"/>.</returns>
|
2020-06-09 08:57:01 -07:00
|
|
|
|
[Obsolete("This endpoint should not be used.")]
|
|
|
|
|
[HttpPost("SecurityInfo")]
|
|
|
|
|
[Authorize(Policy = Policies.RequiresElevation)]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult UpdatePluginSecurityInfo([FromBody, BindRequired] PluginSecurityInfo pluginSecurityInfo)
|
|
|
|
|
{
|
2020-06-20 17:02:07 -07:00
|
|
|
|
return NoContent();
|
2020-06-09 08:57:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets registration status for a feature.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Feature name.</param>
|
|
|
|
|
/// <response code="200">Registration status returned.</response>
|
|
|
|
|
/// <returns>Mb registration record.</returns>
|
|
|
|
|
[Obsolete("This endpoint should not be used.")]
|
|
|
|
|
[HttpPost("RegistrationRecords/{name}")]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult<MBRegistrationRecord> GetRegistrationStatus([FromRoute] string name)
|
|
|
|
|
{
|
|
|
|
|
return new MBRegistrationRecord
|
|
|
|
|
{
|
|
|
|
|
IsRegistered = true,
|
|
|
|
|
RegChecked = true,
|
|
|
|
|
TrialVersion = false,
|
|
|
|
|
IsValid = true,
|
|
|
|
|
RegError = false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets registration status for a feature.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">Feature name.</param>
|
|
|
|
|
/// <response code="501">Not implemented.</response>
|
|
|
|
|
/// <returns>Not Implemented.</returns>
|
|
|
|
|
/// <exception cref="NotImplementedException">This endpoint is not implemented.</exception>
|
|
|
|
|
[Obsolete("Paid plugins are not supported")]
|
|
|
|
|
[HttpGet("/Registrations/{name}")]
|
2020-06-20 17:02:07 -07:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
|
2020-06-09 08:57:01 -07:00
|
|
|
|
public ActionResult GetRegistration([FromRoute] 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|