mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: 修复claude SSE捕获usage问题
This commit is contained in:
@@ -7614,7 +7614,10 @@ router.put('/openai-accounts/:id', authenticateAdmin, async (req, res) => {
|
||||
updateData.subscriptionExpiresAt = updates.expiresAt
|
||||
}
|
||||
|
||||
if (!hasOauthExpiry && Object.prototype.hasOwnProperty.call(updateData, 'subscriptionExpiresAt')) {
|
||||
if (
|
||||
!hasOauthExpiry &&
|
||||
Object.prototype.hasOwnProperty.call(updateData, 'subscriptionExpiresAt')
|
||||
) {
|
||||
delete updateData.expiresAt
|
||||
}
|
||||
|
||||
|
||||
@@ -146,9 +146,7 @@ async function createAccount(accountData) {
|
||||
isActive: accountData.isActive !== false ? 'true' : 'false',
|
||||
status: 'active',
|
||||
schedulable: accountData.schedulable !== false ? 'true' : 'false',
|
||||
subscriptionExpiresAt: normalizeSubscriptionExpiresAt(
|
||||
accountData.subscriptionExpiresAt || ''
|
||||
),
|
||||
subscriptionExpiresAt: normalizeSubscriptionExpiresAt(accountData.subscriptionExpiresAt || ''),
|
||||
createdAt: now,
|
||||
updatedAt: now
|
||||
}
|
||||
@@ -243,9 +241,7 @@ async function updateAccount(accountId, updates) {
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(updates, 'subscriptionExpiresAt')) {
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(
|
||||
updates.subscriptionExpiresAt
|
||||
)
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.subscriptionExpiresAt)
|
||||
} else if (Object.prototype.hasOwnProperty.call(updates, 'expiresAt')) {
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.expiresAt)
|
||||
delete updates.expiresAt
|
||||
|
||||
@@ -162,15 +162,15 @@ class BedrockAccountService {
|
||||
accountType: account.accountType,
|
||||
priority: account.priority,
|
||||
schedulable: account.schedulable,
|
||||
credentialType: account.credentialType,
|
||||
createdAt: account.createdAt,
|
||||
updatedAt: account.updatedAt,
|
||||
type: 'bedrock',
|
||||
hasCredentials: !!account.awsCredentials,
|
||||
expiresAt: account.expiresAt || null,
|
||||
subscriptionExpiresAt: account.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
credentialType: account.credentialType,
|
||||
createdAt: account.createdAt,
|
||||
updatedAt: account.updatedAt,
|
||||
type: 'bedrock',
|
||||
hasCredentials: !!account.awsCredentials,
|
||||
expiresAt: account.expiresAt || null,
|
||||
subscriptionExpiresAt: account.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 按优先级和名称排序
|
||||
|
||||
@@ -183,14 +183,14 @@ class CcrAccountService {
|
||||
schedulable: accountData.schedulable !== 'false', // 默认为true,只有明确设置为false才不可调度
|
||||
// 额度管理相关
|
||||
dailyQuota: parseFloat(accountData.dailyQuota || '0'),
|
||||
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
|
||||
lastResetDate: accountData.lastResetDate || '',
|
||||
quotaResetTime: accountData.quotaResetTime || '00:00',
|
||||
quotaStoppedAt: accountData.quotaStoppedAt || null,
|
||||
expiresAt: accountData.expiresAt || null,
|
||||
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
|
||||
lastResetDate: accountData.lastResetDate || '',
|
||||
quotaResetTime: accountData.quotaResetTime || '00:00',
|
||||
quotaStoppedAt: accountData.quotaStoppedAt || null,
|
||||
expiresAt: accountData.expiresAt || null,
|
||||
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return accounts
|
||||
|
||||
@@ -186,14 +186,14 @@ class ClaudeConsoleAccountService {
|
||||
schedulable: accountData.schedulable !== 'false', // 默认为true,只有明确设置为false才不可调度
|
||||
// 额度管理相关
|
||||
dailyQuota: parseFloat(accountData.dailyQuota || '0'),
|
||||
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
|
||||
lastResetDate: accountData.lastResetDate || '',
|
||||
quotaResetTime: accountData.quotaResetTime || '00:00',
|
||||
quotaStoppedAt: accountData.quotaStoppedAt || null,
|
||||
expiresAt: accountData.expiresAt || null,
|
||||
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
|
||||
lastResetDate: accountData.lastResetDate || '',
|
||||
quotaResetTime: accountData.quotaResetTime || '00:00',
|
||||
quotaStoppedAt: accountData.quotaStoppedAt || null,
|
||||
expiresAt: accountData.expiresAt || null,
|
||||
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return accounts
|
||||
|
||||
@@ -487,9 +487,12 @@ class ClaudeConsoleRelayService {
|
||||
|
||||
// 解析SSE数据寻找usage信息
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ') && line.length > 6) {
|
||||
if (line.startsWith('data:')) {
|
||||
const jsonStr = line.slice(5).trimStart()
|
||||
if (!jsonStr || jsonStr === '[DONE]') {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const jsonStr = line.slice(6)
|
||||
const data = JSON.parse(jsonStr)
|
||||
|
||||
// 收集usage数据
|
||||
|
||||
@@ -1487,9 +1487,12 @@ class ClaudeRelayService {
|
||||
|
||||
for (const line of lines) {
|
||||
// 解析SSE数据寻找usage信息
|
||||
if (line.startsWith('data: ') && line.length > 6) {
|
||||
if (line.startsWith('data:')) {
|
||||
const jsonStr = line.slice(5).trimStart()
|
||||
if (!jsonStr || jsonStr === '[DONE]') {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const jsonStr = line.slice(6)
|
||||
const data = JSON.parse(jsonStr)
|
||||
|
||||
// 收集来自不同事件的usage数据
|
||||
|
||||
@@ -504,9 +504,7 @@ async function updateAccount(accountId, updates) {
|
||||
updates.updatedAt = now
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(updates, 'subscriptionExpiresAt')) {
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(
|
||||
updates.subscriptionExpiresAt
|
||||
)
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.subscriptionExpiresAt)
|
||||
}
|
||||
|
||||
// 检查是否新增了 refresh token
|
||||
|
||||
@@ -173,9 +173,7 @@ class OpenAIResponsesAccountService {
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(updates, 'subscriptionExpiresAt')) {
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(
|
||||
updates.subscriptionExpiresAt
|
||||
)
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.subscriptionExpiresAt)
|
||||
} else if (Object.prototype.hasOwnProperty.call(updates, 'expiresAt')) {
|
||||
updates.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.expiresAt)
|
||||
delete updates.expiresAt
|
||||
|
||||
Reference in New Issue
Block a user