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:
@@ -545,6 +545,18 @@ class UnifiedClaudeScheduler {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订阅是否过期
|
||||
if (account.subscriptionExpiresAt) {
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
const now = new Date()
|
||||
if (expiryDate <= now) {
|
||||
logger.debug(
|
||||
`⏰ Claude Console account ${account.name} (${account.id}) expired at ${account.subscriptionExpiresAt}`
|
||||
)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 主动触发一次额度检查,确保状态即时生效
|
||||
try {
|
||||
await claudeConsoleAccountService.checkQuotaUsage(account.id)
|
||||
@@ -642,6 +654,18 @@ class UnifiedClaudeScheduler {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订阅是否过期
|
||||
if (account.subscriptionExpiresAt) {
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
const now = new Date()
|
||||
if (expiryDate <= now) {
|
||||
logger.debug(
|
||||
`⏰ CCR account ${account.name} (${account.id}) expired at ${account.subscriptionExpiresAt}`
|
||||
)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否被限流
|
||||
const isRateLimited = await ccrAccountService.isAccountRateLimited(account.id)
|
||||
const isQuotaExceeded = await ccrAccountService.isAccountQuotaExceeded(account.id)
|
||||
@@ -774,6 +798,17 @@ class UnifiedClaudeScheduler {
|
||||
) {
|
||||
return false
|
||||
}
|
||||
// 检查订阅是否过期
|
||||
if (account.subscriptionExpiresAt) {
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
const now = new Date()
|
||||
if (expiryDate <= now) {
|
||||
logger.debug(
|
||||
`⏰ Claude Console account ${account.name} (${accountId}) expired at ${account.subscriptionExpiresAt} (session check)`
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
// 检查是否超额
|
||||
try {
|
||||
await claudeConsoleAccountService.checkQuotaUsage(accountId)
|
||||
@@ -832,6 +867,17 @@ class UnifiedClaudeScheduler {
|
||||
if (!this._isModelSupportedByAccount(account, 'ccr', requestedModel, 'in session check')) {
|
||||
return false
|
||||
}
|
||||
// 检查订阅是否过期
|
||||
if (account.subscriptionExpiresAt) {
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
const now = new Date()
|
||||
if (expiryDate <= now) {
|
||||
logger.debug(
|
||||
`⏰ CCR account ${account.name} (${accountId}) expired at ${account.subscriptionExpiresAt} (session check)`
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
// 检查是否超额
|
||||
try {
|
||||
await ccrAccountService.checkQuotaUsage(accountId)
|
||||
@@ -1353,6 +1399,18 @@ class UnifiedClaudeScheduler {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订阅是否过期
|
||||
if (account.subscriptionExpiresAt) {
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
const now = new Date()
|
||||
if (expiryDate <= now) {
|
||||
logger.debug(
|
||||
`⏰ CCR account ${account.name} (${account.id}) expired at ${account.subscriptionExpiresAt}`
|
||||
)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否被限流或超额
|
||||
const isRateLimited = await ccrAccountService.isAccountRateLimited(account.id)
|
||||
const isQuotaExceeded = await ccrAccountService.isAccountQuotaExceeded(account.id)
|
||||
|
||||
Reference in New Issue
Block a user