Files
NebulaLauncher/Nebula.Shared/Models/RobustUrl.cs

63 lines
1.3 KiB
C#
Raw Normal View History

2025-01-05 17:05:23 +03:00
using Nebula.Shared.Utils;
2024-12-27 19:15:33 +03:00
2025-01-05 17:05:23 +03:00
namespace Nebula.Shared.Models;
2024-12-27 19:15:33 +03:00
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()
{
2024-12-28 08:29:01 +03:00
return Uri.ToString();
2024-12-27 19:15:33 +03:00
}
public static implicit operator Uri(RobustUrl url)
{
return url.HttpUri;
}
2025-12-11 21:47:54 +03:00
public static implicit operator RobustUrl(string url)
2024-12-27 19:15:33 +03:00
{
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);
}
}