feat: add back Http tasks (and implement them properly this time)

This commit is contained in:
rjindael 2023-08-01 23:02:12 -07:00
parent 7890fa380a
commit 4f4f1b9cb5
No known key found for this signature in database
GPG Key ID: D069369C906CCF31
2 changed files with 11 additions and 8 deletions

View File

@ -4,11 +4,11 @@ namespace Kiseki.Launcher.Helpers
{ {
public static class Http public static class Http
{ {
public static T? GetJson<T>(string url) public static async Task<T?> GetJson<T>(string url)
{ {
try try
{ {
string json = Web.HttpClient.GetStringAsync(url).Result; string json = await Web.HttpClient.GetStringAsync(url);
return JsonSerializer.Deserialize<T>(json); return JsonSerializer.Deserialize<T>(json);
} }

View File

@ -21,7 +21,10 @@ namespace Kiseki.Launcher
{ {
CurrentUrl = IsInMaintenance ? $"{MAINTENANCE_DOMAIN}.{BASE_URL}" : BASE_URL; CurrentUrl = IsInMaintenance ? $"{MAINTENANCE_DOMAIN}.{BASE_URL}" : BASE_URL;
int response = CheckHealth(); Task<int> task = CheckHealth();
task.Wait();
int response = task.Result;
if (response != RESPONSE_SUCCESS) if (response != RESPONSE_SUCCESS)
{ {
@ -36,9 +39,9 @@ namespace Kiseki.Launcher
public static string Url(string path) => $"https://{CurrentUrl}{path}"; public static string Url(string path) => $"https://{CurrentUrl}{path}";
public static int CheckHealth() public static async Task<int> CheckHealth()
{ {
var response = Helpers.Http.GetJson<Models.HealthCheck>(Url("/api/health")); var response = await Helpers.Http.GetJson<Models.HealthCheck>(Url("/api/health"));
return response is null ? RESPONSE_FAILURE : response.Status; return response is null ? RESPONSE_FAILURE : response.Status;
} }