if rotating account does not work, re login
This commit is contained in:
parent
aefed18612
commit
9a409bcab0
1 changed files with 78 additions and 66 deletions
|
|
@ -35,6 +35,8 @@ var builder = WebApplication.CreateBuilder(args);
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseWebSockets();
|
app.UseWebSockets();
|
||||||
|
|
||||||
|
void LogInAllAccounts()
|
||||||
|
{
|
||||||
Config.Instance.Accounts.ForEach(async account =>
|
Config.Instance.Accounts.ForEach(async account =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -99,11 +101,14 @@ Config.Instance.Accounts.ForEach(async account =>
|
||||||
var curUser = await curUserResp.Content.ReadFromJsonAsync<User>();
|
var curUser = await curUserResp.Content.ReadFromJsonAsync<User>();
|
||||||
Console.WriteLine($"Logged in as {curUser.displayName}");
|
Console.WriteLine($"Logged in as {curUser.displayName}");
|
||||||
apiAccounts.Add(httpClient);
|
apiAccounts.Add(httpClient);
|
||||||
} catch (HttpRequestException e)
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Failed to create API for {account.username}: {e.Message}, {e.StatusCode}, {e}");
|
Console.WriteLine($"Failed to create API for {account.username}: {e.Message}, {e.StatusCode}, {e}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
LogInAllAccounts();
|
||||||
|
|
||||||
app.MapGet("/", () => $"Logged in with {apiAccounts.Count} accounts");
|
app.MapGet("/", () => $"Logged in with {apiAccounts.Count} accounts");
|
||||||
app.MapGet("/rotate", () =>
|
app.MapGet("/rotate", () =>
|
||||||
|
|
@ -172,7 +177,7 @@ app.Use(async (context, next) =>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async Task DoRequest(HttpContext context, bool retriedAlready = false)
|
async Task DoRequest(HttpContext context, bool retriedAlready = false, bool reAuthedAlready = false)
|
||||||
{
|
{
|
||||||
if (apiAccounts.Count == 0)
|
if (apiAccounts.Count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -230,9 +235,16 @@ async Task DoRequest(HttpContext context, bool retriedAlready = false)
|
||||||
{
|
{
|
||||||
if (retriedAlready)
|
if (retriedAlready)
|
||||||
{
|
{
|
||||||
|
if (reAuthedAlready)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Failed to re-authenticate all accounts");
|
||||||
context.Response.StatusCode = 500;
|
context.Response.StatusCode = 500;
|
||||||
Console.Error.WriteLine($"Failed to authenticate: {response.StatusCode}");
|
await context.Response.WriteAsync("Failed to re-authenticate all accounts");
|
||||||
await context.Response.WriteAsync("Failed to authenticate");
|
return;
|
||||||
|
}
|
||||||
|
// re-login all accounts and try again
|
||||||
|
LogInAllAccounts();
|
||||||
|
await DoRequest(context, true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Console.Error.WriteLine($"Retrying request due to {response.StatusCode}");
|
Console.Error.WriteLine($"Retrying request due to {response.StatusCode}");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue