mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user