From a6cdbce02dee39d63c094ef7018b38e145a98995 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:45:17 +0800 Subject: [PATCH] Revert "refactor: add douban httpclient" This reverts commit 7e4246003dec53e01578e1e17a0efaedb73e4a05. --- .../Controllers/ApiController.cs | 12 +++++++++++- Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs | 17 ----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs b/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs index ba5e518..c3c9848 100644 --- a/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs +++ b/Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs @@ -6,6 +6,7 @@ using MediaBrowser.Common.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using MediaBrowser.Common.Net; using Jellyfin.Plugin.MetaShark.Api; using Jellyfin.Plugin.MetaShark.Model; @@ -44,9 +45,12 @@ public async Task ProxyImage(string url) } HttpResponseMessage response; - var httpClient = this._httpClientFactory.CreateClient("douban"); + var httpClient = GetHttpClient(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) { + requestMessage.Headers.Add("User-Agent", DoubanApi.HTTP_USER_AGENT); + requestMessage.Headers.Add("Referer", DoubanApi.HTTP_REFERER); + response = await httpClient.SendAsync(requestMessage); } var stream = await response.Content.ReadAsStreamAsync(); @@ -76,5 +80,11 @@ public async Task CheckDoubanLogin() var isLogin = await _doubanApi.CheckLoginAsync(CancellationToken.None); return new ApiResult(isLogin ? 1 : 0, isLogin ? "logined" : "not login"); } + + private HttpClient GetHttpClient() + { + var client = _httpClientFactory.CreateClient(NamedClient.Default); + return client; + } } } diff --git a/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs b/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs index 658dcb1..7c0b590 100644 --- a/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs +++ b/Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.Logging; using MediaBrowser.Controller.Persistence; using System.Net.Http; -using System.Net; namespace Jellyfin.Plugin.MetaShark { @@ -39,22 +38,6 @@ public void RegisterServices(IServiceCollection serviceCollection) { return new ImdbApi(ctx.GetRequiredService()); }); - - // douban httpclient 忽略 ssl 证书校验 - serviceCollection.AddHttpClient("douban", client => - { - client.DefaultRequestHeaders.Add("User-Agent", DoubanApi.HTTP_USER_AGENT); - client.DefaultRequestHeaders.Add("Referer", DoubanApi.HTTP_REFERER); - }).ConfigurePrimaryHttpMessageHandler(() => - { - var handler = new HttpClientHandler - { - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, - ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true - }; - return handler; - }); - } } }