From 01e6c63bc8830235643ffa86c7f235f7e0009111 Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 29 Oct 2025 16:47:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=9C=BA=E5=88=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?app=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jingrow/jingrow/services/whitelist.py | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/jingrow/jingrow/services/whitelist.py b/apps/jingrow/jingrow/services/whitelist.py index 8479b43..df3c644 100644 --- a/apps/jingrow/jingrow/services/whitelist.py +++ b/apps/jingrow/jingrow/services/whitelist.py @@ -57,19 +57,16 @@ async def authenticate_request(request: Request, allow_guest: bool) -> bool: logger.warning("认证失败: 未提供有效的认证信息") return False -@router.post("/{module_path:path}") -async def handle_request(request: Request, module_path: str): - """ - 处理白名单路由请求 - """ +async def _process_whitelist_call(request: Request, full_module_path: str): + """通用处理:接收完整点分路径 '' 并执行调用""" try: # 解析模块路径并先导入模块,确保装饰器执行 - module_info = parse_module_path(module_path) + module_info = parse_module_path(full_module_path) module = import_module(module_info['module_path']) # 模块导入后再检查是否是白名单函数 - if is_whitelisted(module_path): - whitelist_info = get_whitelisted_function(module_path) + if is_whitelisted(full_module_path): + whitelist_info = get_whitelisted_function(full_module_path) func = whitelist_info['function'] # 检查HTTP方法 @@ -109,11 +106,28 @@ async def handle_request(request: Request, module_path: str): "success": True, "data": result }) - + except Exception as e: logger.error(f"Request handler error: {e}") raise HTTPException(status_code=500, detail=str(e)) + +@router.post("/{module_path:path}") +async def handle_request(request: Request, module_path: str): + """ + 兼容旧路径:直接传入完整点分路径 '' + """ + return await _process_whitelist_call(request, module_path) + + +@router.post("/{app}/{module_path:path}") +async def handle_request_with_app_prefix(request: Request, app: str, module_path: str): + """ + 新路径:支持以 app 作为前缀,例如 app.module.function + """ + full_module_path = f"{app}.{module_path}" + return await _process_whitelist_call(request, full_module_path) + def parse_module_path(module_path: str) -> Dict[str, str]: """解析模块路径""" parts = module_path.split('.')