from fastapi import APIRouter import importlib from shared.config.settings import settings from shared.utils.logger import get_logger logger = get_logger(__name__) router = APIRouter() def _safe_include(module_path: str, label: str): try: module = importlib.import_module(module_path) router_obj = getattr(module, "router", None) if router_obj is None: raise ValueError("未找到 router 对象") router.include_router(router_obj) logger.info(f"{label} 路由加载成功") except Exception as exc: logger.warning(f"{label} 路由加载失败,已跳过: {exc}") _safe_include("moldinsight.api.health_router", "健康检查") _safe_include("moldinsight.api.upload_router", "上传") _safe_include("moldinsight.api.batch_router", "批量") _safe_include("moldinsight.api.task_router", "任务") _safe_include("moldinsight.api.history_router", "历史") _safe_include("moldinsight.api.cam_router", "CAM") _safe_include("moldinsight.api.advanced_router", "高级") _safe_include("moldinsight.api.aluminum_price_routes", "铝价") # 调试端点会 dump 全量任务数据,仅 DEBUG 模式注册(双重防线:还需登录) if settings.DEBUG: _safe_include("moldinsight.api.debug_router", "调试")