fix: 插件路由注册时从配置文件fallback读取面板路径,解决初始化顺序导致的路径缺失
This commit is contained in:
@@ -193,6 +193,21 @@ class InternetService:
|
|||||||
|
|
||||||
logger.debug("默认路由设置完成 (已加认证)")
|
logger.debug("默认路由设置完成 (已加认证)")
|
||||||
|
|
||||||
|
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,
|
async def register_plugin_route(self, plugin_name: str, route_path: str,
|
||||||
handler: Callable, methods: List[str] = ["GET"],
|
handler: Callable, methods: List[str] = ["GET"],
|
||||||
require_auth: bool = True):
|
require_auth: bool = True):
|
||||||
@@ -202,7 +217,7 @@ class InternetService:
|
|||||||
if not route_path.startswith('/'):
|
if not route_path.startswith('/'):
|
||||||
route_path = '/' + route_path
|
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}"
|
full_path = f"{base}/{plugin_name}{route_path}"
|
||||||
|
|
||||||
# 创建包装器处理权限验证
|
# 创建包装器处理权限验证
|
||||||
@@ -268,7 +283,8 @@ class InternetService:
|
|||||||
if not ws_path.startswith('/'):
|
if not ws_path.startswith('/'):
|
||||||
ws_path = '/' + ws_path
|
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):
|
async def websocket_handler(request):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user