Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions src/Ray.BiliBiliTool.Agent/BiliBiliAgent/ApiList.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces
public interface IRelationApi : IBiliBiliApi
{
/// <summary>
///
/// 获取关注列表
/// </summary>
/// <param name="vmid"></param>
/// <param name="pn"></param>
Expand Down
40 changes: 20 additions & 20 deletions src/Ray.BiliBiliTool.Agent/MyHttpClientDelegatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,39 @@ public MyHttpClientDelegatingHandler(ILogger<MyHttpClientDelegatingHandler> logg
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
//记录请求内容
_logger.LogDebug($"[{request.Method}] {request.RequestUri}");
_logger.LogDebug("发起请求:[{method}] {uri}", request.Method, request.RequestUri);

if (request.Content != null)
{
_logger.LogDebug(await request.Content.ReadAsStringAsync());
var requestContent = await request.Content.ReadAsStringAsync();
_logger.LogDebug("请求Content: {content}", requestContent);
}

IntervalForSecurity(request.Method);
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

//记录返回内容
if (response.Content != null)
{
var content = await response.Content.ReadAsStringAsync();
_logger.LogDebug(content);
if (response.Content == null) return response;

//如果返回不是json格式,则抛异常
string msg = "Api返回Content序列化异常,怀疑为不标准返回类型";
try
{
var ob = JsonSerializer.Deserialize<object>(content);
if (ob == null)
{
_logger.LogCritical(msg);
throw new Exception(msg);
}
}
catch (Exception)
var content = await response.Content.ReadAsStringAsync();
_logger.LogDebug("返回Content:{content}", content);

//如果返回不是json格式,则抛异常
string msg = "Api返回Content序列化异常,怀疑为不标准返回类型";
try
{
var ob = JsonSerializer.Deserialize<object>(content);
if (ob == null)
{
_logger.LogInformation(msg);
throw;
_logger.LogError(msg);
throw new Exception(msg);
}
}
catch (Exception)
{
_logger.LogInformation(msg);
throw;
}
return response;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Ray.BiliBiliTool.Config/Options/BiliBiliCookieOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,38 @@ public bool Check(ILogger logger)
string msg = "配置项[{0}]为空,该项为必须配置,对应浏览器中Cookie中的[{1}]值";
string tips = "检测到已配置了[{0}],已兼容使用[{1}]";

//UserId为空,抛异常
if (string.IsNullOrWhiteSpace(UserId))
{
logger.LogWarning(msg, nameof(UserId), GetPropertyDescription(nameof(UserId)));

result = false;
}
else if (string.IsNullOrWhiteSpace(RayConfiguration.Root["BiliBiliCookie:UserID"])
else if (!long.TryParse(UserId, out long uid))//不为空,但不能转换为long,警告
{
logger.LogWarning("UserId:{uid} 不能转换为long型,请确认配置的是正确的Cookie值");
}
//UserId为空,但DedeUserID有值,兼容使用
if (string.IsNullOrWhiteSpace(RayConfiguration.Root["BiliBiliCookie:UserID"])
&& !string.IsNullOrWhiteSpace(RayConfiguration.Root["BiliBiliCookie:DedeUserID"]))
{
logger.LogWarning(tips, "DEDEUSERID", "DEDEUSERID");
}

//SessData为空,抛异常
if (string.IsNullOrWhiteSpace(SessData))
{
logger.LogWarning(msg, nameof(SessData), GetPropertyDescription(nameof(SessData)));
result = false;
}

//BiliJct为空,抛异常
if (string.IsNullOrWhiteSpace(BiliJct))
{
logger.LogWarning(msg, nameof(BiliJct), GetPropertyDescription(nameof(BiliJct)));
result = false;
}
//BiliJct为空,但Bili_jct有值,兼容使用
else if (string.IsNullOrWhiteSpace(RayConfiguration.Root["BiliBiliCookie:BiliJct"])
&& !string.IsNullOrWhiteSpace(RayConfiguration.Root["BiliBiliCookie:Bili_jct"]))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ray.BiliBiliTool.Config/Options/SecurityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SecurityOptions
/// 两次调用api之间间隔的秒数[0,+]
/// 有人担心在几秒内连续调用api会被b站安全机制发现,所以为不放心的朋友添加了间隔秒数配置,两次调用Api之间会大于该秒数
/// </summary>
public int IntervalSecondsBetweenRequestApi { get; set; } = 1;
public int IntervalSecondsBetweenRequestApi { get; set; } = 3;

/// <summary>
/// 间隔秒数所针对的HttpMethod,多个用英文逗号隔开,当前有GET和POST两种,可配置如“GET,POST”
Expand Down
4 changes: 2 additions & 2 deletions src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public decimal ExchangeSilver2Coin()
}

var queryStatus = _liveApi.GetExchangeSilverStatus().Result;
var silver2CoinMoney = _coinDomainService.GetCoinBalance();

_logger.LogInformation("当前银瓜子余额: {0}", queryStatus.Data.Silver);

var silver2CoinMoney = _coinDomainService.GetCoinBalance();
_logger.LogInformation("当前硬币余额: {0}", silver2CoinMoney);

return silver2CoinMoney;
Expand Down
3 changes: 3 additions & 0 deletions test/LogTest/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public void Test1()
logger.LogInformation("testInfo");
logger.LogError("testError");

logger.LogDebug(null);
logger.LogDebug("123{0}{1}", null,"haha");

Task.Delay(3000);
}
}
Expand Down