mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 21:17:30 +00:00
fix: 继续修复PR-541遗留的系列bug
This commit is contained in:
@@ -6,6 +6,19 @@ const config = require('../../config/config')
|
||||
const bedrockRelayService = require('./bedrockRelayService')
|
||||
const LRUCache = require('../utils/lruCache')
|
||||
|
||||
function normalizeSubscriptionExpiresAt(value) {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
|
||||
const date = value instanceof Date ? value : new Date(value)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return ''
|
||||
}
|
||||
|
||||
return date.toISOString()
|
||||
}
|
||||
|
||||
class BedrockAccountService {
|
||||
constructor() {
|
||||
// 加密相关常量
|
||||
@@ -40,7 +53,8 @@ class BedrockAccountService {
|
||||
accountType = 'shared', // 'dedicated' or 'shared'
|
||||
priority = 50, // 调度优先级 (1-100,数字越小优先级越高)
|
||||
schedulable = true, // 是否可被调度
|
||||
credentialType = 'default' // 'default', 'access_key', 'bearer_token'
|
||||
credentialType = 'default', // 'default', 'access_key', 'bearer_token'
|
||||
subscriptionExpiresAt = null
|
||||
} = options
|
||||
|
||||
const accountId = uuidv4()
|
||||
@@ -56,6 +70,7 @@ class BedrockAccountService {
|
||||
priority,
|
||||
schedulable,
|
||||
credentialType,
|
||||
subscriptionExpiresAt: normalizeSubscriptionExpiresAt(subscriptionExpiresAt),
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
type: 'bedrock' // 标识这是Bedrock账户
|
||||
@@ -84,6 +99,7 @@ class BedrockAccountService {
|
||||
priority,
|
||||
schedulable,
|
||||
credentialType,
|
||||
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null,
|
||||
createdAt: accountData.createdAt,
|
||||
type: 'bedrock'
|
||||
}
|
||||
@@ -106,6 +122,11 @@ class BedrockAccountService {
|
||||
account.awsCredentials = this._decryptAwsCredentials(account.awsCredentials)
|
||||
}
|
||||
|
||||
account.subscriptionExpiresAt =
|
||||
account.subscriptionExpiresAt && account.subscriptionExpiresAt !== ''
|
||||
? account.subscriptionExpiresAt
|
||||
: null
|
||||
|
||||
logger.debug(`🔍 获取Bedrock账户 - ID: ${accountId}, 名称: ${account.name}`)
|
||||
|
||||
return {
|
||||
@@ -141,13 +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
|
||||
})
|
||||
}
|
||||
credentialType: account.credentialType,
|
||||
createdAt: account.createdAt,
|
||||
updatedAt: account.updatedAt,
|
||||
type: 'bedrock',
|
||||
hasCredentials: !!account.awsCredentials,
|
||||
expiresAt: account.expiresAt || null,
|
||||
subscriptionExpiresAt: account.subscriptionExpiresAt || null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 按优先级和名称排序
|
||||
@@ -211,6 +234,14 @@ class BedrockAccountService {
|
||||
account.credentialType = updates.credentialType
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(updates, 'subscriptionExpiresAt')) {
|
||||
account.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(
|
||||
updates.subscriptionExpiresAt
|
||||
)
|
||||
} else if (Object.prototype.hasOwnProperty.call(updates, 'expiresAt')) {
|
||||
account.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.expiresAt)
|
||||
}
|
||||
|
||||
// 更新AWS凭证
|
||||
if (updates.awsCredentials !== undefined) {
|
||||
if (updates.awsCredentials) {
|
||||
@@ -245,7 +276,9 @@ class BedrockAccountService {
|
||||
schedulable: account.schedulable,
|
||||
credentialType: account.credentialType,
|
||||
updatedAt: account.updatedAt,
|
||||
type: 'bedrock'
|
||||
type: 'bedrock',
|
||||
expiresAt: account.expiresAt || null,
|
||||
subscriptionExpiresAt: account.subscriptionExpiresAt || null
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user