diff --git a/AListSdkSharp/AListSdkSharp.csproj b/AListSdkSharp/AListSdkSharp.csproj index b5dab75..5375d54 100644 --- a/AListSdkSharp/AListSdkSharp.csproj +++ b/AListSdkSharp/AListSdkSharp.csproj @@ -6,11 +6,17 @@ AList .Net Sdk https://github.com/j4587698/AListSdkSharp https://github.com/j4587698/AListSdkSharp - 1.1.5 + 1.1.3 - + + + + true + \ + + diff --git a/AListSdkSharp/Api/Storage.cs b/AListSdkSharp/Api/Storage.cs new file mode 100644 index 0000000..86a883e --- /dev/null +++ b/AListSdkSharp/Api/Storage.cs @@ -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); + } + + /// + /// 获取所有存储列表 + /// + /// + /// 页码,默认为null + /// 每页条数,默认为null + /// + /// + public Task 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(cancellationToken: cancellationToken); + } + + /// + /// 启用存储 + /// + /// + /// 存储id,从list中获取 + /// + /// + public Task 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(); + } + + /// + /// 禁用存储 + /// + /// + /// 存储id,从list中获取 + /// + /// + public Task 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(); + } + } +} \ No newline at end of file diff --git a/AListSdkSharp/Vo/StorageListOut.cs b/AListSdkSharp/Vo/StorageListOut.cs new file mode 100644 index 0000000..5a7955e --- /dev/null +++ b/AListSdkSharp/Vo/StorageListOut.cs @@ -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 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; } + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 0ac2d65..dec3c4d 100644 --- a/README.md +++ b/README.md @@ -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的存储 + ```