-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #856 from RayWangQvQ/feature/2.2-refactor
2.2.2 Code Refactor
- Loading branch information
Showing
145 changed files
with
4,406 additions
and
5,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Authors>Ray</Authors> | ||
<Version>2.2.1</Version> | ||
<Version>2.2.2</Version> | ||
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn> | ||
</PropertyGroup> | ||
</Project> |
114 changes: 48 additions & 66 deletions
114
src/Ray.BiliBiliTool.Agent/Attributes/AppendHeaderAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WebApiClientCore; | ||
using WebApiClientCore.Attributes; | ||
|
||
namespace Ray.BiliBiliTool.Agent.Attributes | ||
namespace Ray.BiliBiliTool.Agent.Attributes; | ||
|
||
[DebuggerDisplay("{name} = {value}")] | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Parameter, AllowMultiple = true)] | ||
public class AppendHeaderAttribute( | ||
string name, | ||
string value, | ||
AppendHeaderType appendHeaderType = AppendHeaderType.AddOrReplace) | ||
: ApiActionAttribute, IApiParameterAttribute | ||
{ | ||
[DebuggerDisplay("{name} = {value}")] | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)] | ||
public class AppendHeaderAttribute : ApiActionAttribute, IApiParameterAttribute, IApiAttribute | ||
{ | ||
//添加的顺序为:子类、基类、子类函数、子类函数入参 | ||
//添加的顺序为:子类、基类、子类函数、子类函数入参 | ||
|
||
private readonly string _name; | ||
private readonly string _value; | ||
private readonly AppendHeaderType _appendHeaderType; | ||
private readonly string _aliasName; | ||
private readonly string _aliasName; | ||
|
||
public AppendHeaderAttribute(string name, string value, AppendHeaderType appendHeaderType = AppendHeaderType.AddOrReplace) | ||
{ | ||
_name = name; | ||
_value = value; | ||
_appendHeaderType = appendHeaderType; | ||
} | ||
public AppendHeaderAttribute(string aliasName, AppendHeaderType appendHeaderType = AppendHeaderType.AddOrReplace) : this(null, null, appendHeaderType) | ||
{ | ||
_aliasName = aliasName; | ||
} | ||
|
||
public AppendHeaderAttribute(string aliasName, AppendHeaderType appendHeaderType = AppendHeaderType.AddOrReplace) | ||
{ | ||
_aliasName = aliasName; | ||
_appendHeaderType = appendHeaderType; | ||
} | ||
public override Task OnRequestAsync(ApiRequestContext context) | ||
{ | ||
AddByAppendType(context.HttpContext.RequestMessage.Headers, name, value); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public override Task OnRequestAsync(ApiRequestContext context) | ||
public Task OnRequestAsync(ApiParameterContext context) | ||
{ | ||
string parameterName = _aliasName; | ||
if (string.IsNullOrEmpty(parameterName)) | ||
{ | ||
AddByAppendType(context.HttpContext.RequestMessage.Headers, _name, _value); | ||
return Task.CompletedTask; | ||
parameterName = context.ParameterName; | ||
} | ||
|
||
public Task OnRequestAsync(ApiParameterContext context) | ||
string text = context.ParameterValue?.ToString(); | ||
if (!string.IsNullOrEmpty(text)) | ||
{ | ||
string parameterName = _aliasName; | ||
if (string.IsNullOrEmpty(parameterName)) | ||
{ | ||
parameterName = context.ParameterName; | ||
} | ||
|
||
string text = context.ParameterValue?.ToString(); | ||
if (!string.IsNullOrEmpty(text)) | ||
{ | ||
AddByAppendType(context.HttpContext.RequestMessage.Headers, parameterName, text); | ||
} | ||
|
||
return Task.CompletedTask; | ||
AddByAppendType(context.HttpContext.RequestMessage.Headers, parameterName, text); | ||
} | ||
|
||
private void AddByAppendType(HttpRequestHeaders headers, string key, string value) | ||
{ | ||
switch (_appendHeaderType) | ||
{ | ||
case AppendHeaderType.Add: | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
case AppendHeaderType.AddIfNotExist: | ||
if (!headers.Contains(key)) | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
case AppendHeaderType.AddOrReplace: | ||
if (headers.Contains(key)) | ||
headers.Remove(key); | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return Task.CompletedTask; | ||
} | ||
|
||
public enum AppendHeaderType | ||
private void AddByAppendType(HttpRequestHeaders headers, string key, string value) | ||
{ | ||
Add, | ||
AddIfNotExist, | ||
AddOrReplace | ||
switch (appendHeaderType) | ||
{ | ||
case AppendHeaderType.Add: | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
case AppendHeaderType.AddIfNotExist: | ||
if (!headers.Contains(key)) | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
case AppendHeaderType.AddOrReplace: | ||
if (headers.Contains(key)) | ||
headers.Remove(key); | ||
headers.TryAddWithoutValidation(key, value); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Ray.BiliBiliTool.Agent.Attributes; | ||
|
||
public enum AppendHeaderType | ||
{ | ||
Add, | ||
AddIfNotExist, | ||
AddOrReplace | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 16 additions & 23 deletions
39
src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Dtos/AddCoinRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos; | ||
|
||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos | ||
public class AddCoinRequest | ||
{ | ||
public class AddCoinRequest | ||
public AddCoinRequest(long aid, string csrf) | ||
{ | ||
public AddCoinRequest(long aid, string csrf) | ||
{ | ||
Aid = aid; | ||
Csrf = csrf; | ||
} | ||
Aid = aid; | ||
Csrf = csrf; | ||
} | ||
|
||
public long Aid { get; set; } | ||
public long Aid { get; set; } | ||
|
||
public int Multiply { get; set; } = 1; | ||
public int Multiply { get; set; } = 1; | ||
|
||
public int Select_like { get; set; } = 1; | ||
public int Select_like { get; set; } = 1; | ||
|
||
public string Cross_domain { get; set; } = "true"; | ||
public string Cross_domain { get; set; } = "true"; | ||
|
||
public string Csrf { get; set; } | ||
public string Csrf { get; set; } | ||
|
||
public string Eab_x { get; set; } = "2"; | ||
public string Eab_x { get; set; } = "2"; | ||
|
||
public string Ramval { get; set; } = "3"; | ||
public string Ramval { get; set; } = "3"; | ||
|
||
public string Source { get; set; } = "web_normal"; | ||
public string Source { get; set; } = "web_normal"; | ||
|
||
public string Ga { get; set; } = "1"; | ||
} | ||
} | ||
public string Ga { get; set; } = "1"; | ||
} |
21 changes: 10 additions & 11 deletions
21
src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Dtos/BiliApiResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos | ||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos; | ||
|
||
public class BiliApiResponse : BiliApiResponse<object> | ||
{ | ||
public class BiliApiResponse : BiliApiResponse<object> | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class BiliApiResponse<TData> | ||
{ | ||
public int Code { get; set; } = int.MinValue; | ||
public class BiliApiResponse<TData> | ||
{ | ||
public int Code { get; set; } = int.MinValue; | ||
|
||
public string Message { get; set; } | ||
public string Message { get; set; } | ||
|
||
public TData Data { get; set; } | ||
} | ||
} | ||
public TData Data { get; set; } | ||
} |
33 changes: 16 additions & 17 deletions
33
src/Ray.BiliBiliTool.Agent/BiliBiliAgent/Dtos/BiliPageResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos | ||
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos; | ||
|
||
public class BiliPageResult | ||
{ | ||
public class BiliPageResult | ||
{ | ||
/// <summary> | ||
/// 视频总数量 | ||
/// </summary> | ||
public int Count { get; set; } | ||
/// <summary> | ||
/// 视频总数量 | ||
/// </summary> | ||
public int Count { get; set; } | ||
|
||
/// <summary> | ||
/// 页码 | ||
/// </summary> | ||
public int Pn { get; set; } | ||
/// <summary> | ||
/// 页码 | ||
/// </summary> | ||
public int Pn { get; set; } | ||
|
||
/// <summary> | ||
/// 每页条数 | ||
/// </summary> | ||
public int Ps { get; set; } | ||
} | ||
} | ||
/// <summary> | ||
/// 每页条数 | ||
/// </summary> | ||
public int Ps { get; set; } | ||
} |
Oops, something went wrong.