mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
refactor: 优化账户过期检查逻辑和代码一致性
## 主要改进 ### 1. 添加缺失的过期检查方法 - 在 `claudeConsoleAccountService` 中添加 `isSubscriptionExpired()` 方法 - 在 `ccrAccountService` 中添加 `isSubscriptionExpired()` 方法 - 与其他 7 个账户服务保持一致的实现方式 ### 2. 统一过期检查逻辑 - 重构 `unifiedClaudeScheduler` 中的 5 处手动日期检查代码 - 统一调用服务层的 `isSubscriptionExpired()` 方法 - 消除重复代码,提升可维护性 ### 3. 统一字段映射顺序 - 调整 Claude 账户更新端点的 `mapExpiryField()` 调用时机 - 与其他账户类型保持一致的处理顺序 - 提升代码可读性和一致性 ## 技术细节 **修改文件**: - `src/services/claudeConsoleAccountService.js`: 添加 `isSubscriptionExpired()` - `src/services/ccrAccountService.js`: 添加 `isSubscriptionExpired()` - `src/services/unifiedClaudeScheduler.js`: 5 处调用统一为服务方法 - `src/routes/admin.js`: 统一字段映射顺序 **改进效果**: - ✅ 代码一致性提升:所有账户服务统一实现 - ✅ 可维护性提升:过期逻辑集中管理 - ✅ 减少重复代码:消除 4 处重复实现 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -913,6 +913,19 @@ class CcrAccountService {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ⏰ 检查账户订阅是否过期
|
||||
* @param {Object} account - 账户对象
|
||||
* @returns {boolean} - true: 已过期, false: 未过期
|
||||
*/
|
||||
isSubscriptionExpired(account) {
|
||||
if (!account.subscriptionExpiresAt) {
|
||||
return false // 未设置视为永不过期
|
||||
}
|
||||
const expiryDate = new Date(account.subscriptionExpiresAt)
|
||||
return expiryDate <= new Date()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CcrAccountService()
|
||||
|
||||
Reference in New Issue
Block a user