Skip to content

Commit

Permalink
Shorthand URLs for AutoDiscover input
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Nov 4, 2024
1 parent a562c09 commit 0cfe857
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Refresher.Core/Verification/AutoDiscover/AutoDiscoverClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public static class AutoDiscoverClient
{
public static async Task<AutoDiscoverResponse?> InvokeAutoDiscoverAsync(string url, CancellationToken cancellationToken = default)
{
if(!url.StartsWith("http"))
url = "https://" + url; // prefer HTTPS by default if there's no scheme set.
url = TryCompleteUrl(url);

State.Logger.LogInfo(LogType.AutoDiscover, $"Invoking autodiscover on URL '{url}'");
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? autodiscoverUri))
Expand Down Expand Up @@ -103,4 +102,32 @@ private static bool HandleAutoDiscoverError(Exception inner)

return false;
}

private static string TryCompleteUrl(string url)
{
if (url.StartsWith("http")) return url;

// cool GAMER shortcuts
switch (url.ToLowerInvariant())
{
case "r":
case "refresh":
return "https://lbp.littlebigrefresh.com";
case "l":
case "local":
return "http://localhost:10061";
case "b":
case "beacon":
// technically, beacon doesn't support autodiscover so this is more future-proofing if they ever do for some reason
return "https://beacon.lbpunion.com";
case "refreshed":
State.Logger.LogError("jvyden", "you're gonna make me cry. it's refresh. not refreshed.");
goto case "refresh";
default:
// prefer HTTPS by default if there's no scheme set.
return "https://" + url;
}

return url;

Check warning on line 131 in Refresher.Core/Verification/AutoDiscover/AutoDiscoverClient.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds (ubuntu-latest)

Unreachable code detected

Check warning on line 131 in Refresher.Core/Verification/AutoDiscover/AutoDiscoverClient.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds (windows-latest)

Unreachable code detected

Check warning on line 131 in Refresher.Core/Verification/AutoDiscover/AutoDiscoverClient.cs

View workflow job for this annotation

GitHub Actions / Build, Test, and Upload Builds (macos-latest)

Unreachable code detected
}
}

0 comments on commit 0cfe857

Please sign in to comment.