[CHANGE] Get all account info

This commit is contained in:
max
2025-09-06 01:07:12 +02:00
parent f334c87fbb
commit fa0c617c9a
5 changed files with 94 additions and 38 deletions

View File

@@ -128,16 +128,52 @@ public static class NetworkService
return ResultError.Fail("Unable to get http client!");
}
var response = await http.SendAsync(httpRequest);
if (!response.IsSuccessStatusCode)
try
{
var responseResult = await response.Content.ReadAsStringAsync();
return ResultError.Fail(responseResult);
var response = await http.SendAsync(httpRequest);
if (!response.IsSuccessStatusCode)
{
var responseResult = await response.Content.ReadAsStringAsync();
return ResultError.Fail(responseResult);
}
var json = await response.Content.ReadAsStringAsync();
var jsonDocument = JsonDocument.Parse(json);
var activeAccountHeader = jsonDocument.RootElement
.GetProperty("actions")[0]
.GetProperty("openPopupAction")
.GetProperty("popup")
.GetProperty("multiPageMenuRenderer")
.GetProperty("header")
.GetProperty("activeAccountHeaderRenderer");
var matRuns = activeAccountHeader
.GetProperty("manageAccountTitle")
.GetProperty("runs");
var accountPhotos = activeAccountHeader
.GetProperty("accountPhoto")
.GetProperty("thumbnails");
var accInfo = new AccountMenuInfo();
var highestImage = accountPhotos.EnumerateArray().OrderBy(x => x.GetProperty("width").Deserialize<int>())
.FirstOrDefault();
accInfo.ImageUrl = highestImage.GetProperty("url").Deserialize<string>();
accInfo.ImageWidth = highestImage.GetProperty("width").Deserialize<int>();
accInfo.ImageHeight = highestImage.GetProperty("height").Deserialize<int>();
foreach (var run in matRuns.EnumerateArray())
{
var browseEndpoint = run.GetProperty("navigationEndpoint").GetProperty("browseEndpoint");
accInfo.AccountId = browseEndpoint.GetProperty("browseId").GetString();
accInfo.AccountHandle = browseEndpoint.GetProperty("canonicalBaseUrl").GetString()?.Replace("/", "");
}
return accInfo;
}
catch (Exception e)
{
return ResultError.Error(e);
}
var json = await response.Content.ReadAsStringAsync();
var jsonObject = JsonNode.Parse(json);
return ResultError.Fail("Not implemented");
}
}