blob: 5d47277fc4b38f06dca9fe5cc690c816470f60df (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
@page "/Debug"
@using System.Reflection
@using ArcaneLibs.Extensions
@using LibMatrix
@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();
}
}
|