From 10630f3b8fea65915557fe595de9e406f8b94af5 Mon Sep 17 00:00:00 2001 From: qinglong Date: Sun, 14 Jun 2026 20:15:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=92=E4=BB=B6=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=97=B6=E4=BB=8E=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6fallback=E8=AF=BB=E5=8F=96=E9=9D=A2=E6=9D=BF=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E5=AF=BC=E8=87=B4=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/internet_service.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/services/internet_service.py b/services/internet_service.py index 91434bd..e251a64 100644 --- a/services/internet_service.py +++ b/services/internet_service.py @@ -193,7 +193,22 @@ class InternetService: logger.debug("默认路由设置完成 (已加认证)") - async def register_plugin_route(self, plugin_name: str, route_path: str, + def _read_panel_path(self) -> str: + """从 base_config.yaml 读取面板路径 (插件早于面板初始化时的 fallback)""" + try: + import yaml + from pathlib import Path + cfg_path = Path(__file__).resolve().parent.parent / "config" / "framework" / "base_config.yaml" + if cfg_path.exists(): + with open(cfg_path) as f: + cfg = yaml.safe_load(f) + p = cfg.get("panel", {}).get("entrance", {}).get("path", "/panel") + return f"/{p.strip('/')}" + except Exception: + pass + return "" + + async def register_plugin_route(self, plugin_name: str, route_path: str, handler: Callable, methods: List[str] = ["GET"], require_auth: bool = True): """为插件注册HTTP路由 - 修复冻结路由器问题""" @@ -202,7 +217,7 @@ class InternetService: if not route_path.startswith('/'): route_path = '/' + route_path - base = self.http_app.get('panel_base_path', '') or '' + base = self.http_app.get('panel_base_path', '') or self._read_panel_path() full_path = f"{base}/{plugin_name}{route_path}" # 创建包装器处理权限验证 @@ -268,7 +283,8 @@ class InternetService: if not ws_path.startswith('/'): ws_path = '/' + ws_path - full_path = f"/plugin/{plugin_name}/ws{ws_path}" + base = self.http_app.get('panel_base_path', '') or self._read_panel_path() + full_path = f"{base}/plugin/{plugin_name}/ws{ws_path}" async def websocket_handler(request): try: