From ceeb20ed2de8496facbc3d16c9a593599e7306f6 Mon Sep 17 00:00:00 2001 From: yubanmeiqin9048 <1414603524@qq.com> Date: Mon, 7 Aug 2023 20:59:50 +0800 Subject: [PATCH 1/4] update webhook plugin --- app/plugins/webhook/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/plugins/webhook/__init__.py b/app/plugins/webhook/__init__.py index e7d95604..da3b52de 100644 --- a/app/plugins/webhook/__init__.py +++ b/app/plugins/webhook/__init__.py @@ -5,7 +5,6 @@ from app.utils.http import RequestUtils from typing import Any, List, Dict, Tuple from app.log import logger - class WebHook(_PluginBase): # 插件名称 plugin_name = "Webhook" @@ -135,10 +134,21 @@ class WebHook(_PluginBase): """ if not self._webhook_url: return + + def __to_dict(event): + # 遍历 event_data + result = {} + for key, value in event.items(): + if hasattr(value, 'to_dict'): + result[key] = value.to_dict() + result[key] = str(value) + return result + event_info = { "type": event.event_type, - "data": str(event.event_data) + "data": __to_dict(event.event_data) } + if self._method == 'POST': ret = RequestUtils(content_type="application/json").post_res(self._webhook_url, json=event_info) else: From f7b96daa50d933198b107c59be679f4caa8bdc25 Mon Sep 17 00:00:00 2001 From: yubanmeiqin9048 <1414603524@qq.com> Date: Mon, 7 Aug 2023 21:01:47 +0800 Subject: [PATCH 2/4] fix to_dict --- app/core/context.py | 1 + app/schemas/transfer.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/core/context.py b/app/core/context.py index 7b568a51..7b47777a 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -549,6 +549,7 @@ class MediaInfo: dicts["type"] = self.type.value if self.type else None dicts["detail_link"] = self.detail_link dicts["title_year"] = self.title_year + dicts["tmdb_info"]["media_type"] = self.type.value if self.type else None return dicts def clear(self): diff --git a/app/schemas/transfer.py b/app/schemas/transfer.py index 7f95b3de..2f7f04b5 100644 --- a/app/schemas/transfer.py +++ b/app/schemas/transfer.py @@ -30,7 +30,6 @@ class DownloadingTorrent(BaseModel): dlspeed: Optional[str] = None media: Optional[dict] = {} - class TransferInfo(BaseModel): """ 文件转移结果信息 @@ -51,3 +50,12 @@ class TransferInfo(BaseModel): fail_list: Optional[list] = [] # 错误信息 message: Optional[str] = None + + def to_dict(self): + """ + 返回字典 + """ + dicts = vars(self).copy() # 创建一个字典的副本以避免修改原始数据 + dicts["path"] = str(self.path) if self.path else None + dicts["target_path"] = str(self.target_path) if self.target_path else None + return dicts \ No newline at end of file From 6c147131ba149ab363f3a55a123ec549593914d6 Mon Sep 17 00:00:00 2001 From: yubanmeiqin9048 <1414603524@qq.com> Date: Mon, 7 Aug 2023 23:12:35 +0800 Subject: [PATCH 3/4] fix --- app/plugins/webhook/__init__.py | 1 + app/schemas/transfer.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/plugins/webhook/__init__.py b/app/plugins/webhook/__init__.py index da3b52de..81bc5774 100644 --- a/app/plugins/webhook/__init__.py +++ b/app/plugins/webhook/__init__.py @@ -5,6 +5,7 @@ from app.utils.http import RequestUtils from typing import Any, List, Dict, Tuple from app.log import logger + class WebHook(_PluginBase): # 插件名称 plugin_name = "Webhook" diff --git a/app/schemas/transfer.py b/app/schemas/transfer.py index 2f7f04b5..245c0334 100644 --- a/app/schemas/transfer.py +++ b/app/schemas/transfer.py @@ -4,6 +4,7 @@ from typing import Optional from pydantic import BaseModel + class TransferTorrent(BaseModel): """ 待转移任务信息 @@ -30,6 +31,7 @@ class DownloadingTorrent(BaseModel): dlspeed: Optional[str] = None media: Optional[dict] = {} + class TransferInfo(BaseModel): """ 文件转移结果信息 From c6e896dbbaa713a0b772bf97b267123f1850b5f3 Mon Sep 17 00:00:00 2001 From: yubanmeiqin9048 <64676973+yubanmeiqin9048@users.noreply.github.com> Date: Tue, 8 Aug 2023 07:36:44 +0800 Subject: [PATCH 4/4] fix --- app/plugins/webhook/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/plugins/webhook/__init__.py b/app/plugins/webhook/__init__.py index 81bc5774..c38f60f9 100644 --- a/app/plugins/webhook/__init__.py +++ b/app/plugins/webhook/__init__.py @@ -137,12 +137,12 @@ class WebHook(_PluginBase): return def __to_dict(event): - # 遍历 event_data result = {} for key, value in event.items(): if hasattr(value, 'to_dict'): - result[key] = value.to_dict() - result[key] = str(value) + result[key] = value.to_dict() + else: + result[key] = str(value) return result event_info = {