mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 17:49:16 +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) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新账户使用统计
|
// 更新账户使用统计(tokens参数可选,默认为0,仅更新最后使用时间)
|
||||||
async function updateAccountUsage(accountId, tokens) {
|
async function updateAccountUsage(accountId, tokens = 0) {
|
||||||
const account = await getAccount(accountId)
|
const account = await getAccount(accountId)
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalUsage = parseInt(account.totalUsage || 0) + tokens
|
const updates = {
|
||||||
const lastUsedAt = new Date().toISOString()
|
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 = {
|
module.exports = {
|
||||||
createAccount,
|
createAccount,
|
||||||
getAccount,
|
getAccount,
|
||||||
@@ -578,6 +585,7 @@ module.exports = {
|
|||||||
toggleSchedulable,
|
toggleSchedulable,
|
||||||
getAccountRateLimitInfo,
|
getAccountRateLimitInfo,
|
||||||
updateAccountUsage,
|
updateAccountUsage,
|
||||||
|
recordUsage, // 别名,指向updateAccountUsage
|
||||||
encrypt,
|
encrypt,
|
||||||
decrypt
|
decrypt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ class UnifiedOpenAIScheduler {
|
|||||||
if (boundAccount && boundAccount.isActive === 'true' && boundAccount.status !== 'error') {
|
if (boundAccount && boundAccount.isActive === 'true' && boundAccount.status !== 'error') {
|
||||||
const isRateLimited = await this.isAccountRateLimited(boundAccount.id)
|
const isRateLimited = await this.isAccountRateLimited(boundAccount.id)
|
||||||
if (!isRateLimited) {
|
if (!isRateLimited) {
|
||||||
// 检查模型支持
|
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||||
|
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||||
if (
|
if (
|
||||||
requestedModel &&
|
requestedModel &&
|
||||||
boundAccount.supportedModels &&
|
boundAccount.supportedModels &&
|
||||||
@@ -188,7 +189,8 @@ class UnifiedOpenAIScheduler {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查模型支持
|
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||||
|
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||||
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
||||||
const modelSupported = account.supportedModels.includes(requestedModel)
|
const modelSupported = account.supportedModels.includes(requestedModel)
|
||||||
if (!modelSupported) {
|
if (!modelSupported) {
|
||||||
@@ -414,7 +416,8 @@ class UnifiedOpenAIScheduler {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查模型支持
|
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||||
|
// 如果没有设置supportedModels或为空数组,则支持所有模型
|
||||||
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
if (requestedModel && account.supportedModels && account.supportedModels.length > 0) {
|
||||||
const modelSupported = account.supportedModels.includes(requestedModel)
|
const modelSupported = account.supportedModels.includes(requestedModel)
|
||||||
if (!modelSupported) {
|
if (!modelSupported) {
|
||||||
|
|||||||
Reference in New Issue
Block a user