From 41c5a84dacfd036b8d8f01f72226ac5a519995e3 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 14 May 2024 17:49:09 +0200 Subject: Organise tools somewhat, set proper icons for nav menu --- MatrixUtils.Web/Pages/Tools/MediaLocator.razor | 109 ------------------------- 1 file changed, 109 deletions(-) delete mode 100644 MatrixUtils.Web/Pages/Tools/MediaLocator.razor (limited to 'MatrixUtils.Web/Pages/Tools/MediaLocator.razor') diff --git a/MatrixUtils.Web/Pages/Tools/MediaLocator.razor b/MatrixUtils.Web/Pages/Tools/MediaLocator.razor deleted file mode 100644 index 6e87926..0000000 --- a/MatrixUtils.Web/Pages/Tools/MediaLocator.razor +++ /dev/null @@ -1,109 +0,0 @@ -@page "/Tools/MediaLocator" -@inject HttpClient Http -

Media locator

-
- -This is going to expose your IP address to all these homeservers! -
- Checked homeserver list (@homeservers.Count entries) - -
- -
-MXC URL: - - - -@if (successResults.Count > 0) { -

Successes

- -} - -@if (errorResults.Count > 0) { -

Errors

- -} - - -@code { - string mxcUrl { get; set; } - readonly List successResults = new(); - readonly List errorResults = new(); - readonly List homeservers = new(); - - protected override async Task OnInitializedAsync() { - await base.OnInitializedAsync(); - homeservers.AddRange(new[] { - "matrix.org", - "feline.support", - "rory.gay", - "the-apothecary.club", - "envs.net", - "projectsegfau.lt" - }); - } - - Task executeSearch() { - var sem = new SemaphoreSlim(128, 128); - homeservers.ForEach(async hs => { - await sem.WaitAsync(); - var httpClient = new HttpClient { BaseAddress = new Uri(hs) }; - httpClient.Timeout = TimeSpan.FromSeconds(5); - var rmu = mxcUrl.Replace("mxc://", $"{hs}/_matrix/media/v3/download/"); - try { - var res = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, rmu)); - if (res.IsSuccessStatusCode) { - successResults.Add($"{hs}: found - {res.Content.Headers.ContentLength} bytes"); - StateHasChanged(); - return; - } - errorResults.Add($"Error: {hs} - {res.StatusCode}\n" + await res.Content.ReadAsStringAsync()); - } - catch (Exception e) { - errorResults.Add($"Error: {e}"); - } - finally { - sem.Release(); - } - StateHasChanged(); - }); - return Task.CompletedTask; - } - - async Task addMoreHomeservers() { - var res = await Http.GetAsync("/homeservers.txt"); - var content = await res.Content.ReadAsStringAsync(); - homeservers.Clear(); - var lines = content.Split("\n"); - - var sem = new SemaphoreSlim(128, 128); - lines.ToList().ForEach(async line => { - await sem.WaitAsync(); - try { - homeservers.Add((await hsResolver.ResolveHomeserverFromWellKnown(line)).Client); - StateHasChanged(); - } - catch (Exception e) { - Console.WriteLine(e); - } - finally { - sem.Release(); - } - }); - - StateHasChanged(); - } - -} -- cgit 1.4.1