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
cd9d31f5
Commit
cd9d31f5
authored
Dec 28, 2025
by
shaw
Browse files
fix: 修复NeedsRefresh bug导致刷新失败的问题
parent
d3e73f12
Changes
5
Show whitespace changes
Inline
Side-by-side
.gitignore
View file @
cd9d31f5
...
...
@@ -32,6 +32,7 @@ frontend/node_modules/
frontend/dist/
*.local
*.tsbuildinfo
vite.config.d.ts
# 日志
npm-debug.log*
...
...
backend/internal/service/account.go
View file @
cd9d31f5
package
service
import
(
"encoding/json"
"strconv"
"time"
)
...
...
@@ -94,6 +95,9 @@ func (a *Account) GetCredential(key string) string {
switch
val
:=
v
.
(
type
)
{
case
string
:
return
val
case
json
.
Number
:
// GORM datatypes.JSONMap 使用 UseNumber() 解析,数字类型为 json.Number
return
val
.
String
()
case
float64
:
// JSON 解析后数字默认为 float64
return
strconv
.
FormatInt
(
int64
(
val
),
10
)
...
...
backend/internal/service/token_refresh_service.go
View file @
cd9d31f5
...
...
@@ -106,6 +106,9 @@ func (s *TokenRefreshService) processRefresh() {
return
}
totalAccounts
:=
len
(
accounts
)
oauthAccounts
:=
0
// 可刷新的OAuth账号数
needsRefresh
:=
0
// 需要刷新的账号数
refreshed
,
failed
:=
0
,
0
for
i
:=
range
accounts
{
...
...
@@ -117,11 +120,15 @@ func (s *TokenRefreshService) processRefresh() {
continue
}
oauthAccounts
++
// 检查是否需要刷新
if
!
refresher
.
NeedsRefresh
(
account
,
refreshWindow
)
{
continue
break
// 不需要刷新,跳过
}
needsRefresh
++
// 执行刷新
if
err
:=
s
.
refreshWithRetry
(
ctx
,
account
,
refresher
);
err
!=
nil
{
log
.
Printf
(
"[TokenRefresh] Account %d (%s) failed: %v"
,
account
.
ID
,
account
.
Name
,
err
)
...
...
@@ -136,9 +143,9 @@ func (s *TokenRefreshService) processRefresh() {
}
}
if
refreshed
>
0
||
failed
>
0
{
log
.
Printf
(
"[TokenRefresh] Cycle complete:
%d refreshed, %d failed"
,
refreshed
,
failed
)
}
// 始终打印周期日志,便于跟踪服务运行状态
log
.
Printf
(
"[TokenRefresh] Cycle complete:
total=%d, oauth=%d, needs_refresh=%d
, refreshed
=%d
, failed
=%d"
,
totalAccounts
,
oauthAccounts
,
needsRefresh
,
refreshed
,
failed
)
}
// listActiveAccounts 获取所有active状态的账号
...
...
backend/internal/service/token_refresher.go
View file @
cd9d31f5
...
...
@@ -43,19 +43,13 @@ func (r *ClaudeTokenRefresher) CanRefresh(account *Account) bool {
// NeedsRefresh 检查token是否需要刷新
// 基于 expires_at 字段判断是否在刷新窗口内
func
(
r
*
ClaudeTokenRefresher
)
NeedsRefresh
(
account
*
Account
,
refreshWindow
time
.
Duration
)
bool
{
var
expiresAt
int64
// 方式1: 通过 GetCredential 获取(处理字符串和部分数字类型)
if
s
:=
account
.
GetCredential
(
"expires_at"
);
s
!=
""
{
v
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
64
)
if
err
!=
nil
{
s
:=
account
.
GetCredential
(
"expires_at"
)
if
s
==
""
{
return
false
}
expiresAt
=
v
}
else
if
v
,
ok
:=
account
.
Credentials
[
"expires_at"
]
.
(
float64
);
ok
{
// 方式2: 直接获取 float64(处理某些 JSON 解码器将数字解析为 float64 的情况)
expiresAt
=
int64
(
v
)
}
else
{
expiresAt
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
64
)
if
err
!=
nil
{
return
false
}
...
...
frontend/vite.config.d.ts
deleted
100644 → 0
View file @
d3e73f12
declare
const
_default
:
import
(
'
vite
'
).
UserConfig
export
default
_default
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