aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Plugins/PluginManager.cs
diff options
context:
space:
mode:
authordkanada <dkanada@users.noreply.github.com>2021-02-23 23:11:17 +0900
committerdkanada <dkanada@users.noreply.github.com>2021-02-23 23:11:17 +0900
commit64cc5889f2be0dae6b0425c569bd84f996a0e435 (patch)
treec5acf067b14c8b68ce6221beb09b50694d0b6688 /Emby.Server.Implementations/Plugins/PluginManager.cs
parentb18bb3d0de5e459b9bafbc3a67afe6204eca1b08 (diff)
add suggested changes
Diffstat (limited to 'Emby.Server.Implementations/Plugins/PluginManager.cs')
-rw-r--r--Emby.Server.Implementations/Plugins/PluginManager.cs45
1 files changed, 38 insertions, 7 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs
index fec7bcb87..b4ab55157 100644
--- a/Emby.Server.Implementations/Plugins/PluginManager.cs
+++ b/Emby.Server.Implementations/Plugins/PluginManager.cs
@@ -4,14 +4,16 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net;
+using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.Json;
+using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Json;
using MediaBrowser.Common.Json.Converters;
+using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Plugins;
@@ -35,6 +37,21 @@ namespace Emby.Server.Implementations.Plugins
private readonly IList<LocalPlugin> _plugins;
private readonly Version _minimumVersion;
+ private IHttpClientFactory? _httpClientFactory;
+
+ private IHttpClientFactory HttpClientFactory
+ {
+ get
+ {
+ if (_httpClientFactory == null)
+ {
+ _httpClientFactory = _appHost.Resolve<IHttpClientFactory>();
+ }
+
+ return _httpClientFactory;
+ }
+ }
+
/// <summary>
/// Initializes a new instance of the <see cref="PluginManager"/> class.
/// </summary>
@@ -351,15 +368,29 @@ namespace Emby.Server.Implementations.Plugins
}
/// <inheritdoc/>
- public bool GenerateManifest(PackageInfo packageInfo, Version version, string path)
+ public async Task<bool> GenerateManifest(PackageInfo packageInfo, Version version, string path)
{
+ if (packageInfo == null)
+ {
+ return false;
+ }
+
var versionInfo = packageInfo.Versions.First(v => v.Version == version.ToString());
- var url = packageInfo.ImageUrl ?? string.Empty;
- var imageFilename = url.Substring(url.LastIndexOf('/') + 1, url.Length);
+ var imagePath = string.Empty;
- using (var client = new WebClient())
+ if (!string.IsNullOrEmpty(packageInfo.ImageUrl))
{
- client.DownloadFile(url, Path.Join(path, imageFilename));
+ 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
@@ -376,7 +407,7 @@ namespace Emby.Server.Implementations.Plugins
Version = versionInfo.Version,
Status = PluginStatus.Active,
AutoUpdate = true,
- ImagePath = Path.Join(path, imageFilename)
+ ImagePath = imagePath
};
return SaveManifest(manifest, path);