mirror of https://github.com/jellyfin/jellyfin.git
add suggested changes
This commit is contained in:
parent
b18bb3d0de
commit
64cc5889f2
|
@ -4,14 +4,16 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Json;
|
using MediaBrowser.Common.Json;
|
||||||
using MediaBrowser.Common.Json.Converters;
|
using MediaBrowser.Common.Json.Converters;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
@ -35,6 +37,21 @@ namespace Emby.Server.Implementations.Plugins
|
||||||
private readonly IList<LocalPlugin> _plugins;
|
private readonly IList<LocalPlugin> _plugins;
|
||||||
private readonly Version _minimumVersion;
|
private readonly Version _minimumVersion;
|
||||||
|
|
||||||
|
private IHttpClientFactory? _httpClientFactory;
|
||||||
|
|
||||||
|
private IHttpClientFactory HttpClientFactory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_httpClientFactory == null)
|
||||||
|
{
|
||||||
|
_httpClientFactory = _appHost.Resolve<IHttpClientFactory>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _httpClientFactory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -351,15 +368,29 @@ namespace Emby.Server.Implementations.Plugins
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool GenerateManifest(PackageInfo packageInfo, Version version, string path)
|
public async Task<bool> GenerateManifest(PackageInfo packageInfo, Version version, string path)
|
||||||
{
|
{
|
||||||
var versionInfo = packageInfo.Versions.First(v => v.Version == version.ToString());
|
if (packageInfo == null)
|
||||||
var url = packageInfo.ImageUrl ?? string.Empty;
|
|
||||||
var imageFilename = url.Substring(url.LastIndexOf('/') + 1, url.Length);
|
|
||||||
|
|
||||||
using (var client = new WebClient())
|
|
||||||
{
|
{
|
||||||
client.DownloadFile(url, Path.Join(path, imageFilename));
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var versionInfo = packageInfo.Versions.First(v => v.Version == version.ToString());
|
||||||
|
var imagePath = string.Empty;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(packageInfo.ImageUrl))
|
||||||
|
{
|
||||||
|
var url = new Uri(packageInfo.ImageUrl);
|
||||||
|
imagePath = Path.Join(path, url.Segments.Last());
|
||||||
|
|
||||||
|
await using var fileStream = File.OpenWrite(imagePath);
|
||||||
|
var downloadStream = await HttpClientFactory
|
||||||
|
.CreateClient(NamedClient.Default)
|
||||||
|
.GetStreamAsync(url)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
await downloadStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
await fileStream.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
var manifest = new PluginManifest
|
var manifest = new PluginManifest
|
||||||
|
@ -376,7 +407,7 @@ namespace Emby.Server.Implementations.Plugins
|
||||||
Version = versionInfo.Version,
|
Version = versionInfo.Version,
|
||||||
Status = PluginStatus.Active,
|
Status = PluginStatus.Active,
|
||||||
AutoUpdate = true,
|
AutoUpdate = true,
|
||||||
ImagePath = Path.Join(path, imageFilename)
|
ImagePath = imagePath
|
||||||
};
|
};
|
||||||
|
|
||||||
return SaveManifest(manifest, path);
|
return SaveManifest(manifest, path);
|
||||||
|
|
|
@ -194,7 +194,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
var plugin = _pluginManager.GetPlugin(packageGuid, version.VersionNumber);
|
var plugin = _pluginManager.GetPlugin(packageGuid, version.VersionNumber);
|
||||||
if (plugin != null)
|
if (plugin != null)
|
||||||
{
|
{
|
||||||
_pluginManager.GenerateManifest(package, version.VersionNumber, plugin.Path);
|
await _pluginManager.GenerateManifest(package, version.VersionNumber, plugin.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove versions with a target ABI greater then the current application version.
|
// Remove versions with a target ABI greater then the current application version.
|
||||||
|
@ -567,7 +567,7 @@ namespace Emby.Server.Implementations.Updates
|
||||||
|
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
_zipClient.ExtractAllFromZip(stream, targetDir, true);
|
_zipClient.ExtractAllFromZip(stream, targetDir, true);
|
||||||
_pluginManager.GenerateManifest(package.PackageInfo, package.Version, targetDir);
|
await _pluginManager.GenerateManifest(package.PackageInfo, package.Version, targetDir);
|
||||||
_pluginManager.ImportPluginFrom(targetDir);
|
_pluginManager.ImportPluginFrom(targetDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace MediaBrowser.Common.Plugins
|
||||||
/// <param name="version">Version to be installed.</param>
|
/// <param name="version">Version to be installed.</param>
|
||||||
/// <param name="path">The path where to save the manifest.</param>
|
/// <param name="path">The path where to save the manifest.</param>
|
||||||
/// <returns>True if successful.</returns>
|
/// <returns>True if successful.</returns>
|
||||||
bool GenerateManifest(PackageInfo packageInfo, Version version, string path);
|
Task<bool> GenerateManifest(PackageInfo packageInfo, Version version, string path);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Imports plugin details from a folder.
|
/// Imports plugin details from a folder.
|
||||||
|
|
Loading…
Reference in New Issue