The Free Software Media System - Server Backend & API
Change update checks to use static file
Eric Reed55bbfc2dcc64
diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.csindex 778a793a94..81262daf69 100644--- a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs+++ b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs@@ -43,6 +43,12 @@ namespace MediaBrowser.Common.Implementations.Updates_logger = logger;}+ /// <summary>+ /// Get all available packages including registration information.+ /// Use this for the plug-in catalog to provide all information for this installation.+ /// </summary>+ /// <param name="cancellationToken"></param>+ /// <returns></returns>public async Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken){var data = new Dictionary<string, string> { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } };@@ -52,15 +58,39 @@ namespace MediaBrowser.Common.Implementations.UpdatescancellationToken.ThrowIfCancellationRequested();var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();- foreach (var package in packages)++ return FilterVersions(packages);+ }++ }++ /// <summary>+ /// Get all available packages using the static file resource.+ /// Use this for update checks as it will be much less taxing on the server and can be cached.+ /// </summary>+ /// <param name="cancellationToken"></param>+ /// <returns></returns>+ public async Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken)+ {+ using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false))+ {+ cancellationToken.ThrowIfCancellationRequested();++ var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList();++ return FilterVersions(packages);+ }+ }++ private IEnumerable<PackageInfo> FilterVersions(List<PackageInfo> original)+ {+ foreach (var package in original){package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)).OrderByDescending(v => v.version).ToList();}- return packages;- }-+ return original;}public async Task InstallPackage(IProgress<double> progress, PackageVersionInfo package, CancellationToken cancellationToken)diff --git a/MediaBrowser.Common/Updates/IPackageManager.cs b/MediaBrowser.Common/Updates/IPackageManager.csindex ecaf9cef83..4a2db06d1f 100644--- a/MediaBrowser.Common/Updates/IPackageManager.cs+++ b/MediaBrowser.Common/Updates/IPackageManager.cs@@ -9,12 +9,19 @@ namespace MediaBrowser.Common.Updatespublic interface IPackageManager{/// <summary>- /// Gets all available packages.+ /// Gets all available packages dynamically./// </summary>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{List{PackageInfo}}.</returns>Task<IEnumerable<PackageInfo>> GetAvailablePackages(CancellationToken cancellationToken);+ /// <summary>+ /// Gets all available packages from a static resource.+ /// </summary>+ /// <param name="cancellationToken">The cancellation token.</param>+ /// <returns>Task{List{PackageInfo}}.</returns>+ Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken);+/// <summary>/// Installs a package./// </summary>diff --git a/MediaBrowser.Controller/Updates/IInstallationManager.cs b/MediaBrowser.Controller/Updates/IInstallationManager.csindex dc6aaf0c9f..7911502760 100644--- a/MediaBrowser.Controller/Updates/IInstallationManager.cs+++ b/MediaBrowser.Controller/Updates/IInstallationManager.cs@@ -79,13 +79,21 @@ namespace MediaBrowser.Controller.UpdatesPackageVersionInfo GetLatestCompatibleVersion(IEnumerable<PackageInfo> availablePackages, string name, PackageVersionClass classification = PackageVersionClass.Release);/// <summary>- /// Gets the available plugin updates.+ /// Gets the available plugin updates including registration info./// </summary>/// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken);+ /// <summary>+ /// Gets the available plugin updates from a static resource (not including registration info).+ /// </summary>+ /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>+ /// <param name="cancellationToken">The cancellation token.</param>+ /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>+ Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken);+/// <summary>/// Installs the package./// </summary>diff --git a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.csindex 9c869ddc18..3a0a865263 100644--- a/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs+++ b/MediaBrowser.Server.Implementations/ScheduledTasks/PluginUpdateTask.cs@@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks{progress.Report(0);- var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(true, cancellationToken).ConfigureAwait(false)).ToList();+ var packagesToInstall = (await _installationManager.GetAvailablePluginUpdatesStatic(true, cancellationToken).ConfigureAwait(false)).ToList();progress.Report(10);diff --git a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Server.Implementations/Updates/InstallationManager.csindex 9c3b532eca..4dd9c47d1e 100644--- a/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs+++ b/MediaBrowser.Server.Implementations/Updates/InstallationManager.cs@@ -171,6 +171,26 @@ namespace MediaBrowser.Server.Implementations.Updates{var packages = (await _packageManager.GetAvailablePackages(cancellationToken).ConfigureAwait(false)).ToList();+ return FilterPackages(packages, packageType, applicationVersion);+ }++ /// <summary>+ /// Gets all available packages.+ /// </summary>+ /// <param name="cancellationToken">The cancellation token.</param>+ /// <param name="packageType">Type of the package.</param>+ /// <param name="applicationVersion">The application version.</param>+ /// <returns>Task{List{PackageInfo}}.</returns>+ protected async Task<IEnumerable<PackageInfo>> GetAvailablePackagesStatic(CancellationToken cancellationToken,+ PackageType? packageType = null,+ Version applicationVersion = null)+ {+ var packages = (await _packageManager.GetAvailablePackagesStatic(cancellationToken).ConfigureAwait(false)).ToList();+ return FilterPackages(packages, packageType, applicationVersion);+ }++ protected IEnumerable<PackageInfo> FilterPackages(List<PackageInfo> packages, PackageType? packageType, Version applicationVersion)+ {if (packageType.HasValue){packages = packages.Where(p => p.type == packageType.Value).ToList();@@ -265,7 +285,8 @@ namespace MediaBrowser.Server.Implementations.Updates}/// <summary>- /// Gets the available plugin updates.+ /// Gets the available plugin updates including registration information for each one.+ /// Used with API and catalog./// </summary>/// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>/// <param name="cancellationToken">The cancellation token.</param>@@ -273,7 +294,25 @@ namespace MediaBrowser.Server.Implementations.Updatespublic async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdates(bool withAutoUpdateEnabled, CancellationToken cancellationToken){var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false);+ return FilterCatalog(catalog, withAutoUpdateEnabled);+ }+ /// <summary>+ /// Gets the available plugin updates from a static resource - no registration information.+ /// Used for update checks.+ /// </summary>+ /// <param name="withAutoUpdateEnabled">if set to <c>true</c> [with auto update enabled].</param>+ /// <param name="cancellationToken">The cancellation token.</param>+ /// <returns>Task{IEnumerable{PackageVersionInfo}}.</returns>+ public async Task<IEnumerable<PackageVersionInfo>> GetAvailablePluginUpdatesStatic(bool withAutoUpdateEnabled, CancellationToken cancellationToken)+ {+ var catalog = await GetAvailablePackagesStatic(cancellationToken).ConfigureAwait(false);+ return FilterCatalog(catalog, withAutoUpdateEnabled);+ }++ protected IEnumerable<PackageVersionInfo> FilterCatalog(IEnumerable<PackageInfo> catalog, bool withAutoUpdateEnabled)+ {+var plugins = ApplicationHost.Plugins;if (withAutoUpdateEnabled)diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.csindex 70cd319ca6..0d6c5ed358 100644--- a/MediaBrowser.ServerApplication/ApplicationHost.cs+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs@@ -474,7 +474,7 @@ namespace MediaBrowser.ServerApplication/// <returns>Task{CheckForUpdateResult}.</returns>public async override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress){- var availablePackages = await PackageManager.GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);+ var availablePackages = await PackageManager.GetAvailablePackagesStatic(CancellationToken.None).ConfigureAwait(false);var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :diff --git a/MediaBrowser.sln b/MediaBrowser.slnindex e6a61c9de1..f4a9f31569 100644--- a/MediaBrowser.sln+++ b/MediaBrowser.sln@@ -221,7 +221,4 @@ GlobalGlobalSection(SolutionProperties) = preSolutionHideSolutionNode = FALSEEndGlobalSection- GlobalSection(Performance) = preSolution- HasPerformanceSessions = true- EndGlobalSectionEndGlobal