MatrixRoomUtils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

DataExportPage.razor (2882B)


      1 @page "/Export"
      2 @using MatrixRoomUtils.Web.Shared.IndexComponents
      3 @using System.Text.Json
      4 @inject NavigationManager NavigationManager
      5 @inject ILocalStorageService LocalStorage
      6 
      7 <PageTitle>Export</PageTitle>
      8 
      9 <h3>Data export</h3>
     10 
     11 <br/><br/>
     12 <h5>Signed in accounts - <a href="/Login">Add new account</a> or <a href="/ImportUsers">Import from TSV</a></h5>
     13 <hr/>
     14 @if (_isLoaded)
     15 {
     16 @foreach (var (token, user) in RuntimeCache.LoginSessions)
     17 {
     18     @* <IndexUserItem User="@user"/> *@
     19     <pre>
     20 @user.LoginResponse.UserId[1..].Split(":")[0]\auth\access_token=@token
     21 @user.LoginResponse.UserId[1..].Split(":")[0]\auth\device_id=@user.LoginResponse.DeviceId
     22 @user.LoginResponse.UserId[1..].Split(":")[0]\auth\home_server=@(RuntimeCache.HomeserverResolutionCache.ContainsKey(user.LoginResponse.HomeServer) ? RuntimeCache.HomeserverResolutionCache[user.LoginResponse.HomeServer].Result : "loading...")
     23 @user.LoginResponse.UserId[1..].Split(":")[0]\auth\user_id=@@@user.LoginResponse.UserId
     24 @user.LoginResponse.UserId[1..].Split(":")[0]\user\automatically_share_keys_with_trusted_users=true
     25 @user.LoginResponse.UserId[1..].Split(":")[0]\user\muted_tags=global
     26 @user.LoginResponse.UserId[1..].Split(":")[0]\user\online_key_backup=true
     27 @user.LoginResponse.UserId[1..].Split(":")[0]\user\only_share_keys_with_verified_users=false
     28     </pre>
     29 }
     30 }
     31 else
     32 {
     33     <p>Loading...</p>
     34     <p>@resolvedHomeservers/@totalHomeservers homeservers resolved...</p>
     35 }
     36 
     37 @code {
     38     private bool _isLoaded;
     39     private int resolvedHomeservers;
     40     private int totalHomeservers;
     41 
     42     protected override async Task OnInitializedAsync()
     43     {
     44         await base.OnInitializedAsync();
     45         if (!RuntimeCache.WasLoaded)
     46         {
     47             await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
     48         }
     49         var homeservers = RuntimeCache.LoginSessions.Values.Select(x => x.LoginResponse.HomeServer).Distinct();
     50         totalHomeservers = homeservers.Count();
     51         StateHasChanged();
     52         foreach (var hs in homeservers)
     53         {
     54             if (RuntimeCache.HomeserverResolutionCache.ContainsKey(hs))
     55             {
     56                 resolvedHomeservers++;
     57                 continue;
     58             }
     59             var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain;
     60 
     61             RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now });
     62             await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
     63 
     64             Console.WriteLine("Saved to local storage:");
     65             Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions()
     66             {
     67                 WriteIndented = true
     68             }));
     69             resolvedHomeservers++;
     70             StateHasChanged();
     71         }
     72         StateHasChanged();
     73         _isLoaded = true;
     74     }
     75 
     76 }