2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2019-01-13 19:24:58 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
using MediaBrowser.Common.Plugins;
|
2013-07-01 02:27:50 +00:00
|
|
|
using MediaBrowser.Common.Updates;
|
2019-11-17 22:05:39 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-07-02 18:34:08 +00:00
|
|
|
using MediaBrowser.Controller.Net;
|
2013-02-21 01:33:05 +00:00
|
|
|
using MediaBrowser.Model.Plugins;
|
2013-02-24 21:53:54 +00:00
|
|
|
using MediaBrowser.Model.Serialization;
|
2016-10-25 19:02:04 +00:00
|
|
|
using MediaBrowser.Model.Services;
|
2019-11-17 22:05:39 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Class Plugins
|
|
|
|
/// </summary>
|
2014-03-23 20:07:02 +00:00
|
|
|
[Route("/Plugins", "GET", Summary = "Gets a list of currently installed plugins")]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated]
|
2017-08-19 19:43:35 +00:00
|
|
|
public class GetPlugins : IReturn<PluginInfo[]>
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2015-05-16 19:09:02 +00:00
|
|
|
public bool? IsAppStoreEnabled { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class UninstallPlugin
|
|
|
|
/// </summary>
|
2014-03-23 20:07:02 +00:00
|
|
|
[Route("/Plugins/{Id}", "DELETE", Summary = "Uninstalls a plugin")]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated(Roles = "Admin")]
|
2013-02-21 01:33:05 +00:00
|
|
|
public class UninstallPlugin : IReturnVoid
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 19:14:09 +00:00
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2015-05-29 23:51:33 +00:00
|
|
|
public string Id { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class GetPluginConfiguration
|
|
|
|
/// </summary>
|
2014-03-23 20:07:02 +00:00
|
|
|
[Route("/Plugins/{Id}/Configuration", "GET", Summary = "Gets a plugin's configuration")]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated]
|
2013-02-21 01:33:05 +00:00
|
|
|
public class GetPluginConfiguration
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 19:14:09 +00:00
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2015-05-29 23:51:33 +00:00
|
|
|
public string Id { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class UpdatePluginConfiguration
|
|
|
|
/// </summary>
|
2014-03-23 20:07:02 +00:00
|
|
|
[Route("/Plugins/{Id}/Configuration", "POST", Summary = "Updates a plugin's configuration")]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated]
|
2013-02-21 01:33:05 +00:00
|
|
|
public class UpdatePluginConfiguration : IRequiresRequestStream, IReturnVoid
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 19:14:09 +00:00
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2015-05-29 23:51:33 +00:00
|
|
|
public string Id { get; set; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The raw Http Request Input Stream
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The request stream.</value>
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
}
|
|
|
|
|
2019-01-05 07:02:39 +00:00
|
|
|
//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.
|
2019-01-04 23:25:34 +00:00
|
|
|
[Route("/Registrations/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
|
|
|
|
[Authenticated]
|
|
|
|
public class GetRegistration : IReturn<RegistrationInfo>
|
|
|
|
{
|
|
|
|
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
public string Name { get; set; }
|
|
|
|
}
|
2019-01-05 07:18:44 +00:00
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Class GetPluginSecurityInfo
|
|
|
|
/// </summary>
|
2017-09-11 19:25:13 +00:00
|
|
|
[Route("/Plugins/SecurityInfo", "GET", Summary = "Gets plugin registration information", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated]
|
2013-02-21 01:33:05 +00:00
|
|
|
public class GetPluginSecurityInfo : IReturn<PluginSecurityInfo>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Class UpdatePluginSecurityInfo
|
|
|
|
/// </summary>
|
2017-09-11 19:25:13 +00:00
|
|
|
[Route("/Plugins/SecurityInfo", "POST", Summary = "Updates plugin registration information", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated(Roles = "Admin")]
|
2013-03-05 02:05:59 +00:00
|
|
|
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-11 19:25:13 +00:00
|
|
|
[Route("/Plugins/RegistrationRecords/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
|
2014-11-15 02:31:03 +00:00
|
|
|
[Authenticated]
|
2013-04-08 00:26:31 +00:00
|
|
|
public class GetRegistrationStatus
|
|
|
|
{
|
|
|
|
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
public string Name { get; set; }
|
|
|
|
}
|
2014-11-15 02:31:03 +00:00
|
|
|
|
2019-01-05 07:02:39 +00:00
|
|
|
// TODO these two classes are only kept for compability with paid plugins and should be removed
|
2018-09-12 17:26:21 +00:00
|
|
|
public class RegistrationInfo
|
|
|
|
{
|
|
|
|
public string Name { get; set; }
|
|
|
|
public DateTime ExpirationDate { get; set; }
|
|
|
|
public bool IsTrial { get; set; }
|
|
|
|
public bool IsRegistered { get; set; }
|
|
|
|
}
|
|
|
|
|
2019-01-05 07:02:39 +00:00
|
|
|
public class MBRegistrationRecord
|
2015-10-16 14:29:02 +00:00
|
|
|
{
|
2019-01-05 07:02:39 +00:00
|
|
|
public DateTime ExpirationDate { get; set; }
|
|
|
|
public bool IsRegistered { get; set; }
|
|
|
|
public bool RegChecked { get; set; }
|
|
|
|
public bool RegError { get; set; }
|
|
|
|
public bool TrialVersion { get; set; }
|
|
|
|
public bool IsValid { get; set; }
|
2015-10-16 14:29:02 +00:00
|
|
|
}
|
|
|
|
|
2019-01-05 07:02:39 +00:00
|
|
|
public class PluginSecurityInfo
|
|
|
|
{
|
|
|
|
public string SupporterKey { get; set; }
|
|
|
|
public bool IsMBSupporter { get; set; }
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Class PluginsService
|
|
|
|
/// </summary>
|
2013-03-16 05:52:33 +00:00
|
|
|
public class PluginService : BaseApiService
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2013-02-24 21:53:54 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The _json serializer
|
|
|
|
/// </summary>
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
2013-03-03 02:47:04 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The _app host
|
|
|
|
/// </summary>
|
|
|
|
private readonly IApplicationHost _appHost;
|
2013-03-05 04:25:27 +00:00
|
|
|
private readonly IInstallationManager _installationManager;
|
|
|
|
|
2019-11-17 22:05:39 +00:00
|
|
|
public PluginService(
|
|
|
|
ILogger<PluginService> logger,
|
|
|
|
IServerConfigurationManager serverConfigurationManager,
|
|
|
|
IHttpResultFactory httpResultFactory,
|
|
|
|
IJsonSerializer jsonSerializer,
|
2019-01-25 22:05:01 +00:00
|
|
|
IApplicationHost appHost,
|
2019-11-17 22:05:39 +00:00
|
|
|
IInstallationManager installationManager)
|
|
|
|
: base(logger, serverConfigurationManager, httpResultFactory)
|
2013-02-24 21:53:54 +00:00
|
|
|
{
|
2013-03-03 02:47:04 +00:00
|
|
|
_appHost = appHost;
|
2013-03-05 04:25:27 +00:00
|
|
|
_installationManager = installationManager;
|
2013-02-24 21:53:54 +00:00
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
}
|
|
|
|
|
2013-04-08 00:26:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
2019-01-25 22:05:01 +00:00
|
|
|
public object Get(GetRegistrationStatus request)
|
2013-04-08 00:26:31 +00:00
|
|
|
{
|
2019-01-05 07:02:39 +00:00
|
|
|
var record = new MBRegistrationRecord
|
|
|
|
{
|
|
|
|
IsRegistered = true,
|
|
|
|
RegChecked = true,
|
|
|
|
TrialVersion = false,
|
|
|
|
IsValid = true,
|
|
|
|
RegError = false
|
|
|
|
};
|
2013-04-08 00:26:31 +00:00
|
|
|
|
2019-01-05 07:02:39 +00:00
|
|
|
return ToOptimizedResult(record);
|
2013-04-08 00:26:31 +00:00
|
|
|
}
|
2014-11-15 02:31:03 +00:00
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
2019-01-25 22:05:01 +00:00
|
|
|
public object Get(GetPlugins request)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2017-08-19 19:43:35 +00:00
|
|
|
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToArray();
|
2018-09-12 17:26:21 +00:00
|
|
|
return ToOptimizedResult(result);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
public object Get(GetPluginConfiguration request)
|
|
|
|
{
|
2015-05-29 23:51:33 +00:00
|
|
|
var guid = new Guid(request.Id);
|
2018-09-12 17:26:21 +00:00
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid) as IHasPluginConfiguration;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2016-01-20 19:54:06 +00:00
|
|
|
return ToOptimizedResult(plugin.Configuration);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
2019-01-25 22:05:01 +00:00
|
|
|
public object Get(GetPluginSecurityInfo request)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
var result = new PluginSecurityInfo
|
|
|
|
{
|
2019-01-05 07:02:39 +00:00
|
|
|
IsMBSupporter = true,
|
|
|
|
SupporterKey = "IAmTotallyLegit"
|
2013-02-21 01:33:05 +00:00
|
|
|
};
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
return ToOptimizedResult(result);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Posts the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
2018-09-12 17:26:21 +00:00
|
|
|
public Task Post(UpdatePluginSecurityInfo request)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
2019-01-05 07:02:39 +00:00
|
|
|
return Task.CompletedTask;
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Posts the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
2018-09-12 17:26:21 +00:00
|
|
|
public async Task Post(UpdatePluginConfiguration request)
|
2013-02-21 01:33:05 +00:00
|
|
|
{
|
|
|
|
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
|
|
|
|
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
|
2019-11-17 22:05:39 +00:00
|
|
|
var id = Guid.Parse(GetPathValue(1));
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2020-04-05 16:07:43 +00:00
|
|
|
if (!(_appHost.Plugins.First(p => p.Id == id) is IHasPluginConfiguration plugin))
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
throw new FileNotFoundException();
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
var configuration = (await _jsonSerializer.DeserializeFromStreamAsync(request.RequestStream, plugin.ConfigurationType).ConfigureAwait(false)) as BasePluginConfiguration;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
plugin.UpdateConfiguration(configuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
public void Delete(UninstallPlugin request)
|
|
|
|
{
|
2015-05-29 23:51:33 +00:00
|
|
|
var guid = new Guid(request.Id);
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
2013-03-05 04:25:27 +00:00
|
|
|
_installationManager.UninstallPlugin(plugin);
|
2013-02-21 01:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|