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
|
||||||
|
|||||||
@@ -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