结构调整
视频解析多图/多媒体结构 消息体适配
This commit is contained in:
@@ -20,8 +20,12 @@
|
||||
|
||||
```text
|
||||
hexi/
|
||||
├── web_config.py # 配置标准核心:schema 注册 / 值库 / 保存热刷新
|
||||
├── config_standard.py # pydantic Config 一键接入的辅助封装
|
||||
├── web_hub/ # 统一 Web 管理台 / 鉴权 / 配置标准
|
||||
│ ├── web_config.py # 配置标准核心:schema 注册 / 值库 / 保存热刷新
|
||||
│ ├── config_standard.py # pydantic Config 一键接入的辅助封装
|
||||
│ ├── web_auth.py # 统一 Web 鉴权(OAuth2 + SQLite)
|
||||
│ ├── web_plugin_registry.py # 统一 Web 插件注册中心
|
||||
│ └── web_hub_auth.py # 兼容 shim
|
||||
├── config/
|
||||
│ └── plugin_config.json # 统一值库:{ "<plugin_id>": { key: value, ... } }
|
||||
└── web/ # /hub 前端(通用 schema 表单渲染器)
|
||||
@@ -143,7 +147,7 @@ hexi/
|
||||
|
||||
```python
|
||||
# 在插件 __init__.py 里
|
||||
from hexi.config_standard import register_model_config
|
||||
from hexi.web_hub.config_standard import register_model_config
|
||||
from .config import config
|
||||
|
||||
register_model_config(
|
||||
@@ -168,7 +172,7 @@ register_model_config(
|
||||
### 方式 B:非 pydantic 插件手动注册
|
||||
|
||||
```python
|
||||
from hexi.web_config import register_plugin_config
|
||||
from hexi.web_hub.web_config import register_plugin_config
|
||||
|
||||
def _get(): # 返回当前生效值 dict
|
||||
return {"field": get_my_cur_value("field")}
|
||||
@@ -209,7 +213,7 @@ register_plugin_config(
|
||||
2. **写值库** `plugin_config.json`(原子写)。
|
||||
3. **写 .env**:非 list 字段写入 `os.environ` + `../../.env`(保证重启仍生效);list/path/object 跳过,避免 `str(list)` 破坏重启解析。
|
||||
4. **调 `apply(values)`**:把值热应用到插件运行态对象(list/path/object 也在此生效)。
|
||||
5. 若插件未提供 apply,则 `hot_reload(plugin_id)` 让插件重载。
|
||||
5. 若插件未提供 apply,则 `hot_reload(plugin_id)` 让插件重载;**library/非 application 插件不受热重载**(见《插件类型分类》,热拔插会破坏依赖它的插件)。
|
||||
|
||||
**为什么 apply 与 env 都做**:NoneBot 的 `get_driver().config` 在启动时即固定,重载插件也读不到新 env;所以运行期必须 apply,重启靠 env。
|
||||
|
||||
@@ -220,7 +224,7 @@ register_plugin_config(
|
||||
| 方法 | 路径 | 说明 |
|
||||
|---|---|---|
|
||||
| GET | `/api/plugins` | 所有已注册 Web 插件 |
|
||||
| GET | `/api/plugins/catalog` | 所有应用插件 + `has_config/has_web/web_path` |
|
||||
| GET | `/api/plugins/catalog` | 所有 application/library 插件(含带配置项的 library)+ `type/has_config/has_web/web_path` |
|
||||
| GET | `/api/plugins/{id}/config` | 读 `{schema, values, revision}`(登录);secret 值只返回 `****` |
|
||||
| POST | `/api/plugins/{id}/config` | 保存 `{ "revision": n, "values": { key: value } }`;冲突 409,校验失败 422 |
|
||||
| DELETE | `/api/plugins/{id}/config` | 清空该插件覆盖,恢复默认(可选) |
|
||||
@@ -242,7 +246,7 @@ register_plugin_config(
|
||||
|
||||
## 9. 权限与安全
|
||||
|
||||
- 全部配置接口走 `hexi.web_auth.require_admin`(OAuth2 + SQLite)。
|
||||
- 全部配置接口走 `hexi.web_hub.web_auth.require_admin`(OAuth2 + SQLite)。
|
||||
- 配置 POST 必须携带 GET 返回的 `revision`;缺失返回 428,冲突返回 409。
|
||||
- 只允许 `plugin_id` 存在于注册表,未注册返回 `ok:false`(防任意写入)。
|
||||
- 部署时必须显式设置 Web 管理员凭据;禁止生产环境使用默认的 `admin/admin`。
|
||||
@@ -277,7 +281,7 @@ register_plugin_config(
|
||||
|
||||
```python
|
||||
# hexi/plugins/nonebot_plugin_helldivers_tools/__init__.py
|
||||
from hexi.config_standard import register_model_config
|
||||
from hexi.web_hub.config_standard import register_model_config
|
||||
from .config import config as _hd2_config
|
||||
|
||||
register_model_config(
|
||||
@@ -295,7 +299,7 @@ register_model_config(
|
||||
## 12. 已接入与待接入
|
||||
|
||||
- **已接入**:`helldivers_tools`、`mc_server_status`、`video_analysis`、`steam_info`、`picstatus`、`galgame_card`。
|
||||
- **未接入(建议后续)**:`learning_chat`、`group_daily_analysis`(已有独自 Web 配置,避免冲突)、`picfinder_take`、`bf_bot`、`group_tools`、`hexi_core`(模块级常量/SUPERUSERS,运行期热更复杂)。
|
||||
- **未接入(建议后续)**:`learning_chat`、`group_daily_analysis`(已有独自 Web 配置,避免冲突)、`picfinder_take`、`bf_bot`、`group_tools`、`hexi/core`(模块级常量/SUPERUSERS,运行期热更复杂)。
|
||||
|
||||
|
||||
---
|
||||
@@ -316,7 +320,7 @@ register_model_config(
|
||||
### 13.2 通用注册 API(任意来源)
|
||||
|
||||
```python
|
||||
from hexi.config_standard import register_config_items
|
||||
from hexi.web_hub.config_standard import register_config_items
|
||||
|
||||
register_config_items(
|
||||
__name__, # = NoneBot 插件模块名
|
||||
@@ -339,7 +343,7 @@ register_config_items(
|
||||
Web 保存后 apply 会把新值写回来源(模块属性/dict/自定义),但若插件在别处是用 `from .config import X` **值拷贝**进来的量,不受影响。要真正运行期生效,插件在读配置处改用统一 API:
|
||||
|
||||
```python
|
||||
from hexi.web_config import get_effective_value
|
||||
from hexi.web_hub.web_config import get_effective_value
|
||||
|
||||
limit = get_effective_value("hexi.plugins.nonebot_plugin_picfinder_take", "DAILY_LIMIT", 50)
|
||||
if not check_quota(limit): ...
|
||||
@@ -395,7 +399,7 @@ if not check_quota(limit): ...
|
||||
### 14.3 一键注册 API
|
||||
|
||||
```python
|
||||
from hexi.config_standard import register_object_set
|
||||
from hexi.web_hub.config_standard import register_object_set
|
||||
|
||||
register_object_set(
|
||||
__name__, # NoneBot 插件模块名
|
||||
|
||||
Reference in New Issue
Block a user