"git@web.lueluesay.top:chenxi/sub2api.git" did not exist on "4cce21b125ec4b1b947104d9fca9b38af5b71a96"
Commit 82196890 authored by song's avatar song
Browse files

feat(antigravity): 手动刷新令牌时自动恢复 missing_project_id 错误账户状态

- 当手动刷新成功获取到 project_id,且之前错误为 missing_project_id 时,自动清除错误状态
- 后台自动刷新时同样支持状态恢复
parent 95fe1e81
...@@ -462,7 +462,7 @@ func (h *AccountHandler) Refresh(c *gin.Context) { ...@@ -462,7 +462,7 @@ func (h *AccountHandler) Refresh(c *gin.Context) {
return return
} }
// 标记账户为 error // 标记账户为 error
if setErr := h.adminService.SetAccountError(c.Request.Context(), accountID, "账户缺少project id,可能无法使用Antigravity"); setErr != nil { if setErr := h.adminService.SetAccountError(c.Request.Context(), accountID, "missing_project_id: 账户缺少project id,可能无法使用Antigravity"); setErr != nil {
response.InternalError(c, "Failed to set account error: "+setErr.Error()) response.InternalError(c, "Failed to set account error: "+setErr.Error())
return return
} }
...@@ -472,6 +472,14 @@ func (h *AccountHandler) Refresh(c *gin.Context) { ...@@ -472,6 +472,14 @@ func (h *AccountHandler) Refresh(c *gin.Context) {
}) })
return return
} }
// 成功获取到 project_id,如果之前是 missing_project_id 错误则清除
if account.Status == service.StatusError && strings.HasPrefix(account.ErrorMessage, "missing_project_id:") {
if _, clearErr := h.adminService.ClearAccountError(c.Request.Context(), accountID); clearErr != nil {
response.InternalError(c, "Failed to clear account error: "+clearErr.Error())
return
}
}
} else { } else {
// Use Anthropic/Claude OAuth service to refresh token // Use Anthropic/Claude OAuth service to refresh token
tokenInfo, err := h.oauthService.RefreshAccountToken(c.Request.Context(), account) tokenInfo, err := h.oauthService.RefreshAccountToken(c.Request.Context(), account)
......
...@@ -491,6 +491,15 @@ func (r *accountRepository) SetError(ctx context.Context, id int64, errorMsg str ...@@ -491,6 +491,15 @@ func (r *accountRepository) SetError(ctx context.Context, id int64, errorMsg str
return err return err
} }
func (r *accountRepository) ClearError(ctx context.Context, id int64) error {
_, err := r.client.Account.Update().
Where(dbaccount.IDEQ(id)).
SetStatus(service.StatusActive).
SetErrorMessage("").
Save(ctx)
return err
}
func (r *accountRepository) AddToGroup(ctx context.Context, accountID, groupID int64, priority int) error { func (r *accountRepository) AddToGroup(ctx context.Context, accountID, groupID int64, priority int) error {
_, err := r.client.AccountGroup.Create(). _, err := r.client.AccountGroup.Create().
SetAccountID(accountID). SetAccountID(accountID).
......
...@@ -37,6 +37,7 @@ type AccountRepository interface { ...@@ -37,6 +37,7 @@ type AccountRepository interface {
UpdateLastUsed(ctx context.Context, id int64) error UpdateLastUsed(ctx context.Context, id int64) error
BatchUpdateLastUsed(ctx context.Context, updates map[int64]time.Time) error BatchUpdateLastUsed(ctx context.Context, updates map[int64]time.Time) error
SetError(ctx context.Context, id int64, errorMsg string) error SetError(ctx context.Context, id int64, errorMsg string) error
ClearError(ctx context.Context, id int64) error
SetSchedulable(ctx context.Context, id int64, schedulable bool) error SetSchedulable(ctx context.Context, id int64, schedulable bool) error
AutoPauseExpiredAccounts(ctx context.Context, now time.Time) (int64, error) AutoPauseExpiredAccounts(ctx context.Context, now time.Time) (int64, error)
BindGroups(ctx context.Context, accountID int64, groupIDs []int64) error BindGroups(ctx context.Context, accountID int64, groupIDs []int64) error
......
...@@ -173,6 +173,16 @@ func (s *TokenRefreshService) refreshWithRetry(ctx context.Context, account *Acc ...@@ -173,6 +173,16 @@ func (s *TokenRefreshService) refreshWithRetry(ctx context.Context, account *Acc
} }
if err == nil { if err == nil {
// Antigravity 账户:如果之前是因为缺少 project_id 而标记为 error,现在成功获取到了,清除错误状态
if account.Platform == PlatformAntigravity &&
account.Status == StatusError &&
strings.HasPrefix(account.ErrorMessage, "missing_project_id:") {
if clearErr := s.accountRepo.ClearError(ctx, account.ID); clearErr != nil {
log.Printf("[TokenRefresh] Failed to clear error status for account %d: %v", account.ID, clearErr)
} else {
log.Printf("[TokenRefresh] Account %d: cleared missing_project_id error", account.ID)
}
}
return nil return nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment