feat: 多频道任务队列总览卡片
部署到群晖 / deploy (push) Successful in 52s

- download_stat 新增 _task_queue / _completed_chats 与三个辅助函数
- 切频道前自动把上一个频道的最终进度快照进 completed_chats
- save_and_restart(_multi) 启动任务时设置队列,供前端渲染总览
- 前端 banner 改为"任务队列"多卡片列表(已完成 / 🚀当前 / 排队中),
  含进度条、跳过明细;兼容单频道场景

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
yuming
2026-04-23 12:47:44 +08:00
parent 58194ba29f
commit e5e375c30d
4 changed files with 225 additions and 76 deletions
+55 -2
View File
@@ -43,6 +43,12 @@ _task_progress: dict = {
"last_update": 0,
}
# 多频道任务队列与已完成快照(独立于 _task_progress,不被单频道 reset 影响)
# _task_queue: 任务开始时由 API 设置,[{chat_id, chat_title}, ...]
# _completed_chats: 每切换一个频道前把上一个的最终进度快照到这里
_task_queue: list = []
_completed_chats: list = []
def get_download_result() -> dict:
"""get global download result"""
@@ -62,7 +68,7 @@ def get_download_state() -> DownloadState:
def get_task_progress() -> dict:
"""get task progress with auto-detection of checking state"""
progress = _task_progress.copy()
# Auto-detect if still checking based on last_update time
# If last update was within 3 seconds, consider it still active
if progress["current_chat"] and progress["last_update"] > 0:
@@ -73,10 +79,57 @@ def get_task_progress() -> dict:
progress["is_checking"] = True
elif progress["skipped_files"] > 0 or progress["checked_messages"] > 0:
progress["is_checking"] = False
# 附加多频道任务总览,供前端渲染队列卡片
progress["task_queue"] = list(_task_queue)
progress["completed_chats"] = list(_completed_chats)
return progress
def snapshot_current_chat():
"""把当前 _task_progress 的核心字段快照进 _completed_chats。current_chat 为空时 no-op。
在多频道串行下载时,每个 download_chat_task 开始前调用,保留上一个频道的最终进度。
"""
global _completed_chats
chat_id = _task_progress.get("current_chat", "")
if not chat_id:
return
qual = _task_progress.get("qualified_files", 0) or 0
est = _task_progress.get("estimated_total", 0) or 0
existing = _task_progress.get("existing_skipped", 0) or 0
raw_total = est or qual
real_total = max(0, raw_total - existing)
_completed_chats.append({
"chat_id": chat_id,
"chat_title": _task_progress.get("current_chat_title", "") or chat_id,
"done": _task_progress.get("completed_files", 0) or 0,
"total": real_total,
"skip": _task_progress.get("skipped_files", 0) or 0,
"existing_skip": existing,
"failed": _task_progress.get("failed_files", 0) or 0,
})
def set_task_queue(items: list):
"""设置本次任务的完整频道队列。items 每项 {chat_id, chat_title}。"""
global _task_queue
_task_queue = []
for it in (items or []):
cid = str(it.get("chat_id", "") or "").strip()
if not cid:
continue
_task_queue.append({
"chat_id": cid,
"chat_title": it.get("chat_title", "") or cid,
})
def clear_completed_chats():
"""新任务启动时清空已完成列表。"""
global _completed_chats
_completed_chats = []
def update_task_progress(
current_chat: str = None,
current_chat_title: str = None,