feat: Add account ban handling and UI updates (#11)
- Add ban status and reason fields to account configuration - Add account ban status and details handling in API refresh account function. - Add logic to handle account suspension and authentication errors, updating ban status accordingly. - Add and style badge classes for different account statuses and modify account status display logic.
This commit is contained in:
@@ -136,9 +136,61 @@ func RefreshAccountInfo(account *config.Account) (*config.AccountInfo, error) {
|
||||
// 获取使用量和订阅信息
|
||||
usage, err := GetUsageLimits(account)
|
||||
if err != nil {
|
||||
// 检测封禁状态
|
||||
errMsg := err.Error()
|
||||
if strings.Contains(errMsg, "TEMPORARILY_SUSPENDED") {
|
||||
// 账户被暂时封禁,自动禁用并标记封禁状态
|
||||
fmt.Printf("[RefreshAccountInfo] Account %s is temporarily suspended: %v\n", account.Email, err)
|
||||
|
||||
// 更新账户封禁状态并自动禁用
|
||||
updatedAccount := *account
|
||||
updatedAccount.Enabled = false
|
||||
updatedAccount.BanStatus = "BANNED"
|
||||
updatedAccount.BanReason = "AWS temporarily suspended - unusual user activity detected"
|
||||
updatedAccount.BanTime = time.Now().Unix()
|
||||
|
||||
// 保存更新后的账户状态
|
||||
if updateErr := config.UpdateAccount(account.ID, updatedAccount); updateErr != nil {
|
||||
fmt.Printf("[RefreshAccountInfo] Failed to update account ban status: %v\n", updateErr)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Account suspended: %w", err)
|
||||
} else if strings.Contains(errMsg, "403") || strings.Contains(errMsg, "401") ||
|
||||
strings.Contains(errMsg, "invalid") || strings.Contains(errMsg, "expired") {
|
||||
// Token 相关错误,可能需要重新认证
|
||||
fmt.Printf("[RefreshAccountInfo] Authentication error for %s: %v\n", account.Email, err)
|
||||
|
||||
// 更新账户封禁状态为认证失败并自动禁用
|
||||
updatedAccount := *account
|
||||
updatedAccount.Enabled = false
|
||||
updatedAccount.BanStatus = "BANNED"
|
||||
updatedAccount.BanReason = "Authentication failed - token invalid or expired"
|
||||
updatedAccount.BanTime = time.Now().Unix()
|
||||
|
||||
// 保存更新后的账户状态
|
||||
if updateErr := config.UpdateAccount(account.ID, updatedAccount); updateErr != nil {
|
||||
fmt.Printf("[RefreshAccountInfo] Failed to update account ban status: %v\n", updateErr)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("GetUsageLimits: %w", err)
|
||||
}
|
||||
|
||||
// 如果成功获取信息,清除封禁状态(如果之前被标记)
|
||||
if account.BanStatus != "" && account.BanStatus != "ACTIVE" {
|
||||
fmt.Printf("[RefreshAccountInfo] Account %s is now active, clearing ban status\n", account.Email)
|
||||
|
||||
updatedAccount := *account
|
||||
updatedAccount.BanStatus = "ACTIVE"
|
||||
updatedAccount.BanReason = ""
|
||||
updatedAccount.BanTime = 0
|
||||
|
||||
// 保存更新后的账户状态
|
||||
if updateErr := config.UpdateAccount(account.ID, updatedAccount); updateErr != nil {
|
||||
fmt.Printf("[RefreshAccountInfo] Failed to clear account ban status: %v\n", updateErr)
|
||||
}
|
||||
}
|
||||
|
||||
// 解析用户信息
|
||||
if usage.UserInfo != nil {
|
||||
info.Email = usage.UserInfo.Email
|
||||
|
||||
Reference in New Issue
Block a user