@using Microsoft.Extensions.Logging @using MoonlightServers.Shared @using MoonlightServers.Shared.Admin.Nodes @using ShadcnBlazor.Tooltips @inject HttpClient HttpClient @inject ILogger Logger @if (IsLoading) { Loading } else { if (IsHealthy) { Healthy @TooltipText } else { Unhealthy @TooltipText } } @code { [Parameter] public NodeDto Node { get; set; } private bool IsLoading = true; private string TooltipText = "An unknown error has occured. Check logs"; private bool IsHealthy; protected override async Task OnAfterRenderAsync(bool firstRender) { if (!firstRender) return; try { var result = await HttpClient.GetFromJsonAsync($"api/admin/servers/nodes/{Node.Id}/health", SerializationContext.Default.Options); if(result == null) return; IsHealthy = result.IsHealthy; if (IsHealthy) TooltipText = "Version: v2.1.0"; // TODO: Add version loading else { if (result.StatusCode != 0) { if (result.StatusCode is >= 200 and <= 299) { if (result.RemoteStatusCode != 0) { TooltipText = result.RemoteStatusCode switch { 401 => "Daemon is unable to authenticate against the panel", 404 => "Daemon is unable to request the panel's endpoint", 500 => "Panel encountered an internal server error", _ => $"Panel returned {result.RemoteStatusCode}" }; } else TooltipText = "Daemon is unable to reach the panel"; } else { TooltipText = result.StatusCode switch { 401 => "Panel is unable to authenticate against the node", 404 => "Panel is unable to request the daemon's endpoint", 500 => "Daemon encountered an internal server error", _ => $"Daemon returned {result.StatusCode}" }; } } else TooltipText = "Moonlight is unable to reach the node"; } } catch (Exception e) { Logger.LogError(e, "An unhandled error occured while fetching the node health status"); } IsLoading = false; await InvokeAsync(StateHasChanged); } }