fix webhooks
This commit is contained in:
parent
f1a798cd05
commit
738335d16c
@ -1,3 +1,4 @@
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Request
|
||||
|
||||
@ -8,11 +9,11 @@ from app.core.config import settings
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def start_webhook_chain(message: dict):
|
||||
def start_webhook_chain(body: Any, form: Any, args: Any):
|
||||
"""
|
||||
启动链式任务
|
||||
"""
|
||||
WebhookMessageChain().process(message)
|
||||
WebhookMessageChain().process(body=body, form=form, args=args)
|
||||
|
||||
|
||||
@router.post("/", response_model=schemas.Response)
|
||||
@ -22,6 +23,8 @@ async def webhook_message(background_tasks: BackgroundTasks, token: str, request
|
||||
"""
|
||||
if token != settings.API_TOKEN:
|
||||
return {"success": False, "message": "token认证不通过"}
|
||||
|
||||
background_tasks.add_task(start_webhook_chain, await request.json())
|
||||
body = await request.body()
|
||||
form = await request.form()
|
||||
args = request.query_params
|
||||
background_tasks.add_task(start_webhook_chain, body, form, args)
|
||||
return {"success": True}
|
||||
|
@ -79,8 +79,8 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
def message_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
return self.run_module("message_parser", body=body, form=form, args=args)
|
||||
|
||||
def webhook_parser(self, message: dict) -> Optional[dict]:
|
||||
return self.run_module("webhook_parser", message=message)
|
||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
return self.run_module("webhook_parser", body=body, form=form, args=args)
|
||||
|
||||
def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||
return self.run_module("obtain_image", mediainfo=mediainfo)
|
||||
|
@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
from app.chain import ChainBase
|
||||
|
||||
|
||||
@ -6,12 +8,12 @@ class WebhookMessageChain(ChainBase):
|
||||
响应Webhook事件
|
||||
"""
|
||||
|
||||
def process(self, message: dict) -> None:
|
||||
def process(self, body: Any, form: Any, args: Any) -> None:
|
||||
"""
|
||||
处理Webhook报文并发送消息
|
||||
"""
|
||||
# 获取主体内容
|
||||
info: dict = self.webhook_parser(message=message)
|
||||
info: dict = self.webhook_parser(body=body, form=form, args=args)
|
||||
if not info:
|
||||
return
|
||||
# 发送消息
|
||||
|
@ -73,10 +73,12 @@ class _ModuleBase(metaclass=ABCMeta):
|
||||
"""
|
||||
pass
|
||||
|
||||
def webhook_parser(self, message: dict) -> Optional[dict]:
|
||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
"""
|
||||
解析Webhook报文体
|
||||
:param message: 请求体
|
||||
:param body: 请求体
|
||||
:param form: 表单
|
||||
:param args: 参数
|
||||
:return: 字典,解析为消息时需要包含:title、text、image
|
||||
"""
|
||||
pass
|
||||
|
@ -1,4 +1,5 @@
|
||||
from typing import Optional, Tuple, Union
|
||||
import json
|
||||
from typing import Optional, Tuple, Union, Any
|
||||
|
||||
from app.core.context import MediaInfo
|
||||
from app.log import logger
|
||||
@ -20,13 +21,15 @@ class EmbyModule(_ModuleBase):
|
||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||
return "MEDIASERVER", "emby"
|
||||
|
||||
def webhook_parser(self, message: dict) -> Optional[dict]:
|
||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
"""
|
||||
解析Webhook报文体
|
||||
:param message: 请求体
|
||||
:param body: 请求体
|
||||
:param form: 请求表单
|
||||
:param args: 请求参数
|
||||
:return: 字典,解析为消息时需要包含:title、text、image
|
||||
"""
|
||||
return self.emby.get_webhook_message(message)
|
||||
return self.emby.get_webhook_message(json.loads(body))
|
||||
|
||||
def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]:
|
||||
"""
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Optional, Tuple, Union
|
||||
from typing import Optional, Tuple, Union, Any
|
||||
|
||||
from app.core.context import MediaInfo
|
||||
from app.log import logger
|
||||
@ -19,13 +19,15 @@ class JellyfinModule(_ModuleBase):
|
||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||
return "MEDIASERVER", "jellyfin"
|
||||
|
||||
def webhook_parser(self, message: dict) -> Optional[dict]:
|
||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
"""
|
||||
解析Webhook报文体
|
||||
:param message: 请求体
|
||||
:param body: 请求体
|
||||
:param form: 请求表单
|
||||
:param args: 请求参数
|
||||
:return: 字典,解析为消息时需要包含:title、text、image
|
||||
"""
|
||||
return self.jellyfin.get_webhook_message(message)
|
||||
return self.jellyfin.get_webhook_message(form.get("data"))
|
||||
|
||||
def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]:
|
||||
"""
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import Optional, Tuple, Union
|
||||
from typing import Optional, Tuple, Union, Any
|
||||
|
||||
from app.core.context import MediaInfo
|
||||
from app.log import logger
|
||||
@ -20,13 +20,15 @@ class PlexModule(_ModuleBase):
|
||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||
return "MEDIASERVER", "plex"
|
||||
|
||||
def webhook_parser(self, message: dict) -> Optional[dict]:
|
||||
def webhook_parser(self, body: Any, form: Any, args: Any) -> Optional[dict]:
|
||||
"""
|
||||
解析Webhook报文体
|
||||
:param message: 请求体
|
||||
:param body: 请求体
|
||||
:param form: 请求表单
|
||||
:param args: 请求参数
|
||||
:return: 字典,解析为消息时需要包含:title、text、image
|
||||
"""
|
||||
return self.plex.get_webhook_message(message)
|
||||
return self.plex.get_webhook_message(form.get("payload"))
|
||||
|
||||
def media_exists(self, mediainfo: MediaInfo) -> Optional[dict]:
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user