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
c10267ce
Commit
c10267ce
authored
Feb 24, 2026
by
cagedbird043
Browse files
fix: 刷新用量成功后自动清理账号可恢复错误状态
parent
7be5e173
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/internal/service/account_usage_service.go
View file @
c10267ce
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"log"
"log"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -217,12 +218,20 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
...
@@ -217,12 +218,20 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
}
}
if
account
.
Platform
==
PlatformGemini
{
if
account
.
Platform
==
PlatformGemini
{
return
s
.
getGeminiUsage
(
ctx
,
account
)
usage
,
err
:=
s
.
getGeminiUsage
(
ctx
,
account
)
if
err
==
nil
{
s
.
tryClearRecoverableAccountError
(
ctx
,
account
)
}
return
usage
,
err
}
}
// Antigravity 平台:使用 AntigravityQuotaFetcher 获取额度
// Antigravity 平台:使用 AntigravityQuotaFetcher 获取额度
if
account
.
Platform
==
PlatformAntigravity
{
if
account
.
Platform
==
PlatformAntigravity
{
return
s
.
getAntigravityUsage
(
ctx
,
account
)
usage
,
err
:=
s
.
getAntigravityUsage
(
ctx
,
account
)
if
err
==
nil
{
s
.
tryClearRecoverableAccountError
(
ctx
,
account
)
}
return
usage
,
err
}
}
// 只有oauth类型账号可以通过API获取usage(有profile scope)
// 只有oauth类型账号可以通过API获取usage(有profile scope)
...
@@ -256,6 +265,7 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
...
@@ -256,6 +265,7 @@ func (s *AccountUsageService) GetUsage(ctx context.Context, accountID int64) (*U
// 4. 添加窗口统计(有独立缓存,1 分钟)
// 4. 添加窗口统计(有独立缓存,1 分钟)
s
.
addWindowStats
(
ctx
,
account
,
usage
)
s
.
addWindowStats
(
ctx
,
account
,
usage
)
s
.
tryClearRecoverableAccountError
(
ctx
,
account
)
return
usage
,
nil
return
usage
,
nil
}
}
...
@@ -486,6 +496,32 @@ func parseTime(s string) (time.Time, error) {
...
@@ -486,6 +496,32 @@ func parseTime(s string) (time.Time, error) {
return
time
.
Time
{},
fmt
.
Errorf
(
"unable to parse time: %s"
,
s
)
return
time
.
Time
{},
fmt
.
Errorf
(
"unable to parse time: %s"
,
s
)
}
}
func
(
s
*
AccountUsageService
)
tryClearRecoverableAccountError
(
ctx
context
.
Context
,
account
*
Account
)
{
if
account
==
nil
||
account
.
Status
!=
StatusError
{
return
}
msg
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
account
.
ErrorMessage
))
if
msg
==
""
{
return
}
if
!
strings
.
Contains
(
msg
,
"token refresh failed"
)
&&
!
strings
.
Contains
(
msg
,
"invalid_client"
)
&&
!
strings
.
Contains
(
msg
,
"missing_project_id"
)
&&
!
strings
.
Contains
(
msg
,
"unauthenticated"
)
{
return
}
if
err
:=
s
.
accountRepo
.
ClearError
(
ctx
,
account
.
ID
);
err
!=
nil
{
log
.
Printf
(
"[usage] failed to clear recoverable account error for account %d: %v"
,
account
.
ID
,
err
)
return
}
account
.
Status
=
StatusActive
account
.
ErrorMessage
=
""
}
// buildUsageInfo 构建UsageInfo
// buildUsageInfo 构建UsageInfo
func
(
s
*
AccountUsageService
)
buildUsageInfo
(
resp
*
ClaudeUsageResponse
,
updatedAt
*
time
.
Time
)
*
UsageInfo
{
func
(
s
*
AccountUsageService
)
buildUsageInfo
(
resp
*
ClaudeUsageResponse
,
updatedAt
*
time
.
Time
)
*
UsageInfo
{
info
:=
&
UsageInfo
{
info
:=
&
UsageInfo
{
...
...
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