Skip to content

Commit

Permalink
Merge pull request #3 from j4587698/feat-download
Browse files Browse the repository at this point in the history
更新1.1.4版本,增加headers参数
  • Loading branch information
j4587698 authored Jul 24, 2024
2 parents 812fc19 + a95ba1f commit a321e29
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 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.3</Version>
<Version>1.1.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 12 additions & 7 deletions AListSdkSharp/Api/Fs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,52 +282,57 @@ public Task<Base> AddQBit(string token, string path, string[] urls, Cancellation
/// </summary>
/// <param name="rawUrl"></param>
/// <param name="cancellationToken"></param>
/// <param name="headers"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public Task<Stream> Download(string rawUrl, CancellationToken cancellationToken = default)
public Task<Stream> Download(string rawUrl, CancellationToken cancellationToken = default, params (string key, string value)[] headers)
{
if (rawUrl == null)
{
throw new Exception("raw url is null");
}
return rawUrl.GetStreamAsync(cancellationToken: cancellationToken);
var request = rawUrl.WithHeaders(headers);
return request.GetStreamAsync(cancellationToken: cancellationToken);
}

/// <summary>
/// 下载文件
/// </summary>
/// <param name="infoOut"></param>
/// <param name="cancellationToken"></param>
/// <param name="headers"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public Task<Stream> Download(InfoOut infoOut, CancellationToken cancellationToken = default)
public Task<Stream> Download(InfoOut infoOut, CancellationToken cancellationToken = default, params (string key, string value)[] headers)
{
if (infoOut.Code != 200)
{
throw new Exception(infoOut.Message);
}

return Download(infoOut.Data.RawUrl, cancellationToken);
return Download(infoOut.Data.RawUrl, cancellationToken, headers);
}

/// <summary>
/// 分段下载
/// </summary>
/// <param name="rawUrl"></param>
/// <param name="position"></param>
/// <param name="count"></param>
/// <param name="cancellationToken"></param>
/// <param name="headers"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
/// <exception cref="InvalidOperationException"></exception>
public async Task<Stream> RangeDownload(string rawUrl, long position, long count, CancellationToken cancellationToken = default)
public async Task<Stream> RangeDownload(string rawUrl, long position, long count,
CancellationToken cancellationToken = default, params (string key, string value)[] headers)
{
if (rawUrl == null)
{
throw new Exception("raw url is null");
}

var response = await rawUrl
var response = await rawUrl.WithHeaders(headers)
.WithHeader("Range", $"bytes={position}-{position + count - 1}")
.GetAsync(HttpCompletionOption.ResponseHeadersRead, cancellationToken: cancellationToken);

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

AListSdkSharp 是C#的AList SDK访问层,用于访问AList的API。
使用flurl作为http请求库。
version 1.1.4:
Download支持headers参数

version 1.1.3:

删除fs中Related字段,解决Related不为string的问题
Expand Down

0 comments on commit a321e29

Please sign in to comment.