From d8f9ab93e51958d3e8b23b785076742160623efd Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 19 Feb 2024 16:07:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=B6=E5=88=A0=E9=99=A4=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=20fix=20#1391?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/history.py | 3 ++- app/chain/download.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index 63f64d07..0b2066cb 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -96,7 +96,8 @@ def delete_transfer_history(history_in: schemas.TransferHistory, eventmanager.send_event( EventType.DownloadFileDeleted, { - "src": history.src + "src": history.src, + "hash": history.download_hash } ) # 删除记录 diff --git a/app/chain/download.py b/app/chain/download.py index 1b61366e..5b7f9a13 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -9,6 +9,7 @@ from typing import List, Optional, Tuple, Set, Dict, Union from app.chain import ChainBase from app.core.config import settings from app.core.context import MediaInfo, TorrentInfo, Context +from app.core.event import eventmanager, Event from app.core.meta import MetaBase from app.core.metainfo import MetaInfo from app.db.downloadhistory_oper import DownloadHistoryOper @@ -838,3 +839,16 @@ class DownloadChain(ChainBase): 删除下载任务 """ return self.remove_torrents(hashs=[hash_str]) + + @eventmanager.register(EventType.DownloadFileDeleted) + def download_file_deleted(self, event: Event): + """ + 下载文件删除时,同步删除下载任务 + """ + if not event: + return + hash_str = event.event_data.get("hash") + if not hash_str: + return + logger.warn(f"检测到下载源文件被删除,删除下载任务:{hash_str}") + self.remove_torrents(hashs=[hash_str])