diff --git a/src/CloudStoage.Domain/Etos/UploadingEto.cs b/src/CloudStoage.Domain/Etos/UploadingEto.cs new file mode 100644 index 0000000000000000000000000000000000000000..48d6749574fa90817fa8427c295e718d9011152c --- /dev/null +++ b/src/CloudStoage.Domain/Etos/UploadingEto.cs @@ -0,0 +1,26 @@ +namespace CloudStoage.Domain.Etos; + +public class UploadingEto +{ + public Guid Id { get; set; } + + /// + /// /文件名称 + /// + public string? FileName { get; set; } + + /// + /// 文件夹Id + /// + public Guid? StorageId { get; set; } + + /// + /// 长度 + /// + public long? Length { get; set; } + + /// + /// Stream + /// + public Stream Stream { get; set; } +} diff --git a/src/CloudStoage.Domain/HttpModule/Result/UserInfoDto.cs b/src/CloudStoage.Domain/HttpModule/Result/UserInfoDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..3ffa7e1e404e0f1087b73879be5b39d6b1bd90a0 --- /dev/null +++ b/src/CloudStoage.Domain/HttpModule/Result/UserInfoDto.cs @@ -0,0 +1,80 @@ +using CloudStorage.Domain.Shared; + +namespace CloudStoage.Domain.HttpModule.Result; + +public class UserInfoDto +{ + public Guid Id { get; set; } + + /// + /// 账号 + /// + public string? Account { get; set; } + + /// + /// 密码 + /// + public string? Password { get; set; } + + /// + /// 昵称 + /// + public string? Name { get; set; } + + /// + /// 简介 + /// + public string? BriefIntroduction { get; set; } + + /// + /// 微信openid + /// + public string? WeChatOpenId { get; set; } + + /// + /// 头像 + /// + public string? HeadPortraits { get; set; } + + /// + /// 性别 + /// + public SexType Sex { get; set; } + + /// + /// 状态 + /// + public UserStatus Status { get; set; } + + /// + /// 服务器文件 + /// + public string? CloudStorageRoot { get; set; } + + public DateTime CreationTime { get; } + + /// + /// 用户总大小 + /// + public long TotalSize { get; set; } + + /// + /// 已经使用大小 + /// + public long UsedSize { get; set; } = 0; + + /// + /// 使用占比 + /// + public int Percentage + { + get + { + if(UsedSize!=0 && TotalSize != 0) + { + return (int)((UsedSize / TotalSize) * 100); + } + return 0; + } + } +} diff --git a/src/CloudStoage.Domain/UploadingDto.cs b/src/CloudStoage.Domain/UploadingDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..1d5c52cc6f35f9f2d5b679c101c07f87fcae9504 --- /dev/null +++ b/src/CloudStoage.Domain/UploadingDto.cs @@ -0,0 +1,45 @@ +using CloudStorage.Domain.Shared; + +namespace CloudStoage.Domain; + +public class UploadingDto +{ + public Guid Id { get; set; } + + /// + /// /文件名称 + /// + public string? FileName { get; set; } + + /// + /// 长度 + /// + public long Length { get; set; } = 0; + + /// + /// 已经上传的大小 + /// + public long UploadingSize { get; set; } = 0; + + + /// + /// 上传状态 + /// + public UpdateStats Stats { get; set; } + + /// + /// 上传进度 + /// + public int Progress + { + get + { + if (UploadingSize == 0 || Length == 0) + { + return 0; + } + + return (int)((decimal)UploadingSize / (decimal)Length * 100m); + } + } +} diff --git a/src/CloudStorage.Applications/Apis/UserInfoApi.cs b/src/CloudStorage.Applications/Apis/UserInfoApi.cs index dab4e99d0db3ca0df844cbf89493bb8b3a83c91d..86009a56b564bd730d635162725eaf90b37d455a 100644 --- a/src/CloudStorage.Applications/Apis/UserInfoApi.cs +++ b/src/CloudStorage.Applications/Apis/UserInfoApi.cs @@ -1,9 +1,14 @@ -using Token.Module.Dependencys; +using CloudStoage.Domain.HttpModule; +using CloudStoage.Domain.HttpModule.Result; +using Newtonsoft.Json; +using Token.Module.Dependencys; namespace CloudStorage.Applications.Apis; -public class UserInfoApi : IScopedDependency +public class UserInfoApi : IScopedDependency { + private const string Name = "api/userinfo"; + private readonly IHttpClientFactory httpClientFactory; public UserInfoApi(IHttpClientFactory httpClientFactory) @@ -11,4 +16,18 @@ public class UserInfoApi : IScopedDependency this.httpClientFactory = httpClientFactory; } + /// + /// 获取用户基本信息 + /// + /// + public async Task GetAsync() + { + var httpclient = httpClientFactory.CreateClient(string.Empty); + + var data =await httpclient.GetStringAsync(Name); + + var result = JsonConvert.DeserializeObject>(data); + + return result.Data; + } } diff --git a/src/CloudStorage.Applications/CloudStorage.Applications.csproj b/src/CloudStorage.Applications/CloudStorage.Applications.csproj index c9d706542d199e920faa8e10006170da933ea938..94b19e6462cf2d3d560bb3c193d60d03af6dde80 100644 --- a/src/CloudStorage.Applications/CloudStorage.Applications.csproj +++ b/src/CloudStorage.Applications/CloudStorage.Applications.csproj @@ -19,10 +19,14 @@ + + + - + + diff --git a/src/CloudStorage.Applications/CloudStorageApplicationsModule.cs b/src/CloudStorage.Applications/CloudStorageApplicationsModule.cs index d8701d842126ef8df9f470dd99eaed4a64868cc7..b8737db6cbe2bca4449651b48958c04a8a880826 100644 --- a/src/CloudStorage.Applications/CloudStorageApplicationsModule.cs +++ b/src/CloudStorage.Applications/CloudStorageApplicationsModule.cs @@ -1,11 +1,14 @@ using CloudStoage.Domain; -using CloudStorage.Applications.Filter; using CloudStorage.Applications.Manage; -using System.Security.Authentication; +using CloudStorage.Domain.Shared; +using Token.EventBus; using Token.Module; +using Token.Module.Attributes; namespace CloudStorage.Applications; +[DependOn( + typeof(TokenEventBusModule))] public class CloudStorageApplicationsModule : TokenModule { public override async void ConfigureServices(IServiceCollection services) @@ -14,20 +17,21 @@ public class CloudStorageApplicationsModule : TokenModule .ConfigureHttpClient((services, x) => { var status = services.GetService(); - x.DefaultRequestHeaders.Add("Authorization", $"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJ1c2VyIjoie1wiQWNjb3VudFwiOlwiYWRtaW5cIixcIlBhc3N3b3JkXCI6XCJhZG1pblwiLFwiTmFtZVwiOlwiYWRtaW5cIixcIkJyaWVmSW50cm9kdWN0aW9uXCI6bnVsbCxcIldlQ2hhdE9wZW5JZFwiOm51bGwsXCJIZWFkUG9ydHJhaXRzXCI6bnVsbCxcIlNleFwiOjAsXCJTdGF0dXNcIjowLFwiQ2xvdWRTdG9yYWdlUm9vdFwiOlwiLi93d3dyb290L0Nsb3VkU3RvcmFnZVxcXFxhYzRkZWRmYTFlYmU0YzNhOWJmY2JmZGQ2NWQxZjNkMlwiLFwiSXNEZWxldGVkXCI6ZmFsc2UsXCJDcmVhdGlvblRpbWVcIjpcIjAwMDEtMDEtMDFUMDA6MDA6MDBcIixcIkV4dHJhUHJvcGVydGllc1wiOnt9LFwiQ29uY3VycmVuY3lTdGFtcFwiOlwiZjQwMGJiZThjZDI0NDlkNWEyNTFjZmMxM2FmMzEyOGNcIixcIklkXCI6XCI0OTU4MWRkNC0yYzM5LTQ2NzAtOTE5Yi01MjMyY2UwZTllM2VcIn0iLCJpZCI6IjQ5NTgxZGQ0LTJjMzktNDY3MC05MTliLTUyMzJjZTBlOWUzZSIsImV4cCI6MTc2MjEzNjE0OCwiaXNzIjoidG9rZW5odS50b3AiLCJhdWQiOiJ0b2tlbmh1LnRvcCJ9.D-EpFpkPvg8o4W2OF0ZbiKCv2mqqErfCmJ0bN8KJYD8"); + var token = services.GetRequiredService(); + x.DefaultRequestHeaders.Add(Constant.Authorization, $"Bearer " + token.Token); x.BaseAddress = new Uri(Constant.Api); - + }) .ConfigureHttpMessageHandlerBuilder(builder => { builder.PrimaryHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (m, c, ch, e) => true - - }; + + }; }); - await services.Initialize(); + await services.Initialize(); } } \ No newline at end of file diff --git a/src/CloudStorage.Applications/EventHandle/UploadingEventBus.cs b/src/CloudStorage.Applications/EventHandle/UploadingEventBus.cs new file mode 100644 index 0000000000000000000000000000000000000000..48d4b0dd004f62eb372f5b8d45a8aa76c96c1ce2 --- /dev/null +++ b/src/CloudStorage.Applications/EventHandle/UploadingEventBus.cs @@ -0,0 +1,109 @@ +using CloudStoage.Domain; +using CloudStoage.Domain.Etos; +using CloudStorage.Applications.Helpers; +using CloudStorage.Domain.Shared; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.SignalR.Client; +using Newtonsoft.Json; +using System.Collections.Concurrent; +using System.Threading.Channels; +using Token.EventBus; +using Token.EventBus.Handlers; +using Token.Module.Dependencys; + +namespace CloudStorage.Applications.EventHandle; + +public class UploadingEventBus : ILocalEventHandler>, ISingletonDependency +{ + public BlockingCollection UploadingList { get; set; } = new BlockingCollection(); + + private readonly IKeyLocalEventBus> KeyLocalEventBus; + private readonly IKeyLocalEventBus DistributedEventBus; + + private readonly TokenManage token; + + private readonly HtttpClientHelper _htttpClientHelper; + + private HubConnection connection; + + public UploadingEventBus(HtttpClientHelper htttpClientHelper, IKeyLocalEventBus> keyLocalEventBus, TokenManage token, IKeyLocalEventBus distributedEventBus) + { + _htttpClientHelper = htttpClientHelper; + KeyLocalEventBus = keyLocalEventBus; + this.token = token; + DistributedEventBus = distributedEventBus; + } + + public async Task HandleEventAsync(List eventData) + { + if (connection == null || connection.State != HubConnectionState.Connected) + { + connection = new HubConnectionBuilder() + .WithUrl(Constant.Api + "/file-stream", option => + { + option.AccessTokenProvider = () => Task.FromResult(token.Token); + }) + .AddJsonProtocol() + .Build(); + + await connection.StartAsync(); + } + + eventData.ForEach(x => + { + UploadingList.Add(new UploadingDto + { + Id = x.Id, + FileName = x.FileName, + Length = x.Length ?? 0, + Stats = UpdateStats.BeUploading + }); + }); + + int size = (1024 * 10); + foreach (var item in eventData) + { + int length = (int)(item.Length / size); + var channel = Channel.CreateBounded(length+1); + + // 建立传输通道 + await connection.SendAsync("FileStreamSaveAsync", channel.Reader, JsonConvert.SerializeObject(new + { + StorageId = item.StorageId, + FileName = item.FileName, + Length = item.Length + })); + + var bytesTransferred = 0; + + // 定义下载缓存 + var b = new byte[size]; + int len; + while ((len = await item.Stream.ReadAsync(b)) != 0) + { + + await channel.Writer.WriteAsync(b); + bytesTransferred += len; + await UploadingSizeEvent(item.Id, bytesTransferred); + } + + // 传输完成结束通道 + channel.Writer.Complete(); + await DistributedEventBus.PublishAsync("Storages", "上传文件成功"); + } + } + + private async Task UploadingSizeEvent(Guid id, int BytesTransferred) + { + foreach (var d in UploadingList) + { + if (d.Id == id) + { + d.UploadingSize = BytesTransferred; + await KeyLocalEventBus.PublishAsync(KeyLoadNames.UploadingListName, new Tuple(BytesTransferred, id)); + return; + } + } + } + +} diff --git a/src/CloudStorage.Applications/Helpers/CommonHelper.cs b/src/CloudStorage.Applications/Helpers/CommonHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..6b1ef146d17a978bd95a4cabbc23a777e0204470 --- /dev/null +++ b/src/CloudStorage.Applications/Helpers/CommonHelper.cs @@ -0,0 +1,25 @@ +using Token.Module.Dependencys; + +namespace CloudStorage.Applications.Helpers; + +public class CommonHelper : IScopedDependency +{ + public string GetFileSize(long? size) + { + if (size == null) + return ""; + + var num = 1024.00; //byte + + if (size < num) + return size + "B"; + if (size < Math.Pow(num, 2)) + return ((long)size / num).ToString("f2") + "K"; //kb + if (size < Math.Pow(num, 3)) + return ((long)size / Math.Pow(num, 2)).ToString("f2") + "M"; //M + if (size < Math.Pow(num, 4)) + return ((long)size / Math.Pow(num, 3)).ToString("f2") + "G"; //G + + return ((long)size / Math.Pow(num, 4)).ToString("f2") + "T"; //T + } +} diff --git a/src/CloudStorage.Applications/Helpers/HtttpClientHelper.cs b/src/CloudStorage.Applications/Helpers/HtttpClientHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..31609b8dc05b29b43218a5d1df342327571761a6 --- /dev/null +++ b/src/CloudStorage.Applications/Helpers/HtttpClientHelper.cs @@ -0,0 +1,43 @@ +using CloudStoage.Domain; +using CloudStoage.Domain.Etos; +using Microsoft.AspNetCore.Components.Forms; +using System.Net.Http.Handlers; +using Token.Module.Dependencys; + +namespace CloudStorage.Applications.Helpers; + +public class HtttpClientHelper : IScopedDependency +{ + private const string Name = "api/storage"; + + private readonly IHttpClientFactory httpClientFactory; + + public HtttpClientHelper(IHttpClientFactory httpClientFactory) + { + this.httpClientFactory = httpClientFactory; + } + + public async Task UpdateRand(UploadingEto files, EventHandler eventHandler = null) + { + var http = httpClientFactory.CreateClient(string.Empty); + HttpClientHandler handler = new(); + ProgressMessageHandler progressMessageHandler = new(handler); + progressMessageHandler.HttpSendProgress += eventHandler; + + using HttpClient httpClient = new(progressMessageHandler); + + httpClient.BaseAddress = new Uri(Constant.Api); + httpClient.DefaultRequestHeaders + .Add(Constant.Authorization, http.DefaultRequestHeaders.FirstOrDefault(x => x.Key == Constant.Authorization).Value); + httpClient.DefaultRequestHeaders.Add("id", files.Id.ToString()); + + using var multipartFormData = new MultipartFormDataContent + { + { new StreamContent(files.Stream), "file", files.FileName } + }; + + var response = await httpClient.PostAsync(Name + "/upload-file?storageId=" + files.StorageId, multipartFormData); + + } + +} diff --git a/src/CloudStorage.Applications/Manage/TokenStats.cs b/src/CloudStorage.Applications/Manage/TokenStats.cs new file mode 100644 index 0000000000000000000000000000000000000000..bd9c9f98c16e2a175b917460487376db496eb117 --- /dev/null +++ b/src/CloudStorage.Applications/Manage/TokenStats.cs @@ -0,0 +1,8 @@ +using Token.Module.Dependencys; + +namespace CloudStorage.Domain.Shared; + +public class TokenManage : IScopedDependency +{ + public string Token { get; set; } = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJ1c2VyIjoie1wiQWNjb3VudFwiOlwiYWRtaW5cIixcIlBhc3N3b3JkXCI6XCJhZG1pblwiLFwiTmFtZVwiOlwiYWRtaW5cIixcIkJyaWVmSW50cm9kdWN0aW9uXCI6bnVsbCxcIldlQ2hhdE9wZW5JZFwiOm51bGwsXCJIZWFkUG9ydHJhaXRzXCI6XCJodHRwczovL3RzMS5jbi5tbS5iaW5nLm5ldC90aD9pZD1PSVAtQy5JYmdZY2JDSGZVVXRmd2VHTUtBalR3QUFBQSZ3PTI1MCZoPTI1MCZjPTgmcnM9MSZxbHQ9OTAmbz02JnBpZD0zLjEmcm09MlwiLFwiU2V4XCI6MCxcIlN0YXR1c1wiOjAsXCJDbG91ZFN0b3JhZ2VSb290XCI6XCIuL3d3d3Jvb3QvQ2xvdWRTdG9yYWdlL2FjNGRlZGZhMWViZTRjM2E5YmZjYmZkZDY1ZDFmM2QyXCIsXCJJc0RlbGV0ZWRcIjpmYWxzZSxcIkNyZWF0aW9uVGltZVwiOlwiMDAwMS0wMS0wMVQwMDowMDowMFwiLFwiRXh0cmFQcm9wZXJ0aWVzXCI6e30sXCJDb25jdXJyZW5jeVN0YW1wXCI6XCJmNDAwYmJlOGNkMjQ0OWQ1YTI1MWNmYzEzYWYzMTI4Y1wiLFwiSWRcIjpcIjQ5NTgxZGQ0LTJjMzktNDY3MC05MTliLTUyMzJjZTBlOWUzZVwifSIsImlkIjoiNDk1ODFkZDQtMmMzOS00NjcwLTkxOWItNTIzMmNlMGU5ZTNlIiwiZXhwIjoxNzYyMjI2NDM0LCJpc3MiOiJ0b2tlbmh1LnRvcCIsImF1ZCI6InRva2VuaHUudG9wIn0.Qga-H-eKWrguw6ojk3ps1lW0sdx2XVxfmlZPvtjAWSg"; +} diff --git a/src/CloudStorage.Domain.Shared/Constant.cs b/src/CloudStorage.Domain.Shared/Constant.cs index 9451de8df0f3bbd8c381420c128cc4753f65a837..8ba50364f6ea92c1ce5d543bb54b85e6c7c01f66 100644 --- a/src/CloudStorage.Domain.Shared/Constant.cs +++ b/src/CloudStorage.Domain.Shared/Constant.cs @@ -4,10 +4,16 @@ public class Constant { public const string Token = "token"; +#if DEBUG + public const string Api = "https://localhost:8081"; +#else public const string Api = "https://tokenhu.top"; +#endif public const string DateTimeStr = "yyyy-MM-dd HH-mm-ss"; + public const string Authorization = "Authorization"; + /// /// 响应状态码 /// diff --git a/src/CloudStorage.Domain.Shared/KeyLoadNames.cs b/src/CloudStorage.Domain.Shared/KeyLoadNames.cs new file mode 100644 index 0000000000000000000000000000000000000000..a91c23f1ad300fab55ccee51c44e72fc0667c340 --- /dev/null +++ b/src/CloudStorage.Domain.Shared/KeyLoadNames.cs @@ -0,0 +1,6 @@ +namespace CloudStorage.Domain.Shared; + +public class KeyLoadNames +{ + public const string UploadingListName = "UploadingListName"; +} diff --git a/src/CloudStorage.Domain.Shared/UpdateStats.cs b/src/CloudStorage.Domain.Shared/UpdateStats.cs new file mode 100644 index 0000000000000000000000000000000000000000..51b68c49d343b49928d1446574045e5adb46ee49 --- /dev/null +++ b/src/CloudStorage.Domain.Shared/UpdateStats.cs @@ -0,0 +1,24 @@ +namespace CloudStorage.Domain.Shared; + +public enum UpdateStats +{ + /// + /// 正在上传 + /// + BeUploading = 0, + + /// + /// 成功 + /// + Succeed, + + /// + /// 失败 + /// + Failure, + + /// + /// 暂停 + /// + Suspend +} diff --git a/src/CloudStorage.Layou/CloudStorage.Layou.csproj b/src/CloudStorage.Layou/CloudStorage.Layou.csproj index 000809db77a596038f6c1eb9a5391c12fb7728a7..9b596e9f0d4800ed02ac17bdf780054639c585e0 100644 --- a/src/CloudStorage.Layou/CloudStorage.Layou.csproj +++ b/src/CloudStorage.Layou/CloudStorage.Layou.csproj @@ -12,10 +12,10 @@ - + - - + + diff --git a/src/CloudStorage.Layou/CloudStorageLayouModule.cs b/src/CloudStorage.Layou/CloudStorageLayouModule.cs index 31f31208ece6af9626917f146906907c15abf39c..c187919fbaa04dd843f8983d58acdcf6e8bbacbe 100644 --- a/src/CloudStorage.Layou/CloudStorageLayouModule.cs +++ b/src/CloudStorage.Layou/CloudStorageLayouModule.cs @@ -7,12 +7,12 @@ using Token.Module.Attributes; namespace CloudStorage.Layou; [DependOn( + typeof(TokenEventBusModule), typeof(CloudStorageApplicationsModule))] public class CloudStorageLayouModule : TokenModule { public override void ConfigureServices(IServiceCollection services) { - services.AddEventBus(); services.AddMasaBlazor(); } } diff --git a/src/CloudStorage.Layou/Components/CreateFolder.razor.cs b/src/CloudStorage.Layou/Components/CreateFolder.razor.cs index 7499d0858f87ab50494b043c17f4bfa203c510e2..eae78d4a76c9e4b20ea86f8881008b3655f602e3 100644 --- a/src/CloudStorage.Layou/Components/CreateFolder.razor.cs +++ b/src/CloudStorage.Layou/Components/CreateFolder.razor.cs @@ -32,7 +32,7 @@ partial class CreateFolder [Inject] public StorageApi StorageApi { get; set; } [Inject] - public IDistributedEventBus DistributedEventBus { get; set; } + public IKeyLocalEventBus DistributedEventBus { get; set; } /// /// 创建文件夹事件 diff --git a/src/CloudStorage.Layou/Components/FileFunction.razor.cs b/src/CloudStorage.Layou/Components/FileFunction.razor.cs index 4ef7210befd5e50c045f86fadcfd248b5f68d16b..9410290c37bcba7874177738aa52b302a96560d0 100644 --- a/src/CloudStorage.Layou/Components/FileFunction.razor.cs +++ b/src/CloudStorage.Layou/Components/FileFunction.razor.cs @@ -15,12 +15,12 @@ partial class FileFunction public StorageApi StorageApi { get; set; } [Inject] - public IDistributedEventBus DistributedEventBus { get; set; } + public IKeyLocalEventBus DistributedEventBus { get; set; } private async void DeleteFileAsync() { await StorageApi.DeleteStorageAsync(StorageId); - await DistributedEventBus.PublishAsync(nameof(Storagefile.HasFybctuib), false); + await DistributedEventBus.PublishAsync("HasFybctuib", false); } } diff --git a/src/CloudStorage.Layou/Components/MenuList.razor b/src/CloudStorage.Layou/Components/MenuList.razor index 41d97c24f860649558534ab7c336b54fc8bf8d12..995cd06122be0a89c189f8eefdf76d8e939652ef 100644 --- a/src/CloudStorage.Layou/Components/MenuList.razor +++ b/src/CloudStorage.Layou/Components/MenuList.razor @@ -4,6 +4,7 @@ + diff --git a/src/CloudStorage.Layou/Components/Storagefile.razor.cs b/src/CloudStorage.Layou/Components/Storagefile.razor.cs index 796ee3b5d0976fff9e84e8fd6d65c481622168b6..b589825aaf3b1a29980a3b55c05f7604c9dcb085 100644 --- a/src/CloudStorage.Layou/Components/Storagefile.razor.cs +++ b/src/CloudStorage.Layou/Components/Storagefile.razor.cs @@ -1,13 +1,24 @@ using CloudStoage.Domain.HttpModule.Result; +using CloudStorage.Layou.Pages; using Token.EventBus; namespace CloudStorage.Layou.Components; partial class Storagefile { + private bool hasFybctuib; + [Parameter] - public bool HasFybctuib { get; set; } + public bool HasFybctuib + { + get { return hasFybctuib; } + set + { + hasFybctuib = value; + ValueChange.InvokeAsync(value); + } + } [Parameter] public EventCallback ValueChange { get; set; } @@ -22,7 +33,10 @@ partial class Storagefile public StorageApi StorageApi { get; set; } [Inject] - public IDistributedEventBus DistributedEventBus { get; set; } + public IKeyLocalEventBus DistributedEventBus { get; set; } + + [Inject] + public IKeyLocalEventBus StringDstributedEventBus { get; set; } /// /// Ϣ @@ -31,14 +45,16 @@ partial class Storagefile public override async Task SetParametersAsync(ParameterView parameters) { - - parameters.TryGetValue(nameof(StorageId), out Guid? storageId); if (storageId == null) return; parameters.TryGetValue(nameof(HasFybctuib), out bool hasFybctuib); + if (hasFybctuib == HasFybctuib) + { + return; + } HasFybctuib = hasFybctuib; parameters.TryGetValue(nameof(ValueChange), out EventCallback valueChange); @@ -47,22 +63,21 @@ partial class Storagefile await GetStorageAsync(storageId); - StateHasChanged(); - } - - protected override async Task OnInitializedAsync() - { await HasFybctuibAsync(); + + StateHasChanged(); } private async Task HasFybctuibAsync() { - await DistributedEventBus.Subscribe(nameof(HasFybctuib), (data) => + await DistributedEventBus.Subscribe("HasFybctuib", async (data) => { var result = data as bool?; if (result != null) { HasFybctuib = (bool)result; + StateHasChanged(); + await StringDstributedEventBus.PublishAsync(nameof(Storages),"ɾļɹ"); } }); } diff --git a/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor new file mode 100644 index 0000000000000000000000000000000000000000..03d20098709acf6eee3aecbd0a68196f835b5564 --- /dev/null +++ b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor @@ -0,0 +1,28 @@ +
+ @foreach (var d in UploadingList) + { + +
@d.FileName
+ + + @(d.Progress)% + + +
+ } +
+ + + \ No newline at end of file diff --git a/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.cs b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.cs new file mode 100644 index 0000000000000000000000000000000000000000..94856317e97054365b1fcf479dcf4a6de019e3a7 --- /dev/null +++ b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.cs @@ -0,0 +1,42 @@ +using CloudStoage.Domain; +using CloudStorage.Applications.EventHandle; +using CloudStorage.Domain.Shared; +using System.Collections.Concurrent; +using System.Drawing; +using Token.EventBus; + +namespace CloudStorage.Layou.Components.Uploads +{ + partial class UploadTheList + { + [Inject] + public UploadingEventBus UploadingEventBus { get; set; } + + [Inject] + public IKeyLocalEventBus> UploadTheListEventBus { get; set; } + + public static BlockingCollection UploadingList { get; set; } + + protected override async void OnInitialized() + { + + UploadingList = UploadingEventBus.UploadingList; + + + await UploadTheListEventBus.Subscribe(KeyLoadNames.UploadingListName, a => + { + foreach (var d in UploadingList) + { + if (d.Id == a.Item2) + { + d.UploadingSize = a.Item1; + StateHasChanged(); + return; + } + } + + }); + + } + } +} diff --git a/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.css b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.css new file mode 100644 index 0000000000000000000000000000000000000000..5f282702bb03ef11d7184d19c80927b47f919764 --- /dev/null +++ b/src/CloudStorage.Layou/Components/Uploads/UploadTheList.razor.css @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/CloudStorage.Layou/Pages/PersonalCenter.razor b/src/CloudStorage.Layou/Pages/PersonalCenter.razor index f310e16d39ed9f78ae817f798aa24f96f6873f3b..101a76f38c94b39c864503cdf3271fa319e99cc1 100644 --- a/src/CloudStorage.Layou/Pages/PersonalCenter.razor +++ b/src/CloudStorage.Layou/Pages/PersonalCenter.razor @@ -6,57 +6,57 @@ + Src="@UserInfo.HeadPortraits">
- 可用空间440MB/100GB -
+ 已使用@(CommonHelper.GetFileSize(UserInfo?.UsedSize))/@(CommonHelper.GetFileSize(UserInfo?.TotalSize)) + -
+
- - - - - + + + + - - 编辑个人资料 - - - + + 编辑个人资料 + + + - + - 设置 + 设置 - + - - - - + + + + - - 退出登录 - - - - + + 退出登录 + + + + +
- diff --git a/src/CloudStorage.Layou/Pages/PersonalCenter.razor.cs b/src/CloudStorage.Layou/Pages/PersonalCenter.razor.cs index 76b561051c65429ef3241508ce0e389f25556672..0dfb2c6e6ea77779b057dc85d338b6ff80f4e301 100644 --- a/src/CloudStorage.Layou/Pages/PersonalCenter.razor.cs +++ b/src/CloudStorage.Layou/Pages/PersonalCenter.razor.cs @@ -1,14 +1,32 @@ -using Microsoft.AspNetCore.Components.Web; +using CloudStoage.Domain.HttpModule.Result; +using CloudStorage.Applications.Helpers; namespace CloudStorage.Layou.Pages; partial class PersonalCenter { + private UserInfoDto? UserInfo { get; set; } =new UserInfoDto(); [Inject] public NavigationManager? Navigation { get; set; } + [Inject] + public CommonHelper CommonHelper { get; set; } + + [Inject] + public UserInfoApi UserInfoApi { get; set; } + private void OnLogoutClick(MouseEventArgs args) { Navigation?.NavigateTo("/login"); } + + protected override async Task OnInitializedAsync() + { + await GetUserInfoAsync(); + } + + private async Task GetUserInfoAsync() + { + UserInfo = await UserInfoApi.GetAsync(); + } } diff --git a/src/CloudStorage.Layou/Pages/Storages.razor.cs b/src/CloudStorage.Layou/Pages/Storages.razor.cs index 752a786054b9988f92c89d8191c44d51e945fb72..a801c9dcf0ae8c9eb180ef8ba763c2a2e9ee3c3d 100644 --- a/src/CloudStorage.Layou/Pages/Storages.razor.cs +++ b/src/CloudStorage.Layou/Pages/Storages.razor.cs @@ -1,10 +1,14 @@ +using CloudStoage.Domain.Etos; using CloudStoage.Domain.HttpModule.Input; using CloudStoage.Domain.HttpModule.Result; -using CloudStorage.Layou.Components; +using CloudStorage.Applications.Helpers; using CloudStorage.Layou.Helper; +using Masa.Blazor; using Microsoft.AspNetCore.Components.Forms; -using Microsoft.JSInterop; +using System.Diagnostics; +using System.Net.Http.Handlers; using Token.EventBus; +using Token.EventBus.EventBus; namespace CloudStorage.Layou.Pages; @@ -27,7 +31,13 @@ partial class Storages public PagedResultDto StorageList { get; set; } = new PagedResultDto(); [Inject] - public IDistributedEventBus DistributedEventBus { get; set; } + public IKeyLocalEventBus DistributedEventBus { get; set; } + + [Inject] + public ILocalEventBus LocalEventBus { get; set; } + + [Inject] + public IPopupService PopupService { get; set; } /// /// js @@ -38,6 +48,9 @@ partial class Storages [Inject] public StorageApi StorageApi { get; set; } + [Inject] + public HtttpClientHelper HtttpClientHelper { get; set; } + public const string inputFileId = "inputfile"; private async Task ClickInputFileAsync() @@ -110,9 +123,19 @@ partial class Storages var files = eventArgs.GetMultipleFiles(10); if (files.Count > 0) { - await StorageApi.UploadFileListAsync(files, GetStorageListInput.StorageId); - await GetStorageListAsync(); + await PopupService.ToastAsync("ϴļ", BlazorComponent.AlertTypes.Info); + var uploadings = files.Select(x => new UploadingEto + { + Id = Guid.NewGuid(), + FileName = x.Name, + Length = x.Size, + StorageId= GetStorageListInput.StorageId, + Stream = x.OpenReadStream(x.Size) + }).ToList(); + + await LocalEventBus.PublishAsync(uploadings,false); StateHasChanged(); } } + } \ No newline at end of file diff --git a/src/CloudStorage.Layou/Pages/Uploading.razor b/src/CloudStorage.Layou/Pages/Uploading.razor new file mode 100644 index 0000000000000000000000000000000000000000..a88e457e3bb5818bc071635968ba9b9832210088 --- /dev/null +++ b/src/CloudStorage.Layou/Pages/Uploading.razor @@ -0,0 +1,11 @@ +@page "/Uploading" +@using CloudStorage.Layou.Components.Uploads + + + 上传列表 + 下载列表 + 上传记录 + 下载记录 + + + \ No newline at end of file