fix actions

This commit is contained in:
jxxghp
2025-02-19 16:43:42 +08:00
parent 351029a842
commit 1317d9c4f0
8 changed files with 154 additions and 17 deletions
+25 -2
View File
@@ -1,4 +1,5 @@
from app.actions import BaseAction
from app.chain.download import DownloadChain
from app.schemas import ActionParams, ActionContext
@@ -14,6 +15,12 @@ class FetchDownloadsAction(BaseAction):
获取下载任务
"""
_downloads = []
def __init__(self):
super().__init__()
self.downloadchain = DownloadChain()
@property
def name(self) -> str:
return "获取下载任务"
@@ -24,7 +31,23 @@ class FetchDownloadsAction(BaseAction):
@property
def success(self) -> bool:
return True
if not self._downloads:
return True
return True if all([d.completed for d in self._downloads]) else False
async def execute(self, params: FetchDownloadsParams, context: ActionContext) -> ActionContext:
pass
"""
更新downloads中的下载任务状态
"""
self._downloads = context.downloads
for download in self._downloads:
torrents = self.downloadchain.list_torrents(hashs=[download.download_id])
if not torrents:
download.completed = True
continue
for t in torrents:
if t.progress >= 100:
download.completed = True
self.job_done()
return context