Skip to content

Commit

Permalink
1.增加cancellationToken
Browse files Browse the repository at this point in the history
2.增加分段获取数据以及获取文件大小方法
  • Loading branch information
j4587698 committed Apr 8, 2024
1 parent 5f02625 commit 8a42c5c
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 63 deletions.
2 changes: 1 addition & 1 deletion AListSdkSharp/AListSdkSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>AList .Net Sdk</Description>
<PackageProjectUrl>https://github.com/j4587698/AListSdkSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/j4587698/AListSdkSharp</RepositoryUrl>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 17 additions & 11 deletions AListSdkSharp/Api/Auth.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using AListSdkSharp.Vo;
using Flurl.Http;
Expand All @@ -16,17 +17,18 @@ public Auth(string baseUrl)
{
_baseUri = new Uri(baseUrl);
}

/// <summary>
/// 登录
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Login> Login(string username, string password)
public Task<Login> Login(string username, string password, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, "/api/auth/login")
.PostJsonAsync(new { username, password })
.PostJsonAsync(new { username, password }, cancellationToken: cancellationToken)
.ReceiveJson<Login>();
}

Expand All @@ -36,23 +38,25 @@ public Task<Login> Login(string username, string password)
/// <param name="username"></param>
/// <param name="passwordHash"></param>
/// <param name="optCode"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Login> LoginHash(string username, string passwordHash, string optCode)
public Task<Login> LoginHash(string username, string passwordHash, string optCode, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, "/api/auth/login/hash")
.PostJsonAsync(new { username, password = passwordHash, otp_code= optCode })
.PostJsonAsync(new { username, password = passwordHash, otp_code= optCode }, cancellationToken: cancellationToken)
.ReceiveJson<Login>();
}

/// <summary>
/// 创建2FA认证
/// </summary>
/// <param name="token"></param>
public Task<FaOut> Generate2FA(string token)
/// <param name="cancellationToken"></param>
public Task<FaOut> Generate2FA(string token, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, "/api/auth/2fa/generate")
.WithHeader("Authorization", token)
.PostAsync()
.PostAsync(cancellationToken: cancellationToken)
.ReceiveJson<FaOut>();
}

Expand All @@ -62,25 +66,27 @@ public Task<FaOut> Generate2FA(string token)
/// <param name="token"></param>
/// <param name="code"></param>
/// <param name="secret"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Base> Verify2FA(string token, string code, string secret)
public Task<Base> Verify2FA(string token, string code, string secret, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, "/api/auth/2fa/verify")
.WithHeader("Authorization", token)
.PostJsonAsync(new { code, secret })
.PostJsonAsync(new { code, secret }, cancellationToken: cancellationToken)
.ReceiveJson<Base>();
}

/// <summary>
/// 获取用户信息
/// </summary>
/// <param name="token"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<UserInfoOut> GetUserInfo(string token)
public Task<UserInfoOut> GetUserInfo(string token, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, "/api/me")
.WithHeader("Authorization", token)
.GetAsync()
.GetAsync(cancellationToken: cancellationToken)
.ReceiveJson<UserInfoOut>();
}
}
Expand Down
Loading

0 comments on commit 8a42c5c

Please sign in to comment.