mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
refactor: 统一账户过期时间字段映射和检查逻辑
主要改进: 1. 创建 mapExpiryField() 工具函数统一处理前后端字段映射(expiresAt -> subscriptionExpiresAt) 2. 统一 subscriptionExpiresAt 初始值为 null(替代空字符串) 3. 规范过期检查方法名为 isSubscriptionExpired(),返回 true 表示已过期 4. 优化过期检查条件判断,只检查 null 而非空字符串 5. 补充 OpenAI-Responses 和调度器中缺失的过期检查逻辑 6. 添加代码评审文档记录未修复问题 影响范围: - 所有 9 种账户服务的过期字段处理 - admin.js 中所有账户更新路由 - 统一调度器的过期账户过滤逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -787,13 +787,13 @@ class ClaudeAccountService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查账户是否未过期
|
||||
* 检查账户订阅是否过期
|
||||
* @param {Object} account - 账户对象
|
||||
* @returns {boolean} - 如果未设置过期时间或未过期返回 true
|
||||
* @returns {boolean} - true: 已过期, false: 未过期
|
||||
*/
|
||||
isAccountNotExpired(account) {
|
||||
isSubscriptionExpired(account) {
|
||||
if (!account.subscriptionExpiresAt) {
|
||||
return true // 未设置过期时间,视为永不过期
|
||||
return false // 未设置过期时间,视为永不过期
|
||||
}
|
||||
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
@@ -803,10 +803,10 @@ class ClaudeAccountService {
|
||||
logger.debug(
|
||||
`⏰ Account ${account.name} (${account.id}) expired at ${account.subscriptionExpiresAt}`
|
||||
)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
// 🎯 智能选择可用账户(支持sticky会话和模型过滤)
|
||||
@@ -819,7 +819,7 @@ class ClaudeAccountService {
|
||||
account.isActive === 'true' &&
|
||||
account.status !== 'error' &&
|
||||
account.schedulable !== 'false' &&
|
||||
this.isAccountNotExpired(account)
|
||||
!this.isSubscriptionExpired(account)
|
||||
)
|
||||
|
||||
// 如果请求的是 Opus 模型,过滤掉 Pro 和 Free 账号
|
||||
@@ -915,7 +915,7 @@ class ClaudeAccountService {
|
||||
boundAccount.isActive === 'true' &&
|
||||
boundAccount.status !== 'error' &&
|
||||
boundAccount.schedulable !== 'false' &&
|
||||
this.isAccountNotExpired(boundAccount)
|
||||
!this.isSubscriptionExpired(boundAccount)
|
||||
) {
|
||||
logger.info(
|
||||
`🎯 Using bound dedicated account: ${boundAccount.name} (${apiKeyData.claudeAccountId}) for API key ${apiKeyData.name}`
|
||||
@@ -937,7 +937,7 @@ class ClaudeAccountService {
|
||||
account.status !== 'error' &&
|
||||
account.schedulable !== 'false' &&
|
||||
(account.accountType === 'shared' || !account.accountType) && // 兼容旧数据
|
||||
this.isAccountNotExpired(account)
|
||||
!this.isSubscriptionExpired(account)
|
||||
)
|
||||
|
||||
// 如果请求的是 Opus 模型,过滤掉 Pro 和 Free 账号
|
||||
|
||||
Reference in New Issue
Block a user