DebugTools.razor (2969B)
1 @page "/Debug" 2 @using MatrixRoomUtils.Core.Interfaces 3 @using MatrixRoomUtils.Core.Extensions 4 @using System.Reflection 5 @inject ILocalStorageService LocalStorage 6 @inject NavigationManager NavigationManager 7 <h3>Debug Tools</h3> 8 <hr/> 9 @if (Rooms.Count == 0) 10 { 11 <p>You are not in any rooms!</p> 12 @* <p>Loading progress: @checkedRoomCount/@totalRoomCount</p> *@ 13 } 14 else 15 { 16 <details> 17 <summary>Room List</summary> 18 @foreach (var room in Rooms) 19 { 20 <a style="color: unset; text-decoration: unset;" href="/RoomStateViewer/@room.Replace('.', '~')"><RoomListItem RoomId="@room"></RoomListItem></a> 21 } 22 </details> 23 24 } 25 26 <details open> 27 <summary>Send GET request to URL</summary> 28 <div class="input-group"> 29 <input type="text" class="form-control" @bind-value="get_request_url" placeholder="URL"> 30 <button class="btn btn-outline-secondary" type="button" @onclick="SendGetRequest">Send</button> 31 </div> 32 <br/> 33 <pre>@get_request_result</pre> 34 </details> 35 36 <div style="margin-bottom: 4em;"></div> 37 <LogView></LogView> 38 39 @code { 40 public List<string> Rooms { get; set; } = new(); 41 protected override async Task OnInitializedAsync() 42 { 43 await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); 44 await base.OnInitializedAsync(); 45 if (RuntimeCache.CurrentHomeServer == null) 46 { 47 NavigationManager.NavigateTo("/Login"); 48 return; 49 } 50 Rooms = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Select(x=>x.RoomId).ToList(); 51 Console.WriteLine("Fetched joined rooms!"); 52 } 53 54 55 //send req 56 string get_request_url { get; set; } = ""; 57 string get_request_result { get; set; } = ""; 58 private async Task SendGetRequest() 59 { 60 var field = typeof(IHomeServer).GetRuntimeFields().First(x => x.ToString().Contains("<_httpClient>k__BackingField")); 61 var httpClient = field.GetValue(RuntimeCache.CurrentHomeServer) as HttpClient; 62 try 63 { 64 var res = await httpClient.GetAsync(get_request_url); 65 if (res.IsSuccessStatusCode) 66 { 67 if(res.Content.Headers.ContentType.MediaType == "application/json") 68 get_request_result = (await res.Content.ReadFromJsonAsync<object>()).ToJson(); 69 else 70 get_request_result = await res.Content.ReadAsStringAsync(); 71 StateHasChanged(); 72 return; 73 } 74 if(res.Content.Headers.ContentType.MediaType == "application/json") 75 get_request_result = $"Error: {res.StatusCode}\n" + (await res.Content.ReadFromJsonAsync<object>()).ToJson(); 76 else 77 get_request_result = $"Error: {res.StatusCode}\n" + await res.Content.ReadAsStringAsync(); 78 79 } 80 catch (Exception e) 81 { 82 get_request_result = $"Error: {e}"; 83 } 84 StateHasChanged(); 85 } 86 87 }