feat(privacy): 创建/批量创建 OpenAI OAuth 账号时异步设置隐私模式
参照 Antigravity 的模式,单个创建时同步调用 ForceOpenAIPrivacy, 批量创建时收集 OpenAI OAuth 账号后异步 goroutine 设置,避免阻塞请求。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -539,6 +539,8 @@ func (h *AccountHandler) Create(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// Antigravity OAuth: 新账号直接设置隐私
|
// Antigravity OAuth: 新账号直接设置隐私
|
||||||
h.adminService.ForceAntigravityPrivacy(ctx, account)
|
h.adminService.ForceAntigravityPrivacy(ctx, account)
|
||||||
|
// OpenAI OAuth: 新账号直接设置隐私
|
||||||
|
h.adminService.ForceOpenAIPrivacy(ctx, account)
|
||||||
return h.buildAccountResponseWithRuntime(ctx, account), nil
|
return h.buildAccountResponseWithRuntime(ctx, account), nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1161,8 +1163,9 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) {
|
|||||||
success := 0
|
success := 0
|
||||||
failed := 0
|
failed := 0
|
||||||
results := make([]gin.H, 0, len(req.Accounts))
|
results := make([]gin.H, 0, len(req.Accounts))
|
||||||
// 收集需要异步设置隐私的 Antigravity OAuth 账号
|
// 收集需要异步设置隐私的 OAuth 账号
|
||||||
var privacyAccounts []*service.Account
|
var antigravityPrivacyAccounts []*service.Account
|
||||||
|
var openaiPrivacyAccounts []*service.Account
|
||||||
|
|
||||||
for _, item := range req.Accounts {
|
for _, item := range req.Accounts {
|
||||||
if item.RateMultiplier != nil && *item.RateMultiplier < 0 {
|
if item.RateMultiplier != nil && *item.RateMultiplier < 0 {
|
||||||
@@ -1205,9 +1208,14 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 收集 Antigravity OAuth 账号,稍后异步设置隐私
|
// 收集需要异步设置隐私的 OAuth 账号
|
||||||
if account.Platform == service.PlatformAntigravity && account.Type == service.AccountTypeOAuth {
|
if account.Type == service.AccountTypeOAuth {
|
||||||
privacyAccounts = append(privacyAccounts, account)
|
switch account.Platform {
|
||||||
|
case service.PlatformAntigravity:
|
||||||
|
antigravityPrivacyAccounts = append(antigravityPrivacyAccounts, account)
|
||||||
|
case service.PlatformOpenAI:
|
||||||
|
openaiPrivacyAccounts = append(openaiPrivacyAccounts, account)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
success++
|
success++
|
||||||
results = append(results, gin.H{
|
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() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@@ -1227,11 +1236,25 @@ func (h *AccountHandler) BatchCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
bgCtx := context.Background()
|
bgCtx := context.Background()
|
||||||
for _, acc := range privacyAccounts {
|
for _, acc := range accounts {
|
||||||
adminSvc.ForceAntigravityPrivacy(bgCtx, acc)
|
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{
|
return gin.H{
|
||||||
"success": success,
|
"success": success,
|
||||||
|
|||||||
Reference in New Issue
Block a user