@page "/MediaLocator"
@inject HttpClient Http
Media locator
This is going to expose your IP address to all these homeservers!
Checked homeserver list (@homeservers.Count entries)
@foreach (var hs in homeservers) {
- @hs
}
MXC URL:
@if (successResults.Count > 0) {
Successes
@foreach (var result in successResults) {
- @result
}
}
@if (errorResults.Count > 0) {
Errors
@foreach (var result in errorResults) {
- @result
}
}
@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"
});
}
async 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/r0/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();
});
}
async Task addMoreHomeservers() {
await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
var res = await Http.GetAsync("/homeservers.txt");
var content = await res.Content.ReadAsStringAsync();
homeservers.Clear();
var lines = content.Split("\n");
var rhs = new RemoteHomeServer("rory.gay");
var sem = new SemaphoreSlim(128, 128);
lines.ToList().ForEach(async line => {
await sem.WaitAsync();
try {
homeservers.Add(await rhs.ResolveHomeserverFromWellKnown(line));
StateHasChanged();
if (Random.Shared.Next(0, 101) == 50)
await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
}
catch (Exception e) {
Console.WriteLine(e);
}
finally {
sem.Release();
}
});
StateHasChanged();
}
}