about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/DataExportPage.razor
blob: 732cd74fd066d9d607e3e9f797e8f35ebbb8cc14 (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
@page "/Export"
@using System.Text.Json
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage

<PageTitle>Export</PageTitle>

<h3>Data export</h3>

<br/><br/>
<h5>Signed in accounts - <a href="/Login">Add new account</a> or <a href="/ImportUsers">Import from TSV</a></h5>
<hr/>
@if (_isLoaded) {
    @foreach (var (token, user) in RuntimeCache.LoginSessions) {
    @* <IndexUserItem User="@user"/> *@
        <pre>
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\access_token=@token
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\device_id=@user.LoginResponse.DeviceId
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\home_server=@(RuntimeCache.HomeserverResolutionCache.ContainsKey(user.LoginResponse.HomeServer) ? RuntimeCache.HomeserverResolutionCache[user.LoginResponse.HomeServer].Result : "loading...")
@user.LoginResponse.UserId[1..].Split(":")[0]\auth\user_id=@@@user.LoginResponse.UserId
@user.LoginResponse.UserId[1..].Split(":")[0]\user\automatically_share_keys_with_trusted_users=true
@user.LoginResponse.UserId[1..].Split(":")[0]\user\muted_tags=global
@user.LoginResponse.UserId[1..].Split(":")[0]\user\online_key_backup=true
@user.LoginResponse.UserId[1..].Split(":")[0]\user\only_share_keys_with_verified_users=false
    </pre>
    }
}
else {
    <p>Loading...</p>
    <p>@resolvedHomeservers/@totalHomeservers homeservers resolved...</p>
}

@code {
    private bool _isLoaded;
    private int resolvedHomeservers;
    private int totalHomeservers;

    protected override async Task OnInitializedAsync() {
        await base.OnInitializedAsync();
        if (!RuntimeCache.WasLoaded) {
            await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
        }
        var homeservers = RuntimeCache.LoginSessions.Values.Select(x => x.LoginResponse.HomeServer).Distinct();
        totalHomeservers = homeservers.Count();
        StateHasChanged();
        foreach (var hs in homeservers) {
            if (RuntimeCache.HomeserverResolutionCache.ContainsKey(hs)) {
                resolvedHomeservers++;
                continue;
            }
            var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain;

            RuntimeCache.HomeserverResolutionCache.Add(hs, new HomeServerResolutionResult { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
            await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);

            Console.WriteLine("Saved to local storage:");
            Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions {
                WriteIndented = true
            }));
            resolvedHomeservers++;
            StateHasChanged();
        }
        StateHasChanged();
        _isLoaded = true;
    }

}