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