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

View File

@ -21,8 +21,11 @@ namespace Kiseki.Launcher
{
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_MAINTENANCE)
@ -36,9 +39,9 @@ namespace Kiseki.Launcher
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;
}
@ -54,7 +57,7 @@ namespace Kiseki.Launcher
HttpClient.DefaultRequestHeaders.Clear();
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(license)!;
for (int i = 0; i < headers.Count; i++)
HttpClient.DefaultRequestHeaders.Add(headers.ElementAt(i).Key, headers.ElementAt(i).Value);
}