存档
This commit is contained in:
@@ -109,6 +109,17 @@ app.include_router(plugin_router) # plugin路径
|
||||
app.include_router(task_router) # 短任务路径
|
||||
|
||||
|
||||
# 重型插件:纯文件扫描挂载各插件自带的 ``api.py`` router(不依赖 actor 启动顺序)
|
||||
try:
|
||||
from kilostar.plugin_runtime.loader import collect_plugin_routers
|
||||
from kilostar.utils.settings import get_plugin_dir as _get_plugin_dir
|
||||
|
||||
for _prefix, _plugin_router in collect_plugin_routers(_get_plugin_dir()):
|
||||
app.include_router(_plugin_router, prefix=_prefix)
|
||||
except Exception as _e:
|
||||
_api_logger.warning(f"failed to mount plugin routers: {_e}")
|
||||
|
||||
|
||||
@app.exception_handler(BusinessError)
|
||||
async def business_error_handler(request: Request, exc: BusinessError):
|
||||
"""业务可预期错误:按 ``http_status`` 返回 4xx,附 ``code`` + 异常消息。"""
|
||||
@@ -149,6 +160,30 @@ base_dir = os.path.dirname(
|
||||
)
|
||||
frontend_dir = os.path.join(base_dir, "frontend", "dist")
|
||||
|
||||
# 重型插件 UI:扫描 ``data/plugin/*/frontend/dist/``,按目录名挂成静态资源
|
||||
# (/plugin-ui/<name>/ → <plugin>/frontend/dist/)。html=True 让目录访问回退到 index.html
|
||||
# (单页应用风格),但实际我们靠 wc-manifest.json + import() 加载,不依赖该回退。
|
||||
try:
|
||||
from kilostar.utils.settings import get_plugin_dir as _get_plugin_dir_for_ui
|
||||
|
||||
_plugin_root_for_ui = _get_plugin_dir_for_ui()
|
||||
if _plugin_root_for_ui.exists():
|
||||
for _p in _plugin_root_for_ui.iterdir():
|
||||
if not _p.is_dir():
|
||||
continue
|
||||
_dist = _p / "frontend" / "dist"
|
||||
if not _dist.is_dir():
|
||||
continue
|
||||
app.mount(
|
||||
f"/plugin-ui/{_p.name}",
|
||||
StaticFiles(directory=str(_dist), html=True),
|
||||
name=f"plugin_ui_{_p.name}",
|
||||
)
|
||||
_api_logger.info(f"mounted plugin UI: /plugin-ui/{_p.name} → {_dist}")
|
||||
except Exception as _e:
|
||||
_api_logger.warning(f"failed to mount plugin UIs: {_e}")
|
||||
|
||||
|
||||
if os.path.exists(frontend_dir):
|
||||
app.mount(
|
||||
"/assets",
|
||||
|
||||
Reference in New Issue
Block a user