diff --git a/module/web.py b/module/web.py index a85f37a..9970641 100644 --- a/module/web.py +++ b/module/web.py @@ -200,11 +200,37 @@ def get_download_speed(): ) +def _compute_current_task_queue() -> list: + """动态构造当前任务队列。 + 由于 restart 走 os.execv,download_stat 里的 _task_queue 全局变量会丢; + 所以真实来源以 _app.chat_download_config(config.yaml 重载后的结果)为准, + chat_title 从 channel_history 查。 + """ + global _app + if not _app or not _app.chat_download_config: + return [] + history_map = {} + for h in _load_channel_history(): + cid = str(h.get("chat_id", "") or "") + if cid: + history_map[cid] = h.get("chat_title", "") or cid + queue = [] + for chat_id in _app.chat_download_config.keys(): + cid_str = str(chat_id) + queue.append({ + "chat_id": cid_str, + "chat_title": history_map.get(cid_str, cid_str), + }) + return queue + + @_flask_app.route("/api/task_progress") @login_required def api_task_progress(): """Get current task progress including skipped files""" progress = get_task_progress() + # 覆盖 task_queue:download_stat 里的全局变量在 os.execv 重启后会丢,用 app 动态算才稳 + progress["task_queue"] = _compute_current_task_queue() return jsonify(progress)