From ca7542f90f6d37a5c02a64511382970d01a251cb Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 2 Jul 2023 16:11:25 +0800 Subject: [PATCH] downloading api --- app/chain/download.py | 18 +++++++++++++++++- app/schemas/context.py | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/chain/download.py b/app/chain/download.py index 78d8e9f6..a5e9bdce 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -535,4 +535,20 @@ class DownloadChain(ChainBase): """ 查询正在下载的任务 """ - return self.list_torrents(status=TorrentStatus.DOWNLOADING) or [] + torrents = self.list_torrents(status=TorrentStatus.DOWNLOADING) + if not torrents: + return [] + ret_torrents = [] + for torrent in torrents: + history = self.downloadhis.get_by_hash(torrent.hash) + if history: + torrent.media = { + "tmdbid": history.tmdbid, + "type": history.type, + "title": history.title, + "season": history.seasons, + "episode": history.episodes, + "image": history.image, + } + ret_torrents.append(torrent) + return ret_torrents diff --git a/app/schemas/context.py b/app/schemas/context.py index c1ec23fc..fe5188bc 100644 --- a/app/schemas/context.py +++ b/app/schemas/context.py @@ -178,6 +178,7 @@ class TransferTorrent(BaseModel): path: Optional[Path] = None hash: Optional[str] = None tags: Optional[str] = None + media: Optional[dict] = {} class DownloadingTorrent(BaseModel):