2015-02-01 13:05:39 -07:00
|
|
|
|
using MediaBrowser.Common;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-06-30 19:27:50 -07:00
|
|
|
|
using MediaBrowser.Common.Updates;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
2014-07-02 11:34:08 -07:00
|
|
|
|
using MediaBrowser.Controller.Net;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.Plugins;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2015-01-09 22:53:35 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Model.Services;
|
2018-09-12 10:26:21 -07:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
2018-12-20 05:11:26 -07:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Plugins
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins", "GET", Summary = "Gets a list of currently installed plugins")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2017-08-19 12:43:35 -07:00
|
|
|
|
public class GetPlugins : IReturn<PluginInfo[]>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2015-05-16 12:09:02 -07:00
|
|
|
|
public bool? IsAppStoreEnabled { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UninstallPlugin
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}", "DELETE", Summary = "Uninstalls a plugin")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated(Roles = "Admin")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class UninstallPlugin : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetPluginConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}/Configuration", "GET", Summary = "Gets a plugin's configuration")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetPluginConfiguration
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdatePluginConfiguration
|
|
|
|
|
/// </summary>
|
2014-03-23 13:07:02 -07:00
|
|
|
|
[Route("/Plugins/{Id}/Configuration", "POST", Summary = "Updates a plugin's configuration")]
|
2014-11-14 19:31:03 -07:00
|
|
|
|
[Authenticated]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class UpdatePluginConfiguration : IRequiresRequestStream, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 12:14:09 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Plugin Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2015-05-29 16:51:33 -07:00
|
|
|
|
public string Id { get; set; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The raw Http Request Input Stream
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The request stream.</value>
|
|
|
|
|
public Stream RequestStream { get; set; }
|
|
|
|
|
}
|
2019-01-04 16:29:00 -07:00
|
|
|
|
|
2019-01-05 00:02:39 -07: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 16:25:34 -07: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 00:02:39 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetPluginSecurityInfo
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Plugins/SecurityInfo", "GET", Summary = "Gets plugin registration information", IsHidden = true)]
|
|
|
|
|
[Authenticated]
|
|
|
|
|
public class GetPluginSecurityInfo : IReturn<PluginSecurityInfo>
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdatePluginSecurityInfo
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Plugins/SecurityInfo", "POST", Summary = "Updates plugin registration information", IsHidden = true)]
|
|
|
|
|
[Authenticated(Roles = "Admin")]
|
|
|
|
|
public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Plugins/RegistrationRecords/{Name}", "GET", Summary = "Gets registration status for a feature", IsHidden = true)]
|
|
|
|
|
[Authenticated]
|
|
|
|
|
public class GetRegistrationStatus
|
|
|
|
|
{
|
|
|
|
|
[ApiMember(Name = "Name", Description = "Feature Name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO these two classes are only kept for compability with paid plugins and should be removed
|
2019-01-04 16:25:34 -07: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 00:02:39 -07:00
|
|
|
|
public class MBRegistrationRecord
|
|
|
|
|
{
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PluginSecurityInfo
|
|
|
|
|
{
|
|
|
|
|
public string SupporterKey { get; set; }
|
|
|
|
|
public bool IsMBSupporter { get; set; }
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class PluginsService
|
|
|
|
|
/// </summary>
|
2013-03-15 22:52:33 -07:00
|
|
|
|
public class PluginService : BaseApiService
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
2013-03-02 19:47:04 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _app host
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IApplicationHost _appHost;
|
2013-03-04 21:25:27 -07:00
|
|
|
|
private readonly IInstallationManager _installationManager;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
private readonly INetworkManager _network;
|
|
|
|
|
private readonly IDeviceManager _deviceManager;
|
2013-03-04 21:25:27 -07:00
|
|
|
|
|
2019-01-04 14:42:56 -07:00
|
|
|
|
public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost, IInstallationManager installationManager, INetworkManager network, IDeviceManager deviceManager)
|
2013-02-24 14:53:54 -07:00
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
if (jsonSerializer == null)
|
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
|
throw new ArgumentNullException(nameof(jsonSerializer));
|
2013-02-24 14:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 19:47:04 -07:00
|
|
|
|
_appHost = appHost;
|
2013-03-04 21:25:27 -07:00
|
|
|
|
_installationManager = installationManager;
|
2015-05-26 08:31:50 -07:00
|
|
|
|
_network = network;
|
|
|
|
|
_deviceManager = deviceManager;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
_jsonSerializer = jsonSerializer;
|
|
|
|
|
}
|
2019-01-04 16:25:34 -07:00
|
|
|
|
|
2019-01-05 00:02:39 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public async Task<object> Get(GetRegistrationStatus request)
|
|
|
|
|
{
|
|
|
|
|
var record = new MBRegistrationRecord
|
|
|
|
|
{
|
|
|
|
|
IsRegistered = true,
|
|
|
|
|
RegChecked = true,
|
|
|
|
|
TrialVersion = false,
|
|
|
|
|
IsValid = true,
|
|
|
|
|
RegError = false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO this function is only kept for compatibility and should be removed once paid plugins break
|
2019-01-04 16:25:34 -07:00
|
|
|
|
public async Task<object> Get(GetRegistration request)
|
|
|
|
|
{
|
|
|
|
|
var info = new RegistrationInfo
|
|
|
|
|
{
|
|
|
|
|
ExpirationDate = DateTime.Now.AddYears(100),
|
|
|
|
|
IsRegistered = true,
|
|
|
|
|
IsTrial = false,
|
|
|
|
|
Name = request.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(info);
|
|
|
|
|
}
|
2019-01-05 00:02:39 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2015-01-09 22:53:35 -07:00
|
|
|
|
public async Task<object> Get(GetPlugins request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2019-01-05 00:02:39 -07:00
|
|
|
|
// TODO This code can be reused for a proper Jellyfin plugin store (maybe). Remove/reuse when decided.
|
2019-01-04 14:42:56 -07:00
|
|
|
|
var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToArray();
|
|
|
|
|
// var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value;
|
|
|
|
|
//
|
|
|
|
|
// // Don't fail just on account of image url's
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// var packages = (await _installationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None));
|
|
|
|
|
//
|
|
|
|
|
// foreach (var plugin in result)
|
|
|
|
|
// {
|
|
|
|
|
// var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && string.Equals(i.guid.Replace("-", string.Empty), plugin.Id.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
//
|
|
|
|
|
// if (pkg != null)
|
|
|
|
|
// {
|
|
|
|
|
// plugin.ImageUrl = pkg.thumbImage;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (requireAppStoreEnabled)
|
|
|
|
|
// {
|
|
|
|
|
// result = result
|
|
|
|
|
// .Where(plugin =>
|
|
|
|
|
// {
|
|
|
|
|
// var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid)));
|
|
|
|
|
// return pkg != null && pkg.enableInAppStore;
|
|
|
|
|
//
|
|
|
|
|
// })
|
|
|
|
|
// .ToArray();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// Logger.LogError(ex, "Error getting plugin list");
|
|
|
|
|
// // Play it safe here
|
|
|
|
|
// if (requireAppStoreEnabled)
|
|
|
|
|
// {
|
|
|
|
|
// result = new PluginInfo[] { };
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2018-09-12 10:26:21 -07:00
|
|
|
|
return ToOptimizedResult(result);
|
2013-02-20 18:33:05 -07: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 16:51:33 -07:00
|
|
|
|
var guid = new Guid(request.Id);
|
2018-09-12 10:26:21 -07:00
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid) as IHasPluginConfiguration;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2016-01-20 12:54:06 -07:00
|
|
|
|
return ToOptimizedResult(plugin.Configuration);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2019-01-05 00:02:39 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public async Task<object> Get(GetPluginSecurityInfo request)
|
|
|
|
|
{
|
|
|
|
|
var result = new PluginSecurityInfo
|
|
|
|
|
{
|
|
|
|
|
IsMBSupporter = true,
|
|
|
|
|
SupporterKey = "IAmTotallyLegit"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public Task Post(UpdatePluginSecurityInfo request)
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2018-09-12 10:26:21 -07:00
|
|
|
|
public async Task Post(UpdatePluginConfiguration request)
|
2013-02-20 18:33:05 -07: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
|
2015-01-22 09:41:34 -07:00
|
|
|
|
var id = new Guid(GetPathValue(1));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == id) as IHasPluginConfiguration;
|
|
|
|
|
|
|
|
|
|
if (plugin == null)
|
|
|
|
|
{
|
|
|
|
|
throw new FileNotFoundException();
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
|
var configuration = (await _jsonSerializer.DeserializeFromStreamAsync(request.RequestStream, plugin.ConfigurationType).ConfigureAwait(false)) as BasePluginConfiguration;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
plugin.UpdateConfiguration(configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Delete(UninstallPlugin request)
|
|
|
|
|
{
|
2015-05-29 16:51:33 -07:00
|
|
|
|
var guid = new Guid(request.Id);
|
|
|
|
|
var plugin = _appHost.Plugins.First(p => p.Id == guid);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-04 21:25:27 -07:00
|
|
|
|
_installationManager.UninstallPlugin(plugin);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|