mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复OpenAI账户统计问题
- 添加缺失的recordUsage方法,统一updateAccountUsage实现 - 优化模型支持检查逻辑,未设置supportedModels时支持所有模型 - 修复gpt-5模型请求被拒绝的问题 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -549,22 +549,29 @@ async function getAccountRateLimitInfo(accountId) {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新账户使用统计
|
||||
async function updateAccountUsage(accountId, tokens) {
|
||||
// 更新账户使用统计(tokens参数可选,默认为0,仅更新最后使用时间)
|
||||
async function updateAccountUsage(accountId, tokens = 0) {
|
||||
const account = await getAccount(accountId)
|
||||
if (!account) {
|
||||
return
|
||||
}
|
||||
|
||||
const totalUsage = parseInt(account.totalUsage || 0) + tokens
|
||||
const lastUsedAt = new Date().toISOString()
|
||||
const updates = {
|
||||
lastUsedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
await updateAccount(accountId, {
|
||||
totalUsage: totalUsage.toString(),
|
||||
lastUsedAt
|
||||
})
|
||||
// 如果有 tokens 参数且大于0,同时更新使用统计
|
||||
if (tokens > 0) {
|
||||
const totalUsage = parseInt(account.totalUsage || 0) + tokens
|
||||
updates.totalUsage = totalUsage.toString()
|
||||
}
|
||||
|
||||
await updateAccount(accountId, updates)
|
||||
}
|
||||
|
||||
// 为了兼容性,保留recordUsage作为updateAccountUsage的别名
|
||||
const recordUsage = updateAccountUsage
|
||||
|
||||
module.exports = {
|
||||
createAccount,
|
||||
getAccount,
|
||||
@@ -578,6 +585,7 @@ module.exports = {
|
||||
toggleSchedulable,
|
||||
getAccountRateLimitInfo,
|
||||
updateAccountUsage,
|
||||
recordUsage, // 别名,指向updateAccountUsage
|
||||
encrypt,
|
||||
decrypt
|
||||
}
|
||||
|
||||
@@ -135,7 +135,8 @@ class UnifiedOpenAIScheduler {
|
||||
if (boundAccount && boundAccount.isActive === 'true' && boundAccount.status !== 'error') {
|
||||
const isRateLimited = await this.isAccountRateLimited(boundAccount.id)
|
||||
if (!isRateLimited) {
|
||||
// 检查模型支持
|
||||
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||
if (
|
||||
requestedModel &&
|
||||
boundAccount.supportedModels &&
|
||||
@@ -188,7 +189,8 @@ class UnifiedOpenAIScheduler {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查模型支持
|
||||
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
||||
const modelSupported = account.supportedModels.includes(requestedModel)
|
||||
if (!modelSupported) {
|
||||
@@ -414,7 +416,8 @@ class UnifiedOpenAIScheduler {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查模型支持
|
||||
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
||||
const modelSupported = account.supportedModels.includes(requestedModel)
|
||||
if (!modelSupported) {
|
||||
|
||||
Reference in New Issue
Block a user