add 事件广播
This commit is contained in:
@ -6,13 +6,14 @@ from typing import Optional, Any, Tuple, List, Set, Union, Dict
|
||||
from ruamel.yaml import CommentedMap
|
||||
|
||||
from app.core.context import Context
|
||||
from app.core.event import EventManager
|
||||
from app.core.module import ModuleManager
|
||||
from app.core.context import MediaInfo, TorrentInfo
|
||||
from app.core.meta import MetaBase
|
||||
from app.log import logger
|
||||
from app.schemas.context import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent
|
||||
from app.utils.singleton import AbstractSingleton, Singleton
|
||||
from app.utils.types import TorrentStatus, MediaType
|
||||
from app.schemas.types import TorrentStatus, MediaType
|
||||
|
||||
|
||||
class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
@ -25,6 +26,7 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
公共初始化
|
||||
"""
|
||||
self.modulemanager = ModuleManager()
|
||||
self.eventmanager = EventManager()
|
||||
|
||||
@abstractmethod
|
||||
def process(self, *args, **kwargs) -> Optional[Context]:
|
||||
|
@ -9,7 +9,7 @@ from app.helper.torrent import TorrentHelper
|
||||
from app.log import logger
|
||||
from app.schemas.context import ExistMediaInfo, NotExistMediaInfo
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.types import MediaType, TorrentStatus
|
||||
from app.schemas.types import MediaType, TorrentStatus, EventType
|
||||
|
||||
|
||||
class DownloadChain(ChainBase):
|
||||
@ -115,6 +115,12 @@ class DownloadChain(ChainBase):
|
||||
self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent, userid=userid)
|
||||
# 下载成功后处理
|
||||
self.download_added(context=_context, torrent_path=_torrent_file)
|
||||
# 广播事件
|
||||
self.eventmanager.send_event(EventType.DownloadAdded, {
|
||||
"hash": _hash,
|
||||
"torrent_file": _torrent_file,
|
||||
"context": _context
|
||||
})
|
||||
else:
|
||||
# 下载失败
|
||||
logger.error(f"{_media.title_year} 添加下载任务失败:"
|
||||
|
@ -9,7 +9,7 @@ from app.helper.sites import SitesHelper
|
||||
from app.log import logger
|
||||
from app.schemas.context import NotExistMediaInfo
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.types import MediaType
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
|
||||
class SearchChain(ChainBase):
|
||||
|
@ -11,7 +11,7 @@ from app.helper.sites import SitesHelper
|
||||
from app.log import logger
|
||||
from app.schemas.context import NotExistMediaInfo
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.types import MediaType
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
|
||||
class SubscribeChain(ChainBase):
|
||||
|
@ -10,7 +10,7 @@ from app.log import logger
|
||||
from app.schemas.context import TransferInfo, TransferTorrent
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.system import SystemUtils
|
||||
from app.utils.types import TorrentStatus
|
||||
from app.schemas.types import TorrentStatus, EventType
|
||||
|
||||
|
||||
class TransferChain(ChainBase):
|
||||
@ -114,6 +114,12 @@ class TransferChain(ChainBase):
|
||||
self.refresh_mediaserver(mediainfo=mediainfo, file_path=transferinfo.target_path)
|
||||
# 发送通知
|
||||
self.__send_transfer_message(meta=meta, mediainfo=mediainfo, transferinfo=transferinfo)
|
||||
# 广播事件
|
||||
self.eventmanager.send_event(EventType.TransferComplete, {
|
||||
'meta': meta,
|
||||
'mediainfo': mediainfo,
|
||||
'transferinfo': transferinfo
|
||||
})
|
||||
|
||||
logger.info("下载器文件转移执行完成")
|
||||
return True
|
||||
|
@ -7,7 +7,7 @@ from app.core.context import MediaInfo, TorrentInfo
|
||||
from app.core.metainfo import MetaInfo
|
||||
from app.core.event import EventManager
|
||||
from app.log import logger
|
||||
from app.utils.types import EventType
|
||||
from app.schemas.types import EventType
|
||||
|
||||
|
||||
class UserMessageChain(ChainBase):
|
||||
|
@ -3,6 +3,7 @@ from typing import Any
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.utils.http import WebUtils
|
||||
from app.schemas.types import EventType
|
||||
|
||||
|
||||
class WebhookMessageChain(ChainBase):
|
||||
@ -18,6 +19,8 @@ class WebhookMessageChain(ChainBase):
|
||||
event_info: dict = self.webhook_parser(body=body, form=form, args=args)
|
||||
if not event_info:
|
||||
return
|
||||
# 广播事件
|
||||
self.eventmanager.send_event(EventType.WebhookMessage, event_info)
|
||||
# 拼装消息内容
|
||||
_webhook_actions = {
|
||||
"library.new": "新入库",
|
||||
|
Reference in New Issue
Block a user