summary refs log tree commit diff
path: root/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2025-04-08 18:55:55 +0200
committerEmma [it/its]@Rory& <root@rory.gay>2025-10-05 21:34:40 +0200
commitabb1b570a4343d5e4fde34f55c1a2bf403f62981 (patch)
tree1986363f5bf369a03ee1f18ed3170da73d859c38 /extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor
parentRewrite access tokens, initial admin api (diff)
downloadserver-ts-abb1b570a4343d5e4fde34f55c1a2bf403f62981.tar.xz
Local changes
Diffstat (limited to 'extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor')
-rw-r--r--extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor61
1 files changed, 61 insertions, 0 deletions
diff --git a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor
new file mode 100644

index 000000000..084a372fe --- /dev/null +++ b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/UsersDelete.razor
@@ -0,0 +1,61 @@ +@page "/Users/Delete/{Id}" +@using System.Net.Http.Headers +@using System.Text.Json +@using System.Text.Json.Nodes +@using ArcaneLibs.Extensions +@using Spacebar.AdminApi.Models +@using Spacebar.AdminAPI.TestClient.Services +@inject Config Config +<h3>UsersDelete - @Id</h3> + +Deleted @ChannelDeleteProgress.Sum(x=>x.Value.Deleted) messages so far! +@foreach (var (channel, progress) in ChannelDeleteProgress.Where(x=>x.Value.Deleted != x.Value.Total).OrderByDescending(x=>x.Value.Progress)) { + <div>@channel: @progress.Total total, @progress.Deleted deleted</div> + <progress max="@progress.Total" value="@progress.Deleted"></progress> +} + +@code { + + [Parameter] + public required string Id { get; set; } + + private Dictionary<string, DeleteProgress> ChannelDeleteProgress { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + using var hc = new HttpClient(); + hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Config.AccessToken); + var response = await hc.GetAsync(Config.AdminUrl + $"/_spacebar/admin/Users/{Id}/delete?messageDeleteChunkSize=100"); + if (!response.IsSuccessStatusCode) throw new Exception(await response.Content.ReadAsStringAsync()); + var content = response.Content.ReadFromJsonAsAsyncEnumerable<AsyncActionResult>(); + await foreach (var actionResult in content) { + Console.WriteLine(actionResult.ToJson(indent: false)); + switch (actionResult.MessageType) { + case "STATS": { + var data = JsonSerializer.Deserialize<JsonObject>(actionResult.Data.ToJson()); + ChannelDeleteProgress = data!["messages_per_channel"]! + .Deserialize<Dictionary<string, int>>()! + .ToDictionary(x=>x.Key, x=>new DeleteProgress { Total = x.Value }); + break; + } + case "BULK_DELETED": { + var data = JsonSerializer.Deserialize<JsonObject>(actionResult.Data.ToJson()); + ChannelDeleteProgress[data!["channel_id"]!.ToString()].Deleted += data!["deleted"]!.GetValue<int>(); + break; + } + default: { + Console.WriteLine($"Unknown message type: {actionResult.MessageType}"); + break; + } + } + + StateHasChanged(); + await Task.Delay(1); + } + } + + private class DeleteProgress { + public int Total { get; set; } + public int Deleted { get; set; } = 0; + public float Progress => (float)Deleted / Total; + } +} \ No newline at end of file