@@ -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
@@ -1420,13 +1425,30 @@ func (s *adminServiceImpl) CreateAccount(ctx context.Context, input *CreateAccou
14201425 }
14211426 }
14221427
1428+ // OpenAI OAuth: attempt to disable training data sharing
1429+ extra := input .Extra
1430+ if input .Platform == PlatformOpenAI && input .Type == AccountTypeOAuth {
1431+ if token , _ := input .Credentials ["access_token" ].(string ); token != "" {
1432+ var proxyURL string
1433+ if input .ProxyID != nil {
1434+ if p , err := s .proxyRepo .GetByID (ctx , * input .ProxyID ); err == nil && p != nil {
1435+ proxyURL = p .URL ()
1436+ }
1437+ }
1438+ if extra == nil {
1439+ extra = make (map [string ]any )
1440+ }
1441+ extra ["privacy_mode" ] = disableOpenAITraining (ctx , s .privacyClientFactory , token , proxyURL )
1442+ }
1443+ }
1444+
14231445 account := & Account {
14241446 Name : input .Name ,
14251447 Notes : normalizeAccountNotes (input .Notes ),
14261448 Platform : input .Platform ,
14271449 Type : input .Type ,
14281450 Credentials : input .Credentials ,
1429- Extra : input . Extra ,
1451+ Extra : extra ,
14301452 ProxyID : input .ProxyID ,
14311453 Concurrency : input .Concurrency ,
14321454 Priority : input .Priority ,
@@ -2502,3 +2524,39 @@ func (e *MixedChannelError) Error() string {
25022524func (s * adminServiceImpl ) ResetAccountQuota (ctx context.Context , id int64 ) error {
25032525 return s .accountRepo .ResetQuotaUsed (ctx , id )
25042526}
2527+
2528+ // EnsureOpenAIPrivacy 检查 OpenAI OAuth 账号是否已设置 privacy_mode,
2529+ // 未设置则调用 disableOpenAITraining 并持久化到 Extra,返回设置的 mode 值。
2530+ func (s * adminServiceImpl ) EnsureOpenAIPrivacy (ctx context.Context , account * Account ) string {
2531+ if account .Platform != PlatformOpenAI || account .Type != AccountTypeOAuth {
2532+ return ""
2533+ }
2534+ if s .privacyClientFactory == nil {
2535+ return ""
2536+ }
2537+ if account .Extra != nil {
2538+ if _ , ok := account .Extra ["privacy_mode" ]; ok {
2539+ return ""
2540+ }
2541+ }
2542+
2543+ token , _ := account .Credentials ["access_token" ].(string )
2544+ if token == "" {
2545+ return ""
2546+ }
2547+
2548+ var proxyURL string
2549+ if account .ProxyID != nil {
2550+ if p , err := s .proxyRepo .GetByID (ctx , * account .ProxyID ); err == nil && p != nil {
2551+ proxyURL = p .URL ()
2552+ }
2553+ }
2554+
2555+ mode := disableOpenAITraining (ctx , s .privacyClientFactory , token , proxyURL )
2556+ if mode == "" {
2557+ return ""
2558+ }
2559+
2560+ _ = s .accountRepo .UpdateExtra (ctx , account .ID , map [string ]any {"privacy_mode" : mode })
2561+ return mode
2562+ }
0 commit comments