将配置重置为 .env.example 并热重载。
()
| 485 | |
| 486 | @router.post("/config/reset", dependencies=[Depends(require_auth)]) |
| 487 | async def reset_config(): |
| 488 | """将配置重置为 .env.example 并热重载。""" |
| 489 | try: |
| 490 | await reset_env_to_example(reload_callback=reload_settings) |
| 491 | logger.info("✅ 配置已重置为 .env.example 默认值") |
| 492 | return _with_hx_trigger( |
| 493 | _build_alert( |
| 494 | "配置已恢复为 .env.example 默认值,页面即将刷新。", |
| 495 | title="已重置!", |
| 496 | level="success", |
| 497 | ), |
| 498 | "admin-config-refresh", |
| 499 | ) |
| 500 | except FileNotFoundError: |
| 501 | logger.error("❌ 未找到 .env.example,无法重置配置") |
| 502 | return _build_alert( |
| 503 | "未找到 .env.example,无法重置配置。", |
| 504 | title="错误!", |
| 505 | level="error", |
| 506 | status_code=404, |
| 507 | ) |
| 508 | except Exception as exc: |
| 509 | logger.error(f"❌ 配置重置失败: {exc}") |
| 510 | return _build_alert( |
| 511 | f"重置失败: {exc}", |
| 512 | title="错误!", |
| 513 | level="error", |
| 514 | status_code=500, |
| 515 | ) |
| 516 | |
| 517 | |
| 518 | @router.get("/env-preview", dependencies=[Depends(require_auth)]) |
nothing calls this directly
no test coverage detected