mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3040209f20 | ||
|
|
f5aca74623 | ||
|
|
8b9788eeb4 | ||
|
|
66a9e2e6bb |
@@ -1013,7 +1013,8 @@ func IsUpstreamBillingProbeIdentity(platform, accountType string) bool {
|
||||
}
|
||||
switch platform {
|
||||
case PlatformOpenAI, PlatformAnthropic, PlatformGemini, PlatformAntigravity, PlatformGrok,
|
||||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo:
|
||||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo,
|
||||
PlatformTypeSafe:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -1052,6 +1053,7 @@ var upstreamBillingProbeOfficialAPIDomains = []string{
|
||||
"bigmodel.cn",
|
||||
"deepseek.com",
|
||||
"opencode.ai",
|
||||
"typesafe.ai",
|
||||
}
|
||||
|
||||
func upstreamBillingProbeTargetIsOfficialAPI(baseURL string) bool {
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestUpstreamBillingProbeIdentityCoversAllAPIKeyPlatforms(t *testing.T) {
|
||||
for _, platform := range []string{
|
||||
PlatformOpenAI, PlatformGrok, PlatformAnthropic, PlatformGemini, PlatformAntigravity,
|
||||
PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo,
|
||||
PlatformTypeSafe,
|
||||
} {
|
||||
require.True(t, IsUpstreamBillingProbeIdentity(platform, AccountTypeAPIKey), platform)
|
||||
require.True(t, isUpstreamBillingProbeAccount(&Account{Platform: platform, Type: AccountTypeAPIKey}), platform)
|
||||
@@ -174,6 +175,8 @@ func TestUpstreamBillingProbeOfficialAPIBaseURLIsUnsupportedWithoutRequest(t *te
|
||||
{PlatformDeepseek, "https://api.deepseek.com/anthropic"},
|
||||
{PlatformOpenCodeGo, "https://opencode.ai/zen/go/v1"},
|
||||
{PlatformOpenCodeGo, "https://opencode.ai/zen/go"},
|
||||
{PlatformTypeSafe, "https://api.typesafe.ai"},
|
||||
{PlatformTypeSafe, "https://api.typesafe.ai/v1"},
|
||||
}
|
||||
for i, tc := range cases {
|
||||
account := &Account{
|
||||
@@ -217,6 +220,7 @@ func TestUpstreamBillingProbeOfficialAPIHostMatchingIsNormalized(t *testing.T) {
|
||||
require.True(t, upstreamBillingProbeTargetIsOfficialAPI("https://api.deepseek.com/anthropic"))
|
||||
require.True(t, upstreamBillingProbeTargetIsOfficialAPI("https://opencode.ai/zen/go/v1"))
|
||||
require.True(t, upstreamBillingProbeTargetIsOfficialAPI("https://opencode.ai/zen/go"))
|
||||
require.True(t, upstreamBillingProbeTargetIsOfficialAPI("https://api.typesafe.ai"))
|
||||
// 相似但不同的注册域不拦:中转完全可能叫 *-x.ai 之外的任何名字。
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://relay.example/v1"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://notx.ai"))
|
||||
@@ -228,6 +232,7 @@ func TestUpstreamBillingProbeOfficialAPIHostMatchingIsNormalized(t *testing.T) {
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://notmoonshot.cn/v1"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://moonshot.cn.evil.example/v1"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://kimi.example/v1"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://nottypesafe.ai"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://notbigmodel.cn"))
|
||||
require.False(t, upstreamBillingProbeTargetIsOfficialAPI("https://deepseek.example.com"))
|
||||
}
|
||||
@@ -276,3 +281,16 @@ func TestUpstreamBillingProbeSetAccountEnabledAcceptsGrokAPIKey(t *testing.T) {
|
||||
err := svc.SetAccountEnabled(context.Background(), grokOAuth.ID, true)
|
||||
require.ErrorIs(t, err, ErrUpstreamBillingProbeAccountInvalid)
|
||||
}
|
||||
|
||||
func TestBuildAccountForCreateAcceptsTypeSafeAPIKeyWithProbeEnabled(t *testing.T) {
|
||||
enabled := true
|
||||
account, err := buildAccountForCreate(&CreateAccountInput{
|
||||
Name: "typesafe",
|
||||
Platform: PlatformTypeSafe,
|
||||
Type: AccountTypeAPIKey,
|
||||
Credentials: map[string]any{"api_key": "ts-key", "base_url": "https://api.typesafe.ai"},
|
||||
ProbeEnabled: &enabled,
|
||||
}, map[string]any{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, account.Extra[UpstreamBillingProbeEnabledExtraKey])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user