feat: add back Http tasks (and implement them properly this time)
This commit is contained in:
parent
7890fa380a
commit
4f4f1b9cb5
|
|
@ -4,12 +4,12 @@ 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);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,11 @@ 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)
|
||||||
{
|
{
|
||||||
if (response == RESPONSE_MAINTENANCE)
|
if (response == RESPONSE_MAINTENANCE)
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +57,7 @@ namespace Kiseki.Launcher
|
||||||
HttpClient.DefaultRequestHeaders.Clear();
|
HttpClient.DefaultRequestHeaders.Clear();
|
||||||
|
|
||||||
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(license)!;
|
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(license)!;
|
||||||
|
|
||||||
for (int i = 0; i < headers.Count; i++)
|
for (int i = 0; i < headers.Count; i++)
|
||||||
HttpClient.DefaultRequestHeaders.Add(headers.ElementAt(i).Key, headers.ElementAt(i).Value);
|
HttpClient.DefaultRequestHeaders.Add(headers.ElementAt(i).Key, headers.ElementAt(i).Value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue