@@ -57,6 +57,8 @@ type AdminService interface {
5757 RefreshAccountCredentials (ctx context.Context , id int64 ) (* Account , error )
5858 ClearAccountError (ctx context.Context , id int64 ) (* Account , error )
5959 SetAccountError (ctx context.Context , id int64 , errorMsg string ) error
60+ // EnsureOpenAIPrivacy 检查 OpenAI OAuth 账号 privacy_mode,未设置则尝试关闭训练数据共享并持久化。
61+ EnsureOpenAIPrivacy (ctx context.Context , account * Account ) string
6062 SetAccountSchedulable (ctx context.Context , id int64 , schedulable bool ) (* Account , error )
6163 BulkUpdateAccounts (ctx context.Context , input * BulkUpdateAccountsInput ) (* BulkUpdateAccountsResult , error )
6264 CheckMixedChannelRisk (ctx context.Context , currentAccountID int64 , currentAccountPlatform string , groupIDs []int64 ) error
@@ -433,6 +435,7 @@ type adminServiceImpl struct {
433435 settingService * SettingService
434436 defaultSubAssigner DefaultSubscriptionAssigner
435437 userSubRepo UserSubscriptionRepository
438+ privacyClientFactory PrivacyClientFactory
436439}
437440
438441type userGroupRateBatchReader interface {
@@ -461,6 +464,7 @@ func NewAdminService(
461464 settingService * SettingService ,
462465 defaultSubAssigner DefaultSubscriptionAssigner ,
463466 userSubRepo UserSubscriptionRepository ,
467+ privacyClientFactory PrivacyClientFactory ,
464468) AdminService {
465469 return & adminServiceImpl {
466470 userRepo : userRepo ,
@@ -479,6 +483,7 @@ func NewAdminService(
479483 settingService : settingService ,
480484 defaultSubAssigner : defaultSubAssigner ,
481485 userSubRepo : userSubRepo ,
486+ privacyClientFactory : privacyClientFactory ,
482487 }
483488}
484489
@@ -2502,3 +2507,39 @@ func (e *MixedChannelError) Error() string {
25022507func (s * adminServiceImpl ) ResetAccountQuota (ctx context.Context , id int64 ) error {
25032508 return s .accountRepo .ResetQuotaUsed (ctx , id )
25042509}
2510+
2511+ // EnsureOpenAIPrivacy 检查 OpenAI OAuth 账号是否已设置 privacy_mode,
2512+ // 未设置则调用 disableOpenAITraining 并持久化到 Extra,返回设置的 mode 值。
2513+ func (s * adminServiceImpl ) EnsureOpenAIPrivacy (ctx context.Context , account * Account ) string {
2514+ if account .Platform != PlatformOpenAI || account .Type != AccountTypeOAuth {
2515+ return ""
2516+ }
2517+ if s .privacyClientFactory == nil {
2518+ return ""
2519+ }
2520+ if account .Extra != nil {
2521+ if _ , ok := account .Extra ["privacy_mode" ]; ok {
2522+ return ""
2523+ }
2524+ }
2525+
2526+ token , _ := account .Credentials ["access_token" ].(string )
2527+ if token == "" {
2528+ return ""
2529+ }
2530+
2531+ var proxyURL string
2532+ if account .ProxyID != nil {
2533+ if p , err := s .proxyRepo .GetByID (ctx , * account .ProxyID ); err == nil && p != nil {
2534+ proxyURL = p .URL ()
2535+ }
2536+ }
2537+
2538+ mode := disableOpenAITraining (ctx , s .privacyClientFactory , token , proxyURL )
2539+ if mode == "" {
2540+ return ""
2541+ }
2542+
2543+ _ = s .accountRepo .UpdateExtra (ctx , account .ID , map [string ]any {"privacy_mode" : mode })
2544+ return mode
2545+ }
0 commit comments