Skip to content

Commit

Permalink
Revert "refactor: add douban httpclient"
Browse files Browse the repository at this point in the history
This reverts commit 7e42460.
  • Loading branch information
cxfksword committed Sep 16, 2023
1 parent 04c3ef9 commit a6cdbce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
12 changes: 11 additions & 1 deletion Jellyfin.Plugin.MetaShark/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -44,9 +45,12 @@ public async Task<Stream> 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();
Expand Down Expand Up @@ -76,5 +80,11 @@ public async Task<ApiResult> 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;
}
}
}
17 changes: 0 additions & 17 deletions Jellyfin.Plugin.MetaShark/ServiceRegistrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.Extensions.Logging;
using MediaBrowser.Controller.Persistence;
using System.Net.Http;
using System.Net;

namespace Jellyfin.Plugin.MetaShark
{
Expand All @@ -39,22 +38,6 @@ public void RegisterServices(IServiceCollection serviceCollection)
{
return new ImdbApi(ctx.GetRequiredService<ILoggerFactory>());
});

// 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;
});

}
}
}

0 comments on commit a6cdbce

Please sign in to comment.