feat:源文件删除时删除下载任务 fix #1391
This commit is contained in:
@ -96,7 +96,8 @@ def delete_transfer_history(history_in: schemas.TransferHistory,
|
|||||||
eventmanager.send_event(
|
eventmanager.send_event(
|
||||||
EventType.DownloadFileDeleted,
|
EventType.DownloadFileDeleted,
|
||||||
{
|
{
|
||||||
"src": history.src
|
"src": history.src,
|
||||||
|
"hash": history.download_hash
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# 删除记录
|
# 删除记录
|
||||||
|
@ -9,6 +9,7 @@ from typing import List, Optional, Tuple, Set, Dict, Union
|
|||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo, TorrentInfo, Context
|
from app.core.context import MediaInfo, TorrentInfo, Context
|
||||||
|
from app.core.event import eventmanager, Event
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.db.downloadhistory_oper import DownloadHistoryOper
|
from app.db.downloadhistory_oper import DownloadHistoryOper
|
||||||
@ -838,3 +839,16 @@ class DownloadChain(ChainBase):
|
|||||||
删除下载任务
|
删除下载任务
|
||||||
"""
|
"""
|
||||||
return self.remove_torrents(hashs=[hash_str])
|
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])
|
||||||
|
Reference in New Issue
Block a user