Implemented "roundtrip" status checking. Added node ssl field.

This commit is contained in:
2024-12-13 20:12:56 +01:00
parent 3c88b60e8d
commit d15c5326ed
16 changed files with 872 additions and 7 deletions

View File

@@ -0,0 +1,52 @@
using MoonCore.Attributes;
using MoonCore.Helpers;
using MoonlightServers.ApiServer.Database.Entities;
using MoonlightServers.DaemonShared.Http.Responses.Sys;
namespace MoonlightServers.ApiServer.Services;
[Singleton]
public class NodeService
{
public async Task<HttpApiClient> CreateApiClient(Node node)
{
string url = "";
if (node.UseSsl)
url += "https://";
else
url += "http://";
url += $"{node.Fqdn}:{node.HttpPort}/";
var httpClient = new HttpClient()
{
BaseAddress = new Uri(url)
};
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {node.Token}");
return new HttpApiClient(httpClient);
}
public async Task<SystemInfoResponse> GetSystemInfo(Node node)
{
using var apiClient = await CreateApiClient(node);
return await apiClient.GetJson<SystemInfoResponse>("api/system/info");
}
public async Task<SystemStatusResponse> GetSystemStatus(Node node)
{
using var apiClient = await CreateApiClient(node);
return await apiClient.GetJson<SystemStatusResponse>("api/system/status");
}
public async Task<SystemDataUsageResponse> GetSystemDataUsage(Node node)
{
using var apiClient = await CreateApiClient(node);
return await apiClient.GetJson<SystemDataUsageResponse>("api/system/dataUsage");
}
}