105 lines
5.0 KiB
Python
105 lines
5.0 KiB
Python
"""统一配置注册:把插件配置按文档标准接入 hexi.web_hub.web_config(Web 可读可改)。
|
||
|
||
- temp 清理配置(env pydantic) → register_model_config
|
||
- S3 存储配置(原硬编码在 services/storage/s3.py) → register_config_items(store=s3 模块)
|
||
- 群分组配置(data/list.json) → register_config_items(type=json, nosave)
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from hexi.web_hub.config_standard import register_config_items, register_model_config
|
||
|
||
from . import cleanup, list_proc # noqa: F401
|
||
from .services.storage import s3 as _s3mod
|
||
|
||
# 插件模块名 = plugin_id(与 NoneBot 模块名一致)
|
||
_PLUGIN_ID = __package__
|
||
|
||
|
||
def _reset_s3_caches(_values=None, store=None):
|
||
"""保存 S3 配置后清空懒加载客户端缓存,让下次上传用新配置重建。"""
|
||
if store is None:
|
||
return
|
||
for name in ("_local_s3_plana", "_local_s3_planb", "_local_s3_planc", "_public_s3"):
|
||
try:
|
||
setattr(store, name, None)
|
||
except Exception: # noqa: BLE001
|
||
pass
|
||
|
||
|
||
def register_config() -> None:
|
||
"""注册本插件全部配置(供 __init__.py 在导入期调用)。"""
|
||
# 1) temp 清理配置
|
||
register_model_config(
|
||
_PLUGIN_ID,
|
||
cleanup.cleanup_config,
|
||
fields=[
|
||
"video_analysis_temp_cleanup_mode",
|
||
"video_analysis_temp_max_age_days",
|
||
"video_analysis_temp_cleanup_hour",
|
||
],
|
||
labels={
|
||
"video_analysis_temp_cleanup_mode": "temp 清理模式",
|
||
"video_analysis_temp_max_age_days": "清理过期天数",
|
||
"video_analysis_temp_cleanup_hour": "每日清理时间(时)",
|
||
},
|
||
descriptions={
|
||
"video_analysis_temp_cleanup_mode": "auto=每日定时自动清理; manual=仅命令手动清理",
|
||
"video_analysis_temp_max_age_days": "超过该天数未修改的文件会被清理",
|
||
"video_analysis_temp_cleanup_hour": "自动模式下的每日清理小时(0-23)",
|
||
},
|
||
options={
|
||
"video_analysis_temp_cleanup_mode": [
|
||
{"value": "auto", "label": "自动(auto)"},
|
||
{"value": "manual", "label": "手动(manual)"},
|
||
]
|
||
},
|
||
types={"video_analysis_temp_cleanup_mode": "enum"},
|
||
# 保存后按新配置重设自动定时任务
|
||
apply_extra=lambda _values, _conf: cleanup.reload_cleanup_config(),
|
||
)
|
||
|
||
# 2) S3 存储配置(来源无关)
|
||
register_config_items(
|
||
_PLUGIN_ID,
|
||
[
|
||
{"key": "LOCAL_S3_PLANA_ENDPOINT", "label": "PLANA 端点", "type": "string", "secret": True},
|
||
{"key": "LOCAL_S3_PLANA_ACCESS_KEY", "label": "PLANA AccessKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANA_SECRET_KEY", "label": "PLANA SecretKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANA_BUCKET", "label": "PLANA 桶", "type": "string"},
|
||
{"key": "LOCAL_S3_PLANB_ENDPOINT", "label": "PLANB 端点", "type": "string", "secret": True},
|
||
{"key": "LOCAL_S3_PLANB_ACCESS_KEY", "label": "PLANB AccessKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANB_SECRET_KEY", "label": "PLANB SecretKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANB_BUCKET", "label": "PLANB 桶", "type": "string"},
|
||
{"key": "LOCAL_S3_PLANC_ENDPOINT", "label": "PLANC 端点", "type": "string", "secret": True},
|
||
{"key": "LOCAL_S3_PLANC_ACCESS_KEY", "label": "PLANC AccessKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANC_SECRET_KEY", "label": "PLANC SecretKey", "type": "password", "secret": True},
|
||
{"key": "LOCAL_S3_PLANC_BUCKET", "label": "PLANC 桶", "type": "string"},
|
||
{"key": "PUBLIC_S3_ENDPOINT", "label": "公网端点", "type": "string"},
|
||
{"key": "PUBLIC_S3_ACCESS_KEY", "label": "公网 AccessKey", "type": "password", "secret": True},
|
||
{"key": "PUBLIC_S3_SECRET_KEY", "label": "公网 SecretKey", "type": "password", "secret": True},
|
||
{"key": "PUBLIC_S3_BUCKET", "label": "公网桶", "type": "string"},
|
||
{"key": "PUBLIC_S3_REGION", "label": "公网 Region", "type": "string"},
|
||
{"key": "PUBLIC_S3_SECURE", "label": "公网 HTTPS", "type": "bool", "default": True},
|
||
{"key": "PUBLIC_S3_DOMAIN", "label": "公网访问域名", "type": "string"},
|
||
],
|
||
store=_s3mod,
|
||
apply_extra=_reset_s3_caches,
|
||
)
|
||
|
||
# 3) 群分组配置(data/list.json, 权威源在插件自身)
|
||
register_config_items(
|
||
_PLUGIN_ID,
|
||
[
|
||
{
|
||
"key": "group_config",
|
||
"label": "群分组配置",
|
||
"type": "json",
|
||
"description": "data/list.json 内容。groups 为 {群号: {auto, plan(A/B), auto_link[]}},blacklist 为禁用用户 QQ 列表。白名单即 groups 的键。",
|
||
"getter": list_proc.get_group_config_sync,
|
||
"setter": list_proc.set_group_config_sync,
|
||
"nosave": True,
|
||
}
|
||
],
|
||
)
|