- policy.py:per-group 正交策略(自动解析 / 自动策略 / 禁用策略 / 存储 A·B·C /
公网 / 链接 / 群文件 + 平台限定),list.json v1/v2 → v3 自动迁移,
写入统一走 PolicyStore(加锁 + .tmp 原子替换 + 字段归一)
- 群文件并行通道 group_file.py:打包 zip(可选 pyzipper AES-256)后优先走 S3 预签名、
本地直传兜底;设了密码但 pyzipper 不可用就放弃上传,不退化成明文
- list_proc.py 收敛到「视频策略」统一入口,权限判定改走 policy
- Web 管理页 /hub/video_analysis(群策略 + 链接解析面板)与 services/web_jobs.py
(只复用纯函数层,Web 上下文不发消息;内存任务表 + 并发闸门 + 超时)
- 媒体命名统一到 utils.py({作者}_{作者id}/{作品名}[_短码]),cleanup 回收空目录
- 测试:policy / 命名 / 群文件 / web_jobs 四组
顺带 pyproject 的 pytest 加 testpaths=tests(避免收进 debug/ 下的调试脚本)。
Co-Authored-By: Claude Code <noreply@anthropic.com>
138 lines
6.3 KiB
Python
138 lines
6.3 KiB
Python
"""统一配置注册:把插件配置按文档标准接入 hexi.web_hub.web_config(Web 可读可改)。
|
|
|
|
- temp 清理配置(env pydantic) → register_model_config
|
|
- 群文件投递配置(打包/解压密码, env pydantic) → register_model_config
|
|
- S3 存储配置(原硬编码在 services/storage/s3.py) → register_config_items(store=s3 模块)
|
|
|
|
群策略(data/list.json v3)不在这里注册:它有独立的 Web 页面与 API
|
|
(见 web_hub.py),不再走配置抽屉里的裸 JSON 编辑。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from nonebot import get_plugin_config
|
|
from pydantic import BaseModel
|
|
|
|
from hexi.web_hub.config_standard import register_config_items, register_model_config
|
|
|
|
from . import cleanup # noqa: F401
|
|
from .services.storage import s3 as _s3mod
|
|
|
|
# 插件模块名 = plugin_id(与 NoneBot 模块名一致)
|
|
_PLUGIN_ID = __package__
|
|
|
|
|
|
class GroupFileConfig(BaseModel):
|
|
# 上传群文件时打包成一个 zip(关掉则逐个上传原文件)
|
|
video_analysis_group_file_zip: bool = True
|
|
# 压缩包解压密码(留空 = 不加密; 设置后要求 pyzipper 可用, 否则放弃群文件上传)
|
|
video_analysis_group_file_password: str = ""
|
|
|
|
|
|
group_file_config = get_plugin_config(GroupFileConfig)
|
|
|
|
|
|
def group_file_settings() -> tuple[bool, str]:
|
|
"""群文件投递设置:(是否打包成 zip, 解压密码)。
|
|
|
|
运行期读取实例属性,所以 Web 保存后立即生效(apply 是 setattr)。
|
|
"""
|
|
return (
|
|
bool(group_file_config.video_analysis_group_file_zip),
|
|
str(group_file_config.video_analysis_group_file_password or ""),
|
|
)
|
|
|
|
|
|
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) 群文件投递:打包 / 解压密码
|
|
register_model_config(
|
|
_PLUGIN_ID,
|
|
group_file_config,
|
|
fields=[
|
|
"video_analysis_group_file_zip",
|
|
"video_analysis_group_file_password",
|
|
],
|
|
labels={
|
|
"video_analysis_group_file_zip": "群文件打包成 zip",
|
|
"video_analysis_group_file_password": "压缩包解压密码",
|
|
},
|
|
descriptions={
|
|
"video_analysis_group_file_zip": "开启后群文件收到的是一个压缩包;关闭则逐个上传原文件",
|
|
"video_analysis_group_file_password": "留空 = 不加密;设置后用 AES-256 加密(需要 7-Zip/WinRAR 等工具解压),缺 pyzipper 时会放弃群文件上传而不是传明文",
|
|
},
|
|
types={
|
|
"video_analysis_group_file_zip": "bool",
|
|
"video_analysis_group_file_password": "password",
|
|
},
|
|
)
|
|
|
|
# 3) 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,
|
|
)
|