Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
b688ebee
Unverified
Commit
b688ebee
authored
Mar 27, 2026
by
Wesley Liddick
Committed by
GitHub
Mar 27, 2026
Browse files
Merge pull request #1215 from weak-fox/fix/privacy-retry-failed-mode
fix: 允许 OpenAI privacy_mode修改失败后能在 token 刷新时重试
parents
1854050d
ccd42c1d
Changes
4
Show whitespace changes
Inline
Side-by-side
backend/internal/service/admin_service.go
View file @
b688ebee
...
...
@@ -2639,11 +2639,9 @@ func (s *adminServiceImpl) EnsureOpenAIPrivacy(ctx context.Context, account *Acc
if
s
.
privacyClientFactory
==
nil
{
return
""
}
if
account
.
Extra
!=
nil
{
if
_
,
ok
:=
account
.
Extra
[
"privacy_mode"
];
ok
{
if
shouldSkipOpenAIPrivacyEnsure
(
account
.
Extra
)
{
return
""
}
}
token
,
_
:=
account
.
Credentials
[
"access_token"
]
.
(
string
)
if
token
==
""
{
...
...
backend/internal/service/openai_privacy_retry_test.go
0 → 100644
View file @
b688ebee
//go:build unit
package
service
import
(
"context"
"errors"
"testing"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/imroc/req/v3"
"github.com/stretchr/testify/require"
)
func
TestAdminService_EnsureOpenAIPrivacy_RetriesNonSuccessModes
(
t
*
testing
.
T
)
{
t
.
Parallel
()
for
_
,
mode
:=
range
[]
string
{
PrivacyModeFailed
,
PrivacyModeCFBlocked
}
{
t
.
Run
(
mode
,
func
(
t
*
testing
.
T
)
{
t
.
Parallel
()
privacyCalls
:=
0
svc
:=
&
adminServiceImpl
{
accountRepo
:
&
mockAccountRepoForGemini
{},
privacyClientFactory
:
func
(
proxyURL
string
)
(
*
req
.
Client
,
error
)
{
privacyCalls
++
return
nil
,
errors
.
New
(
"factory failed"
)
},
}
account
:=
&
Account
{
ID
:
101
,
Platform
:
PlatformOpenAI
,
Type
:
AccountTypeOAuth
,
Credentials
:
map
[
string
]
any
{
"access_token"
:
"token-1"
,
},
Extra
:
map
[
string
]
any
{
"privacy_mode"
:
mode
,
},
}
got
:=
svc
.
EnsureOpenAIPrivacy
(
context
.
Background
(),
account
)
require
.
Equal
(
t
,
PrivacyModeFailed
,
got
)
require
.
Equal
(
t
,
1
,
privacyCalls
)
})
}
}
func
TestTokenRefreshService_ensureOpenAIPrivacy_RetriesNonSuccessModes
(
t
*
testing
.
T
)
{
t
.
Parallel
()
cfg
:=
&
config
.
Config
{
TokenRefresh
:
config
.
TokenRefreshConfig
{
MaxRetries
:
1
,
RetryBackoffSeconds
:
0
,
},
}
for
_
,
mode
:=
range
[]
string
{
PrivacyModeFailed
,
PrivacyModeCFBlocked
}
{
t
.
Run
(
mode
,
func
(
t
*
testing
.
T
)
{
t
.
Parallel
()
service
:=
NewTokenRefreshService
(
&
tokenRefreshAccountRepo
{},
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
cfg
,
nil
)
privacyCalls
:=
0
service
.
SetPrivacyDeps
(
func
(
proxyURL
string
)
(
*
req
.
Client
,
error
)
{
privacyCalls
++
return
nil
,
errors
.
New
(
"factory failed"
)
},
nil
)
account
:=
&
Account
{
ID
:
202
,
Platform
:
PlatformOpenAI
,
Type
:
AccountTypeOAuth
,
Credentials
:
map
[
string
]
any
{
"access_token"
:
"token-2"
,
},
Extra
:
map
[
string
]
any
{
"privacy_mode"
:
mode
,
},
}
service
.
ensureOpenAIPrivacy
(
context
.
Background
(),
account
)
require
.
Equal
(
t
,
1
,
privacyCalls
)
})
}
}
backend/internal/service/openai_privacy_service.go
View file @
b688ebee
...
...
@@ -22,6 +22,19 @@ const (
PrivacyModeCFBlocked
=
"training_set_cf_blocked"
)
func
shouldSkipOpenAIPrivacyEnsure
(
extra
map
[
string
]
any
)
bool
{
if
extra
==
nil
{
return
false
}
raw
,
ok
:=
extra
[
"privacy_mode"
]
if
!
ok
{
return
false
}
mode
,
_
:=
raw
.
(
string
)
mode
=
strings
.
TrimSpace
(
mode
)
return
mode
!=
PrivacyModeFailed
&&
mode
!=
PrivacyModeCFBlocked
}
// disableOpenAITraining calls ChatGPT settings API to turn off "Improve the model for everyone".
// Returns privacy_mode value: "training_off" on success, "cf_blocked" / "failed" on failure.
func
disableOpenAITraining
(
ctx
context
.
Context
,
clientFactory
PrivacyClientFactory
,
accessToken
,
proxyURL
string
)
string
{
...
...
backend/internal/service/token_refresh_service.go
View file @
b688ebee
...
...
@@ -443,12 +443,9 @@ func (s *TokenRefreshService) ensureOpenAIPrivacy(ctx context.Context, account *
if
s
.
privacyClientFactory
==
nil
{
return
}
// 已设置过则跳过
if
account
.
Extra
!=
nil
{
if
_
,
ok
:=
account
.
Extra
[
"privacy_mode"
];
ok
{
if
shouldSkipOpenAIPrivacyEnsure
(
account
.
Extra
)
{
return
}
}
token
,
_
:=
account
.
Credentials
[
"access_token"
]
.
(
string
)
if
token
==
""
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment