From 821968903c4ccb4c6c8419c3b295e07b6bccad14 Mon Sep 17 00:00:00 2001 From: song Date: Fri, 16 Jan 2026 13:18:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(antigravity):=20=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E4=BB=A4=E7=89=8C=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=20missing=5Fproject=5Fid=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=B4=A6=E6=88=B7=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 当手动刷新成功获取到 project_id,且之前错误为 missing_project_id 时,自动清除错误状态 - 后台自动刷新时同样支持状态恢复 --- backend/internal/handler/admin/account_handler.go | 10 +++++++++- backend/internal/repository/account_repo.go | 9 +++++++++ backend/internal/service/account_service.go | 1 + backend/internal/service/token_refresh_service.go | 10 ++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/internal/handler/admin/account_handler.go b/backend/internal/handler/admin/account_handler.go index 97206b15..55311b3a 100644 --- a/backend/internal/handler/admin/account_handler.go +++ b/backend/internal/handler/admin/account_handler.go @@ -462,7 +462,7 @@ func (h *AccountHandler) Refresh(c *gin.Context) { return } // 标记账户为 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()) return } @@ -472,6 +472,14 @@ func (h *AccountHandler) Refresh(c *gin.Context) { }) 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 { // Use Anthropic/Claude OAuth service to refresh token tokenInfo, err := h.oauthService.RefreshAccountToken(c.Request.Context(), account) diff --git a/backend/internal/repository/account_repo.go b/backend/internal/repository/account_repo.go index 04ca7052..0acf1636 100644 --- a/backend/internal/repository/account_repo.go +++ b/backend/internal/repository/account_repo.go @@ -491,6 +491,15 @@ func (r *accountRepository) SetError(ctx context.Context, id int64, errorMsg str 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 { _, err := r.client.AccountGroup.Create(). SetAccountID(accountID). diff --git a/backend/internal/service/account_service.go b/backend/internal/service/account_service.go index 2f138b81..93a36c3e 100644 --- a/backend/internal/service/account_service.go +++ b/backend/internal/service/account_service.go @@ -37,6 +37,7 @@ type AccountRepository interface { UpdateLastUsed(ctx context.Context, id int64) error BatchUpdateLastUsed(ctx context.Context, updates map[int64]time.Time) 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 AutoPauseExpiredAccounts(ctx context.Context, now time.Time) (int64, error) BindGroups(ctx context.Context, accountID int64, groupIDs []int64) error diff --git a/backend/internal/service/token_refresh_service.go b/backend/internal/service/token_refresh_service.go index 29ff142f..6e405efb 100644 --- a/backend/internal/service/token_refresh_service.go +++ b/backend/internal/service/token_refresh_service.go @@ -173,6 +173,16 @@ func (s *TokenRefreshService) refreshWithRetry(ctx context.Context, account *Acc } 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 }