From aee72aefb0c89fb9d173da27d2e97c97bb689822 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 17 Aug 2020 11:46:40 -0600 Subject: [PATCH] Remove IHttpClient from StudiosImageProvider --- .../MediaBrowser.Providers.csproj | 3 +- .../Studios/StudiosImageProvider.cs | 30 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 7c0b54250..85966b3bf 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -18,6 +18,7 @@ + @@ -27,7 +28,7 @@ netstandard2.1 false true - true + true diff --git a/MediaBrowser.Providers/Studios/StudiosImageProvider.cs b/MediaBrowser.Providers/Studios/StudiosImageProvider.cs index 25f8beb40..1fcd63d3f 100644 --- a/MediaBrowser.Providers/Studios/StudiosImageProvider.cs +++ b/MediaBrowser.Providers/Studios/StudiosImageProvider.cs @@ -20,13 +20,13 @@ namespace MediaBrowser.Providers.Studios public class StudiosImageProvider : IRemoteImageProvider { private readonly IServerConfigurationManager _config; - private readonly IHttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly IFileSystem _fileSystem; - public StudiosImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem) + public StudiosImageProvider(IServerConfigurationManager config, IHttpClientFactory httpClientFactory, IFileSystem fileSystem) { _config = config; - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _fileSystem = fileSystem; } @@ -108,14 +108,14 @@ namespace MediaBrowser.Providers.Studios { const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studiothumbs.txt"; - return EnsureList(url, file, _httpClient, _fileSystem, cancellationToken); + return EnsureList(url, file, _fileSystem, cancellationToken); } private Task EnsurePosterList(string file, CancellationToken cancellationToken) { const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studioposters.txt"; - return EnsureList(url, file, _httpClient, _fileSystem, cancellationToken); + return EnsureList(url, file, _fileSystem, cancellationToken); } public int Order => 0; @@ -139,26 +139,18 @@ namespace MediaBrowser.Providers.Studios /// The file system. /// The cancellation token. /// Task. - public async Task EnsureList(string url, string file, IHttpClient httpClient, IFileSystem fileSystem, CancellationToken cancellationToken) + public async Task EnsureList(string url, string file, IFileSystem fileSystem, CancellationToken cancellationToken) { var fileInfo = fileSystem.GetFileInfo(file); if (!fileInfo.Exists || (DateTime.UtcNow - fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays > 1) { - Directory.CreateDirectory(Path.GetDirectoryName(file)); + var httpClient = _httpClientFactory.CreateClient(); - using (var res = await httpClient.SendAsync( - new HttpRequestOptions - { - CancellationToken = cancellationToken, - Url = url - }, - HttpMethod.Get).ConfigureAwait(false)) - using (var content = res.Content) - using (var fileStream = new FileStream(file, FileMode.Create)) - { - await content.CopyToAsync(fileStream).ConfigureAwait(false); - } + Directory.CreateDirectory(Path.GetDirectoryName(file)); + await using var response = await httpClient.GetStreamAsync(url).ConfigureAwait(false); + await using var fileStream = new FileStream(file, FileMode.Create); + await response.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false); } return file;