feat: OAuth Token 自动刷新调度、OAuth 对话框优化及 OpenAI CLI normalizer 重构

- 系统设置新增 OAuth Token 自动刷新任务开关,支持动态调度
- OAuth 授权对话框简化步骤布局,移除编号圆圈样式
- 重构 OpenAI CLI normalizer:将 if-else 链替换为事件处理器映射表,
  将 stream_event_from_internal 拆分为独立方法
- 维护调度器在禁用刷新时移除已调度的 job
- .gitignore 新增 CLIProxyAPI/ 和 sub2api/ 排除项
- 补充 noop/unknown 事件处理器的测试覆盖
This commit is contained in:
fawney19
2026-02-05 01:07:47 +08:00
parent ba4d88e8ce
commit 9a8f25d1a9
7 changed files with 609 additions and 513 deletions

View File

@@ -634,6 +634,15 @@ class AdminSetSystemConfigAdapter(AdminApiAdapter):
except Exception as e:
logger.warning(f"更新用户配额重置任务时间失败: {e}")
# 如果更新的是 OAuth Token 自动刷新开关,触发调度器重新计算
if self.key == "enable_oauth_token_refresh":
try:
from src.services.system.maintenance_scheduler import get_maintenance_scheduler
get_maintenance_scheduler().trigger_oauth_refresh_check()
except Exception as e:
logger.warning("触发 OAuth Token 刷新调度失败: {}", e)
# 返回时不暴露加密后的值
display_value = "********" if self.key in self.ENCRYPTED_KEYS else config.value

File diff suppressed because it is too large Load Diff

View File

@@ -396,6 +396,11 @@ class MaintenanceScheduler:
# 检查配置开关
if not SystemConfigService.get_config(db, "enable_oauth_token_refresh", True):
logger.info("OAuth Token 自动刷新已禁用,不调度任务")
# 移除已调度的 job如果存在
try:
scheduler.remove_job(job_id)
except Exception:
pass
return
# 查找所有活跃的 OAuth 类型 Key
oauth_keys = (
@@ -966,9 +971,7 @@ class MaintenanceScheduler:
days_since_reset = (now_local.date() - last_local_date).days
if days_since_reset < 0:
logger.warning(
"user_quota_last_reset_at 在未来,跳过本次用户配额自动重置"
)
logger.warning("user_quota_last_reset_at 在未来,跳过本次用户配额自动重置")
should_run = False
elif days_since_reset < interval_days:
logger.info(
@@ -1006,7 +1009,9 @@ class MaintenanceScheduler:
"用户配额自动重置的上次执行时间UTC内部使用",
)
logger.info(f"用户配额自动重置完成: interval_days={interval_days}, 重置用户数={reset_count}")
logger.info(
f"用户配额自动重置完成: interval_days={interval_days}, 重置用户数={reset_count}"
)
except Exception as e:
logger.exception(f"用户配额自动重置任务执行失败: {e}")