diff --git a/backend/internal/handler/admin/account_handler.go b/backend/internal/handler/admin/account_handler.go index 2fc1c806..ce5cffe4 100644 --- a/backend/internal/handler/admin/account_handler.go +++ b/backend/internal/handler/admin/account_handler.go @@ -539,6 +539,8 @@ func (h *AccountHandler) Create(c *gin.Context) { } // Antigravity OAuth: 新账号直接设置隐私 h.adminService.ForceAntigravityPrivacy(ctx, account) + // OpenAI OAuth: 新账号直接设置隐私 + h.adminService.ForceOpenAIPrivacy(ctx, account) return h.buildAccountResponseWithRuntime(ctx, account), nil }) if err != nil { @@ -1161,8 +1163,9 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) { success := 0 failed := 0 results := make([]gin.H, 0, len(req.Accounts)) - // 收集需要异步设置隐私的 Antigravity OAuth 账号 - var privacyAccounts []*service.Account + // 收集需要异步设置隐私的 OAuth 账号 + var antigravityPrivacyAccounts []*service.Account + var openaiPrivacyAccounts []*service.Account for _, item := range req.Accounts { if item.RateMultiplier != nil && *item.RateMultiplier < 0 { @@ -1205,9 +1208,14 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) { }) continue } - // 收集 Antigravity OAuth 账号,稍后异步设置隐私 - if account.Platform == service.PlatformAntigravity && account.Type == service.AccountTypeOAuth { - privacyAccounts = append(privacyAccounts, account) + // 收集需要异步设置隐私的 OAuth 账号 + if account.Type == service.AccountTypeOAuth { + switch account.Platform { + case service.PlatformAntigravity: + antigravityPrivacyAccounts = append(antigravityPrivacyAccounts, account) + case service.PlatformOpenAI: + openaiPrivacyAccounts = append(openaiPrivacyAccounts, account) + } } success++ results = append(results, gin.H{ @@ -1217,9 +1225,10 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) { }) } - // 异步设置 Antigravity 隐私,避免批量创建时阻塞请求 - if len(privacyAccounts) > 0 { - adminSvc := h.adminService + // 异步设置隐私,避免批量创建时阻塞请求 + adminSvc := h.adminService + if len(antigravityPrivacyAccounts) > 0 { + accounts := antigravityPrivacyAccounts go func() { defer func() { if r := recover(); r != nil { @@ -1227,11 +1236,25 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) { } }() bgCtx := context.Background() - for _, acc := range privacyAccounts { + for _, acc := range accounts { adminSvc.ForceAntigravityPrivacy(bgCtx, acc) } }() } + if len(openaiPrivacyAccounts) > 0 { + accounts := openaiPrivacyAccounts + go func() { + defer func() { + if r := recover(); r != nil { + slog.Error("batch_create_openai_privacy_panic", "recover", r) + } + }() + bgCtx := context.Background() + for _, acc := range accounts { + adminSvc.ForceOpenAIPrivacy(bgCtx, acc) + } + }() + } return gin.H{ "success": success,