fix: 继续修复PR-541遗留的系列bug

This commit is contained in:
shaw
2025-10-12 22:13:38 +08:00
parent 7d4bf9f94f
commit 6f6c274877
9 changed files with 368 additions and 61 deletions

View File

@@ -6,6 +6,19 @@ const logger = require('../utils/logger')
const config = require('../../config/config')
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 ClaudeConsoleAccountService {
constructor() {
// 加密相关常量
@@ -52,7 +65,8 @@ class ClaudeConsoleAccountService {
accountType = 'shared', // 'dedicated' or 'shared'
schedulable = true, // 是否可被调度
dailyQuota = 0, // 每日额度限制美元0表示不限制
quotaResetTime = '00:00' // 额度重置时间HH:mm格式
quotaResetTime = '00:00', // 额度重置时间HH:mm格式
subscriptionExpiresAt = null
} = options
// 验证必填字段
@@ -94,7 +108,8 @@ class ClaudeConsoleAccountService {
// 使用与统计一致的时区日期,避免边界问题
lastResetDate: redis.getDateStringInTimezone(), // 最后重置日期(按配置时区)
quotaResetTime, // 额度重置时间
quotaStoppedAt: '' // 因额度停用的时间
quotaStoppedAt: '', // 因额度停用的时间
subscriptionExpiresAt: normalizeSubscriptionExpiresAt(subscriptionExpiresAt)
}
const client = redis.getClientSafe()
@@ -130,7 +145,8 @@ class ClaudeConsoleAccountService {
dailyUsage: 0,
lastResetDate: accountData.lastResetDate,
quotaResetTime,
quotaStoppedAt: null
quotaStoppedAt: null,
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
}
}
@@ -170,12 +186,14 @@ class ClaudeConsoleAccountService {
schedulable: accountData.schedulable !== 'false', // 默认为true只有明确设置为false才不可调度
// 额度管理相关
dailyQuota: parseFloat(accountData.dailyQuota || '0'),
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
lastResetDate: accountData.lastResetDate || '',
quotaResetTime: accountData.quotaResetTime || '00:00',
quotaStoppedAt: accountData.quotaStoppedAt || null
})
}
dailyUsage: parseFloat(accountData.dailyUsage || '0'),
lastResetDate: accountData.lastResetDate || '',
quotaResetTime: accountData.quotaResetTime || '00:00',
quotaStoppedAt: accountData.quotaStoppedAt || null,
expiresAt: accountData.expiresAt || null,
subscriptionExpiresAt: accountData.subscriptionExpiresAt || null
})
}
}
return accounts
@@ -224,6 +242,11 @@ class ClaudeConsoleAccountService {
accountData.proxy = JSON.parse(accountData.proxy)
}
accountData.subscriptionExpiresAt =
accountData.subscriptionExpiresAt && accountData.subscriptionExpiresAt !== ''
? accountData.subscriptionExpiresAt
: null
logger.debug(
`[DEBUG] Final account data - name: ${accountData.name}, hasApiUrl: ${!!accountData.apiUrl}, hasApiKey: ${!!accountData.apiKey}, supportedModels: ${JSON.stringify(accountData.supportedModels)}`
)
@@ -318,6 +341,14 @@ class ClaudeConsoleAccountService {
updatedData.quotaStoppedAt = updates.quotaStoppedAt
}
if (Object.prototype.hasOwnProperty.call(updates, 'subscriptionExpiresAt')) {
updatedData.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(
updates.subscriptionExpiresAt
)
} else if (Object.prototype.hasOwnProperty.call(updates, 'expiresAt')) {
updatedData.subscriptionExpiresAt = normalizeSubscriptionExpiresAt(updates.expiresAt)
}
// 处理账户类型变更
if (updates.accountType && updates.accountType !== existingAccount.accountType) {
updatedData.accountType = updates.accountType