Skip to content

Commit

Permalink
Merge pull request #8 from j4587698/feat-storage
Browse files Browse the repository at this point in the history
feat: 增加存储相关操作
  • Loading branch information
j4587698 authored Oct 17, 2024
2 parents e84711c + 67bdbf8 commit b955185
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 2 deletions.
10 changes: 8 additions & 2 deletions AListSdkSharp/AListSdkSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
<Description>AList .Net Sdk</Description>
<PackageProjectUrl>https://github.com/j4587698/AListSdkSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/j4587698/AListSdkSharp</RepositoryUrl>
<Version>1.1.5</Version>
<Version>1.1.3</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="4.0.2" />
</ItemGroup>


<ItemGroup>
<None Include="README.md">
<Pack>true</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>
63 changes: 63 additions & 0 deletions AListSdkSharp/Api/Storage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using AListSdkSharp.Vo;
using Flurl.Http;

namespace AListSdkSharp.Api
{
public class Storage
{
private readonly Uri _baseUri;

public Storage(string baseUrl)
{
_baseUri = new Uri(baseUrl);
}

/// <summary>
/// 获取所有存储列表
/// </summary>
/// <param name="token"></param>
/// <param name="page">页码,默认为null</param>
/// <param name="prePage">每页条数,默认为null</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<StorageListOut> List(string token, int? page = null, int? prePage = null, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, $"/api/admin/storage/list?page={page}&prePage={prePage}")
.WithHeader("Authorization", token)
.GetJsonAsync<StorageListOut>(cancellationToken: cancellationToken);
}

/// <summary>
/// 启用存储
/// </summary>
/// <param name="token"></param>
/// <param name="id">存储id,从list中获取</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Base> Enable(string token, int id, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, $"/api/admin/storage/enable?id={id}")
.WithHeader("Authorization", token)
.PostAsync(cancellationToken: cancellationToken)
.ReceiveJson<Base>();
}

/// <summary>
/// 禁用存储
/// </summary>
/// <param name="token"></param>
/// <param name="id">存储id,从list中获取</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<Base> Disable(string token, int id, CancellationToken cancellationToken = default)
{
return new Uri(_baseUri, $"/api/admin/storage/disable?id={id}")
.WithHeader("Authorization", token)
.PostAsync(cancellationToken: cancellationToken)
.ReceiveJson<Base>();
}
}
}
65 changes: 65 additions & 0 deletions AListSdkSharp/Vo/StorageListOut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace AListSdkSharp.Vo
{
public class StorageListOut: Base
{
public StorageListOutData Data { get; set; }

public class StorageListOutData
{
public List<StorageListOutContent> Content { get; set; }

public int Total { get; set; }
}

public class StorageListOutContent
{
public int Id { get; set; }

[JsonPropertyName("mount_path")]
public string MountPath { get; set; }

public int Order { get; set; }

public string Driver { get; set; }

[JsonPropertyName("cache_expiration")]
public int CacheExpiration { get; set; }

public string Status { get; set; }

public string Addition { get; set; }

public string Remark { get; set; }

public DateTime Modified { get; set; }

public bool Disabled { get; set; }

[JsonPropertyName("enable_sign")]
public bool EnableSign { get; set; }

[JsonPropertyName("order_by")]
public string OrderBy { get; set; }

[JsonPropertyName("order_direction")]
public string OrderDirection { get; set; }

[JsonPropertyName("extract_folder")]
public string ExtractFolder { get; set; }

[JsonPropertyName("web_proxy")]
public bool WebProxy { get; set; }

[JsonPropertyName("webdav_policy")]
public string WebdavPolicy { get; set; }

[JsonPropertyName("down_proxy_url")]
public string DownProxyUrl { get; set; }
}
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ var file = File.Create("文件");
await stream.CopyToAsync(file);
file.Close();

// 存储相关
var storage = new Storage(baseUrl); // 创建一个Storage对象
var b = await storage.List(token); // 获取文件列表
var d = await storage.Disable(token, 2); // 禁用指定id的存储
var c = await storage.Enable(token, 2); // 启用指定id的存储
```

0 comments on commit b955185

Please sign in to comment.