结构调整
视频解析多图/多媒体结构 消息体适配
This commit is contained in:
@@ -31,8 +31,8 @@ nonebot_plugin_template/
|
||||
|
||||
## Web 子应用
|
||||
- `web/admin.py::build_admin_app()` 返回一个 FastAPI 实例,经 `register_web_plugin` 由 hub 挂载到 `/api/template`。
|
||||
- 鉴权统一 `hexi.web_auth.require_admin`;示例端点:`GET /ping`、`GET /config`(读插件配置)。
|
||||
- 想要更丰富的管理页:前端放 `web/dist/`,在 admin.py 里挂 `StaticFiles` + SPA 兜底即可(参考 `nonebot_plugin_web_hub`)。
|
||||
- 鉴权统一 `hexi.web_hub.web_auth.require_admin`;示例端点:`GET /ping`、`GET /config`(读插件配置)。
|
||||
- 想要更丰富的管理页:前端放 `web/dist/`,在 admin.py 里挂 `StaticFiles` + SPA 兜底即可(参考 `hexi/web_hub`)。
|
||||
|
||||
## 约定
|
||||
- `plugin_id` = 模块名(自动取 `__package__`;web 子应用用 `__package__.rsplit(".", 1)[0]`)。
|
||||
|
||||
@@ -24,7 +24,7 @@ from . import config as _config # noqa: E402,F401
|
||||
from . import handlers as _handlers # noqa: E402,F401
|
||||
from . import web as _web # noqa: E402,F401
|
||||
|
||||
from hexi.web_plugin_registry import register_web_plugin # noqa: E402
|
||||
from hexi.web_hub.web_plugin_registry import register_web_plugin # noqa: E402
|
||||
|
||||
_config.register_config()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from __future__ import annotations
|
||||
from nonebot import get_plugin_config
|
||||
from pydantic import BaseModel
|
||||
|
||||
from hexi.config_standard import register_config_items, register_model_config, register_object_set
|
||||
from hexi.web_hub.config_standard import register_config_items, register_model_config, register_object_set
|
||||
|
||||
# plugin_id = NoneBot 插件模块名
|
||||
_PLUGIN_ID = __package__
|
||||
|
||||
@@ -8,7 +8,7 @@ from nonebot.rule import to_me
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from hexi.web_config import get_effective_value
|
||||
from hexi.web_hub.web_config import get_effective_value
|
||||
|
||||
from ..services.main import do_something
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from hexi.web_config import get_effective_value
|
||||
from hexi.web_hub.web_config import get_effective_value
|
||||
|
||||
from ..repository import get_record, save_record
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
- 由 `__init__.py` 里 `register_web_plugin("template", ..., module_name=__name__)` 注册,
|
||||
hub 启动时自动挂载到 `/api/template`。
|
||||
- 鉴权统一走 `hexi.web_auth.require_admin`(OAuth2 + SQLite);注意它本身是 FastAPI 的
|
||||
- 鉴权统一走 `hexi.web_hub.web_auth.require_admin`(OAuth2 + SQLite);注意它本身是 FastAPI 的
|
||||
`Depends` 实例,直接用 `_: dict = API` 注入,不要再包一层 `Depends(...)`。
|
||||
- 可直接读写 `hexi.web_config` 的插件配置。
|
||||
- 可直接读写 `hexi.web_hub.web_config` 的插件配置。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -13,7 +13,7 @@ from fastapi import FastAPI
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
||||
from hexi import web_config
|
||||
from hexi.web_auth import require_admin as API
|
||||
from hexi.web_hub.web_auth import require_admin as API
|
||||
|
||||
# 插件模块名(去掉 .web):= NoneBot 模块名 = plugin_id
|
||||
_PLUGIN_ID = __package__.rsplit(".", 1)[0]
|
||||
|
||||
Reference in New Issue
Block a user