diff options
author | Rory& <root@rory.gay> | 2024-01-24 02:31:56 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-24 17:05:25 +0100 |
commit | 03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch) | |
tree | e000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixUtils.Web/Pages/Dev/DevUtilities.razor | |
parent | Make RMU installable (diff) | |
download | MatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz |
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixUtils.Web/Pages/Dev/DevUtilities.razor')
-rw-r--r-- | MatrixUtils.Web/Pages/Dev/DevUtilities.razor | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Dev/DevUtilities.razor b/MatrixUtils.Web/Pages/Dev/DevUtilities.razor new file mode 100644 index 0000000..a6a4a82 --- /dev/null +++ b/MatrixUtils.Web/Pages/Dev/DevUtilities.razor @@ -0,0 +1,78 @@ +@page "/Dev/Utilities" +@using System.Reflection +@using ArcaneLibs.Extensions +@using LibMatrix.Extensions +@using LibMatrix.Homeservers +@using MatrixUtils.Abstractions +@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 RoomInfo="@(new RoomInfo() { Room = hs.GetRoom(room) })" LoadData="true"></RoomListItem> + </a> + } + </details> +} + +<details open> + <summary>Send GET request to URL</summary> + <div class="input-group"> + <input type="text" class="form-control" @bind-value="GetRequestUrl" placeholder="URL"> + <button class="btn btn-outline-secondary" type="button" @onclick="SendGetRequest">Send</button> + </div> + <br/> + <pre>@GetRequestResult</pre> +</details> + +<div style="margin-bottom: 4em;"></div> +<LogView></LogView> + +@code { + public List<string> Rooms { get; set; } = new(); + public AuthenticatedHomeserverGeneric? hs { get; set; } + + protected override async Task OnInitializedAsync() { + await base.OnInitializedAsync(); + hs = await RMUStorage.GetCurrentSessionOrNavigate(); + if (hs == null) return; + Rooms = (await hs.GetJoinedRooms()).Select(x => x.RoomId).ToList(); + Console.WriteLine("Fetched joined rooms!"); + } + + //send req + string GetRequestUrl { get; set; } = ""; + string GetRequestResult { get; set; } = ""; + + private async Task SendGetRequest() { + var httpClient = hs?.ClientHttpClient; + try { + var res = await httpClient.GetAsync(GetRequestUrl); + if (res.IsSuccessStatusCode) { + if (res.Content.Headers.ContentType.MediaType == "application/json") + GetRequestResult = (await res.Content.ReadFromJsonAsync<object>()).ToJson(); + else + GetRequestResult = await res.Content.ReadAsStringAsync(); + StateHasChanged(); + return; + } + if (res.Content.Headers.ContentType.MediaType == "application/json") + GetRequestResult = $"Error: {res.StatusCode}\n" + (await res.Content.ReadFromJsonAsync<object>()).ToJson(); + else + GetRequestResult = $"Error: {res.StatusCode}\n" + await res.Content.ReadAsStringAsync(); + } + catch (Exception e) { + GetRequestResult = $"Error: {e}"; + } + StateHasChanged(); + } + +} \ No newline at end of file |