diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 60209c2a..02ce8886 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -437,12 +437,13 @@ class ChainBase(metaclass=ABCMeta): :param medias: 媒体列表 :return: 成功或失败 """ - self.messagehelper.put(message, role="user") + note_list = [media.to_dict() for media in medias] + self.messagehelper.put(message, role="user", note=note_list) self.messageoper.add(channel=message.channel, mtype=message.mtype, title=message.title, text=message.text, image=message.image, link=message.link, userid=message.userid, action=1, - note=[media.to_dict() for media in medias]) + note=note_list) return self.run_module("post_medias_message", message=message, medias=medias) def post_torrents_message(self, message: Notification, torrents: List[Context]) -> Optional[bool]: @@ -452,12 +453,13 @@ class ChainBase(metaclass=ABCMeta): :param torrents: 种子列表 :return: 成功或失败 """ - self.messagehelper.put(message, role="user") + note_list = [torrent.torrent_info.to_dict() for torrent in torrents] + self.messagehelper.put(message, role="user", note=note_list) self.messageoper.add(channel=message.channel, mtype=message.mtype, title=message.title, text=message.text, image=message.image, link=message.link, userid=message.userid, action=1, - note=[torrent.to_dict() for torrent in torrents]) + note=note_list) return self.run_module("post_torrents_message", message=message, torrents=torrents) def scrape_metadata(self, path: Path, mediainfo: MediaInfo, transfer_type: str, diff --git a/app/core/context.py b/app/core/context.py index f5b0ca37..993f5c53 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -615,6 +615,7 @@ class MediaInfo: """ 返回字典 """ + self.clear() dicts = asdict(self) dicts["type"] = self.type.value if self.type else None dicts["detail_link"] = self.detail_link diff --git a/app/db/message_oper.py b/app/db/message_oper.py index 82d55b77..02863b17 100644 --- a/app/db/message_oper.py +++ b/app/db/message_oper.py @@ -50,7 +50,7 @@ class MessageOper(DbOper): "userid": userid, "action": action, "reg_time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), - "note": json.dumps(note or {}) + "note": json.dumps(note) if note else '' }) Message(**kwargs).create(self._db) diff --git a/app/helper/message.py b/app/helper/message.py index f8606188..d609fdc5 100644 --- a/app/helper/message.py +++ b/app/helper/message.py @@ -14,11 +14,12 @@ class MessageHelper(metaclass=Singleton): self.sys_queue = queue.Queue() self.user_queue = queue.Queue() - def put(self, message: Any, role: str = "sys"): + def put(self, message: Any, role: str = "sys", note: dict = None): """ 存消息 :param message: 消息 :param role: 消息通道 sys/user + :param note: 附件json """ if role == "sys": self.sys_queue.put(message) @@ -28,6 +29,7 @@ class MessageHelper(metaclass=Singleton): elif hasattr(message, "to_dict"): content = message.to_dict() content['date'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + content['note'] = json.dumps(note) if note else None self.user_queue.put(json.dumps(content)) def get(self, role: str = "sys") -> Optional[str]: