mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor(notification): 建立通知渠道通用管理契约 channel_manage
- schemas 层新增 NotificationAction 公共动作词汇表(状态/二维码/退出/连通性/缓存迁移) - 模块实现统一 channel_manage(channel, action, **params),按渠道名路由, 非本渠道返回 None;动作语义、表单参数解释与临时参数初始化封闭在模块内 - NotificationChain 收敛为单一 manage_channel 纯透明转发, chain 层不再出现任何渠道名与模块特色 - endpoint 路由路径保持前端兼容,内部统一走通用接口 - 新增 6 项契约守护测试,文档记录通用模式:新渠道接入无需改 chain
This commit is contained in:
@@ -7,6 +7,7 @@ from app.api.response import ResponseAPIRouter
|
||||
from app.chain.notification import NotificationChain
|
||||
from app.db.models import User
|
||||
from app.api.deps import get_current_active_superuser
|
||||
from app.schemas.types import MessageChannel, NotificationAction
|
||||
|
||||
router = ResponseAPIRouter()
|
||||
|
||||
@@ -27,15 +28,17 @@ def wechatclawbot_status(
|
||||
_: User = Depends(get_current_active_superuser),
|
||||
):
|
||||
"""查询微信 ClawBot 登录状态和二维码。"""
|
||||
result = NotificationChain().get_wechatclawbot_status(
|
||||
result = NotificationChain().manage_channel(
|
||||
channel=MessageChannel.WechatClawBot,
|
||||
action=NotificationAction.STATUS,
|
||||
source=source,
|
||||
fallback_source=fallback_source,
|
||||
refresh_remote=refresh_remote,
|
||||
auto_generate_qrcode=auto_generate_qrcode,
|
||||
WECHATCLAWBOT_BASE_URL=WECHATCLAWBOT_BASE_URL,
|
||||
WECHATCLAWBOT_DEFAULT_TARGET=WECHATCLAWBOT_DEFAULT_TARGET,
|
||||
WECHATCLAWBOT_ADMINS=WECHATCLAWBOT_ADMINS,
|
||||
WECHATCLAWBOT_POLL_TIMEOUT=WECHATCLAWBOT_POLL_TIMEOUT,
|
||||
refresh_remote=refresh_remote,
|
||||
auto_generate_qrcode=auto_generate_qrcode,
|
||||
)
|
||||
return schemas.Response(
|
||||
success=bool(result.get("success")),
|
||||
@@ -59,7 +62,9 @@ def refresh_wechatclawbot_qrcode(
|
||||
_: User = Depends(get_current_active_superuser),
|
||||
):
|
||||
"""刷新微信 ClawBot 二维码。"""
|
||||
result = NotificationChain().refresh_wechatclawbot_qrcode(
|
||||
result = NotificationChain().manage_channel(
|
||||
channel=MessageChannel.WechatClawBot,
|
||||
action=NotificationAction.REFRESH_QRCODE,
|
||||
source=source,
|
||||
fallback_source=fallback_source,
|
||||
WECHATCLAWBOT_BASE_URL=WECHATCLAWBOT_BASE_URL,
|
||||
@@ -89,7 +94,9 @@ def logout_wechatclawbot(
|
||||
_: User = Depends(get_current_active_superuser),
|
||||
):
|
||||
"""退出微信 ClawBot 登录。"""
|
||||
result = NotificationChain().logout_wechatclawbot(
|
||||
result = NotificationChain().manage_channel(
|
||||
channel=MessageChannel.WechatClawBot,
|
||||
action=NotificationAction.LOGOUT,
|
||||
source=source,
|
||||
fallback_source=fallback_source,
|
||||
WECHATCLAWBOT_BASE_URL=WECHATCLAWBOT_BASE_URL,
|
||||
@@ -119,7 +126,9 @@ def test_wechatclawbot(
|
||||
_: User = Depends(get_current_active_superuser),
|
||||
):
|
||||
"""测试微信 ClawBot 当前登录态是否可用。"""
|
||||
result = NotificationChain().test_wechatclawbot_connection(
|
||||
result = NotificationChain().manage_channel(
|
||||
channel=MessageChannel.WechatClawBot,
|
||||
action=NotificationAction.TEST_CONNECTION,
|
||||
source=source,
|
||||
fallback_source=fallback_source,
|
||||
WECHATCLAWBOT_BASE_URL=WECHATCLAWBOT_BASE_URL,
|
||||
@@ -143,10 +152,12 @@ def migrate_wechatclawbot_cache(
|
||||
_: User = Depends(get_current_active_superuser),
|
||||
):
|
||||
"""在通知名称变更时迁移对应的微信 ClawBot 登录缓存。"""
|
||||
success, message = NotificationChain().migrate_wechatclawbot_cache(
|
||||
result = NotificationChain().manage_channel(
|
||||
channel=MessageChannel.WechatClawBot,
|
||||
action=NotificationAction.MIGRATE_CACHE,
|
||||
old_name=old_source,
|
||||
new_name=new_source,
|
||||
cleanup_old=cleanup_old,
|
||||
overwrite=overwrite,
|
||||
)
|
||||
return schemas.Response(success=success, message=message)
|
||||
return schemas.Response(success=bool(result.get("success")), message=result.get("message"))
|
||||
|
||||
Reference in New Issue
Block a user