- tweak: refactor funny

This commit is contained in:
2025-01-05 17:05:23 +03:00
parent 5b24f915a2
commit 8619e248fd
67 changed files with 485 additions and 492 deletions

View File

@@ -0,0 +1,63 @@
using Nebula.Shared.Utils;
namespace Nebula.Shared.Models;
public class RobustUrl
{
public RobustUrl(string url)
{
if (!UriHelper.TryParseSs14Uri(url, out var uri))
throw new Exception("Invalid scheme");
Uri = uri;
HttpUri = UriHelper.GetServerApiAddress(Uri);
}
public Uri Uri { get; }
public Uri HttpUri { get; }
public RobustPath InfoUri => new(this, "info");
public RobustPath StatusUri => new(this, "status");
public override string ToString()
{
return Uri.ToString();
}
public static implicit operator Uri(RobustUrl url)
{
return url.HttpUri;
}
public static explicit operator RobustUrl(string url)
{
return new RobustUrl(url);
}
public static explicit operator RobustUrl(Uri uri)
{
return new RobustUrl(uri.ToString());
}
}
public class RobustPath
{
public string Path;
public RobustUrl Url;
public RobustPath(RobustUrl url, string path)
{
Url = url;
Path = path;
}
public override string ToString()
{
return ((Uri)this).ToString();
}
public static implicit operator Uri(RobustPath path)
{
return new Uri(path.Url, path.Url.HttpUri.PathAndQuery + path.Path);
}
}