mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 17:39:16 +00:00
fix: 修复codex限流自动恢复问题
This commit is contained in:
@@ -694,13 +694,17 @@ async function getAllAccounts() {
|
|||||||
// 添加限流状态信息(统一格式)
|
// 添加限流状态信息(统一格式)
|
||||||
rateLimitStatus: rateLimitInfo
|
rateLimitStatus: rateLimitInfo
|
||||||
? {
|
? {
|
||||||
|
status: rateLimitInfo.status,
|
||||||
isRateLimited: rateLimitInfo.isRateLimited,
|
isRateLimited: rateLimitInfo.isRateLimited,
|
||||||
rateLimitedAt: rateLimitInfo.rateLimitedAt,
|
rateLimitedAt: rateLimitInfo.rateLimitedAt,
|
||||||
|
rateLimitResetAt: rateLimitInfo.rateLimitResetAt,
|
||||||
minutesRemaining: rateLimitInfo.minutesRemaining
|
minutesRemaining: rateLimitInfo.minutesRemaining
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
|
status: 'normal',
|
||||||
isRateLimited: false,
|
isRateLimited: false,
|
||||||
rateLimitedAt: null,
|
rateLimitedAt: null,
|
||||||
|
rateLimitResetAt: null,
|
||||||
minutesRemaining: 0
|
minutesRemaining: 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -979,34 +983,39 @@ async function getAccountRateLimitInfo(accountId) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.rateLimitStatus === 'limited') {
|
const status = account.rateLimitStatus || 'normal'
|
||||||
|
const rateLimitedAt = account.rateLimitedAt || null
|
||||||
|
const rateLimitResetAt = account.rateLimitResetAt || null
|
||||||
|
|
||||||
|
if (status === 'limited') {
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
let remainingTime = 0
|
let remainingTime = 0
|
||||||
|
|
||||||
// 优先使用 rateLimitResetAt 字段(精确的重置时间)
|
if (rateLimitResetAt) {
|
||||||
if (account.rateLimitResetAt) {
|
const resetAt = new Date(rateLimitResetAt).getTime()
|
||||||
const resetAt = new Date(account.rateLimitResetAt).getTime()
|
|
||||||
remainingTime = Math.max(0, resetAt - now)
|
remainingTime = Math.max(0, resetAt - now)
|
||||||
}
|
} else if (rateLimitedAt) {
|
||||||
// 回退到使用 rateLimitedAt + 默认1小时
|
const limitedAt = new Date(rateLimitedAt).getTime()
|
||||||
else if (account.rateLimitedAt) {
|
|
||||||
const limitedAt = new Date(account.rateLimitedAt).getTime()
|
|
||||||
const limitDuration = 60 * 60 * 1000 // 默认1小时
|
const limitDuration = 60 * 60 * 1000 // 默认1小时
|
||||||
remainingTime = Math.max(0, limitedAt + limitDuration - now)
|
remainingTime = Math.max(0, limitedAt + limitDuration - now)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const minutesRemaining = remainingTime > 0 ? Math.ceil(remainingTime / (60 * 1000)) : 0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isRateLimited: remainingTime > 0,
|
status,
|
||||||
rateLimitedAt: account.rateLimitedAt,
|
isRateLimited: minutesRemaining > 0,
|
||||||
rateLimitResetAt: account.rateLimitResetAt,
|
rateLimitedAt,
|
||||||
minutesRemaining: Math.ceil(remainingTime / (60 * 1000))
|
rateLimitResetAt,
|
||||||
|
minutesRemaining
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
status,
|
||||||
isRateLimited: false,
|
isRateLimited: false,
|
||||||
rateLimitedAt: null,
|
rateLimitedAt,
|
||||||
rateLimitResetAt: null,
|
rateLimitResetAt,
|
||||||
minutesRemaining: 0
|
minutesRemaining: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,12 +138,12 @@ class RateLimitCleanupService {
|
|||||||
const accounts = await openaiAccountService.getAllAccounts()
|
const accounts = await openaiAccountService.getAllAccounts()
|
||||||
|
|
||||||
for (const account of accounts) {
|
for (const account of accounts) {
|
||||||
// 检查是否处于限流状态(兼容对象和字符串格式)
|
const { rateLimitStatus } = account
|
||||||
const isRateLimited =
|
const isRateLimited =
|
||||||
account.rateLimitStatus === 'limited' ||
|
rateLimitStatus === 'limited' ||
|
||||||
(account.rateLimitStatus &&
|
(rateLimitStatus &&
|
||||||
typeof account.rateLimitStatus === 'object' &&
|
typeof rateLimitStatus === 'object' &&
|
||||||
account.rateLimitStatus.status === 'limited')
|
(rateLimitStatus.status === 'limited' || rateLimitStatus.isRateLimited === true))
|
||||||
|
|
||||||
if (isRateLimited) {
|
if (isRateLimited) {
|
||||||
result.checked++
|
result.checked++
|
||||||
|
|||||||
Reference in New Issue
Block a user