Implemented node crud and status health check. Added daemon status health endpoint. Refactored project structure. Added sidebar items and ui views

This commit is contained in:
2026-03-05 10:56:52 +00:00
parent 2d1b48b0d4
commit 7c5dc657dc
54 changed files with 1808 additions and 222 deletions

View File

@@ -0,0 +1,109 @@
@using Microsoft.Extensions.Logging
@using MoonlightServers.Shared.Admin.Nodes
@using ShadcnBlazor.Tooltips
@inject HttpClient HttpClient
@inject ILogger<NodeHealthDisplay> Logger
@if (IsLoading)
{
<span class="text-muted-foreground">Loading</span>
}
else
{
if (IsHealthy)
{
<Tooltip>
<TooltipTrigger>
<Slot>
<span class="text-green-400" @attributes="context">Healthy</span>
</Slot>
</TooltipTrigger>
<TooltipContent>
@TooltipText
</TooltipContent>
</Tooltip>
}
else
{
<Tooltip>
<TooltipTrigger>
<Slot>
<span class="text-destructive" @attributes="context">Unhealthy</span>
</Slot>
</TooltipTrigger>
<TooltipContent>
@TooltipText
</TooltipContent>
</Tooltip>
}
}
@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<NodeHealthDto>($"api/admin/servers/nodes/{Node.Id}/health");
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);
}
}