diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-19 07:21:41 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-19 07:21:41 +0200 |
commit | 063fb6f12aea3a5b71c05beea22e7f6482c2f1cf (patch) | |
tree | 064aa9edd5a27017f95ed0a6b19ac69499005778 /MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor | |
parent | Add user management page (diff) | |
download | MatrixUtils-063fb6f12aea3a5b71c05beea22e7f6482c2f1cf.tar.xz |
Refactor, fix stuff
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor b/MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor new file mode 100644 index 0000000..f7e6aec --- /dev/null +++ b/MatrixRoomUtils.Web/Pages/Dev/DevUtilities.razor @@ -0,0 +1,79 @@ +@page "/Dev/Utilities" +@using System.Reflection +@using ArcaneLibs.Extensions +@using LibMatrix.Extensions +@using LibMatrix.Homeservers +@inject ILocalStorageService LocalStorage +@inject NavigationManager NavigationManager +<h3>Debug Tools</h3> +<hr/> +@if (Rooms.Count == 0) { + <p>You are not in any rooms!</p> + @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@ +} +else { + <details> + <summary>Room List</summary> + @foreach (var room in Rooms) { + <a style="color: unset; text-decoration: unset;" href="/RoomStateViewer/@room.Replace('.', '~')"> + <RoomListItem RoomId="@room"></RoomListItem> + </a> + } + </details> +} + +<details open> + <summary>Send GET request to URL</summary> + <div class="input-group"> + <input type="text" class="form-control" @bind-value="get_request_url" placeholder="URL"> + <button class="btn btn-outline-secondary" type="button" @onclick="SendGetRequest">Send</button> + </div> + <br/> + <pre>@get_request_result</pre> +</details> + +<div style="margin-bottom: 4em;"></div> +<LogView></LogView> + +@code { + public List<string> Rooms { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs == null) return; + Rooms = (await hs.GetJoinedRooms()).Select(x => x.RoomId).ToList(); + Console.WriteLine("Fetched joined rooms!"); + } + + //send req + string get_request_url { get; set; } = ""; + string get_request_result { get; set; } = ""; + + private async Task SendGetRequest() { + var field = typeof(RemoteHomeServer).GetRuntimeFields().First(x => x.ToString().Contains("<_httpClient>k__BackingField")); + var hs = await MRUStorage.GetCurrentSessionOrNavigate(); + if (hs == null) return; + var httpClient = field.GetValue(hs) as MatrixHttpClient; + try { + var res = await httpClient.GetAsync(get_request_url); + if (res.IsSuccessStatusCode) { + if (res.Content.Headers.ContentType.MediaType == "application/json") + get_request_result = (await res.Content.ReadFromJsonAsync<object>()).ToJson(); + else + get_request_result = await res.Content.ReadAsStringAsync(); + StateHasChanged(); + return; + } + if (res.Content.Headers.ContentType.MediaType == "application/json") + get_request_result = $"Error: {res.StatusCode}\n" + (await res.Content.ReadFromJsonAsync<object>()).ToJson(); + else + get_request_result = $"Error: {res.StatusCode}\n" + await res.Content.ReadAsStringAsync(); + } + catch (Exception e) { + get_request_result = $"Error: {e}"; + } + StateHasChanged(); + } + +} |