mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 08:55:23 +00:00
feat: Codex账号管理优化与API Key激活机制
✨ 新功能 - 支持通过refreshToken新增Codex账号,创建时立即验证token有效性 - API Key新增首次使用自动激活机制,支持activation模式设置有效期 - 前端账号表单增加token验证功能,确保账号创建成功 🐛 修复 - 修复Codex token刷新失败问题,增加分布式锁防止并发刷新 - 优化token刷新错误处理,提供更详细的错误信息和建议 - 修复OpenAI账号token过期检测和自动刷新逻辑 📝 文档更新 - 更新README中Codex使用说明,改为config.toml配置方式 - 优化Cherry Studio等第三方工具接入文档 - 添加详细的配置示例和账号类型说明 🎨 界面优化 - 改进账号创建表单UI,支持手动和OAuth两种模式 - 优化API Key过期时间编辑弹窗,支持激活操作 - 调整教程页面布局,提升移动端响应式体验 💡 代码改进 - 重构token刷新服务,增强错误处理和重试机制 - 优化代理配置处理,确保OAuth请求正确使用代理 - 改进webhook通知,增加token刷新失败告警
This commit is contained in:
@@ -167,7 +167,7 @@ class UnifiedOpenAIScheduler {
|
||||
|
||||
// 获取所有OpenAI账户(共享池)
|
||||
const openaiAccounts = await openaiAccountService.getAllAccounts()
|
||||
for (const account of openaiAccounts) {
|
||||
for (let account of openaiAccounts) {
|
||||
if (
|
||||
account.isActive &&
|
||||
account.status !== 'error' &&
|
||||
@@ -176,13 +176,27 @@ class UnifiedOpenAIScheduler {
|
||||
) {
|
||||
// 检查是否可调度
|
||||
|
||||
// 检查token是否过期
|
||||
// 检查token是否过期并自动刷新
|
||||
const isExpired = openaiAccountService.isTokenExpired(account)
|
||||
if (isExpired && !account.refreshToken) {
|
||||
logger.warn(
|
||||
`⚠️ OpenAI account ${account.name} token expired and no refresh token available`
|
||||
)
|
||||
continue
|
||||
if (isExpired) {
|
||||
if (!account.refreshToken) {
|
||||
logger.warn(
|
||||
`⚠️ OpenAI account ${account.name} token expired and no refresh token available`
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
// 自动刷新过期的 token
|
||||
try {
|
||||
logger.info(`🔄 Auto-refreshing expired token for OpenAI account ${account.name}`)
|
||||
await openaiAccountService.refreshAccountToken(account.id)
|
||||
// 重新获取更新后的账户信息
|
||||
account = await openaiAccountService.getAccount(account.id)
|
||||
logger.info(`✅ Token refreshed successfully for ${account.name}`)
|
||||
} catch (refreshError) {
|
||||
logger.error(`❌ Failed to refresh token for ${account.name}:`, refreshError.message)
|
||||
continue // 刷新失败,跳过此账户
|
||||
}
|
||||
}
|
||||
|
||||
// 检查模型支持(仅在明确设置了supportedModels且不为空时才检查)
|
||||
|
||||
Reference in New Issue
Block a user