From 4fc76e27f31726eafc03813511fa198368ab6a8a Mon Sep 17 00:00:00 2001 From: yuming Date: Fri, 24 Apr 2026 21:30:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=95=E6=9D=A1=E3=80=8C=E7=BB=A7?= =?UTF-8?q?=E7=BB=AD=E3=80=8D=E5=8F=AF=E7=AA=81=E7=A0=B4=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E6=9A=82=E5=81=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 全局暂停下对单条点继续,赋予该消息豁免权可绕过全局暂停 while 循环继续下载; 全局恢复下载或单条暂停/跳过时自动清理豁免,避免脏状态残留。 Co-Authored-By: Claude Opus 4.7 (1M context) --- module/download_stat.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/module/download_stat.py b/module/download_stat.py index fec8220..a48a66e 100644 --- a/module/download_stat.py +++ b/module/download_stat.py @@ -18,6 +18,8 @@ class DownloadState(Enum): _download_result: dict = {} _paused_messages: set = set() # (chat_id, message_id) 单条暂停 _skipped_messages: set = set() # (chat_id, message_id) 单条跳过 +# 全局暂停时被手动点「继续」的消息,允许它们突破全局暂停继续下载 +_individual_run_messages: set = set() _total_download_speed: int = 0 _total_download_size: int = 0 _last_download_time: float = time.time() @@ -203,22 +205,31 @@ def set_download_state(state: DownloadState): """set download state""" global _download_state _download_state = state + # 全局恢复下载时清空豁免集合:所有消息都能跑,豁免不再有意义,防止脏状态残留 + if state == DownloadState.Downloading: + _individual_run_messages.clear() def pause_message(chat_id: str, message_id: int): """暂停单条消息下载""" _paused_messages.add((chat_id, message_id)) + # 单独暂停意味着用户想让这条停下,移除豁免状态(如有) + _individual_run_messages.discard((chat_id, message_id)) def resume_message(chat_id: str, message_id: int): - """继续单条消息下载""" + """继续单条消息下载;若全局正处于暂停,赋予这条豁免通行权""" _paused_messages.discard((chat_id, message_id)) + # 仅在全局暂停时 resume 才需要豁免;全局正常时 resume 只是从单条暂停恢复,无需进豁免集合 + if _download_state == DownloadState.StopDownload: + _individual_run_messages.add((chat_id, message_id)) def skip_message(chat_id: str, message_id: int): """跳过单条消息下载""" _skipped_messages.add((chat_id, message_id)) _paused_messages.discard((chat_id, message_id)) + _individual_run_messages.discard((chat_id, message_id)) def is_message_paused(chat_id: str, message_id: int) -> bool: @@ -229,6 +240,11 @@ def is_message_skipped(chat_id: str, message_id: int) -> bool: return (chat_id, message_id) in _skipped_messages +def is_message_individual_run(chat_id: str, message_id: int) -> bool: + """该消息是否在全局暂停下被手动放行""" + return (chat_id, message_id) in _individual_run_messages + + def clear_skipped_message(chat_id: str, message_id: int): """清除跳过标记(下载流程退出时调用)""" _skipped_messages.discard((chat_id, message_id)) @@ -276,8 +292,11 @@ async def update_download_status( return await asyncio.sleep(0.5) - # 全局暂停 - while get_download_state() == DownloadState.StopDownload: + # 全局暂停:被手动点过「继续」的单条消息享有豁免,可以突破全局暂停继续下载 + while ( + get_download_state() == DownloadState.StopDownload + and not is_message_individual_run(*_msg_key) + ): if node.is_stop_transmission: client.stop_transmission() await asyncio.sleep(1)