From 61f7b082e43ddacceff5e95b15d9378f0d962c7b Mon Sep 17 00:00:00 2001 From: dsutanto Date: Thu, 30 Jul 2026 21:34:34 +0700 Subject: [PATCH] Fix long loading --- recounting_dashboard.py | 29 +++++++++++++++++------------ templates/recounting.html | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/recounting_dashboard.py b/recounting_dashboard.py index 7efe23b..8462926 100644 --- a/recounting_dashboard.py +++ b/recounting_dashboard.py @@ -112,25 +112,30 @@ def api_recount_progress(): def api_mp4_files(): folders = {} output = Path(OUTPUT_DIR) - if output.exists(): - for f in sorted(output.rglob("*.mp4"), key=lambda p: p.stat().st_mtime, reverse=True): + if not output.exists(): + return jsonify([]) + + for d in sorted(output.iterdir(), reverse=True): + if not d.is_dir(): + continue + folder_name = d.name + mp4s = sorted(d.glob("*.mp4"), key=lambda p: p.stat().st_mtime, reverse=True) + if not mp4s: + continue + files = [] + for f in mp4s: st = f.stat() - rel = f.relative_to(output) - folder = str(rel.parent) if str(rel.parent) != "." else "" - if folder not in folders: - folders[folder] = [] - folders[folder].append({ + files.append({ "name": f.name, "path": str(f), "size": st.st_size, "mtime": datetime.fromtimestamp(st.st_mtime).isoformat(), }) + folders[folder_name] = files + result = [] - for folder, files in sorted(folders.items(), key=lambda x: x[0], reverse=True): - result.append({ - "folder": folder, - "files": files, - }) + for folder, files in sorted(folders.items(), reverse=True): + result.append({"folder": folder, "files": files}) return jsonify(result) diff --git a/templates/recounting.html b/templates/recounting.html index d74c521..2baaeb6 100644 --- a/templates/recounting.html +++ b/templates/recounting.html @@ -505,10 +505,10 @@ function applyState(data) { // --- File list --- async function loadFiles() { + const container = document.getElementById('file-list'); try { const res = await fetch('/api/mp4-files'); const folders = await res.json(); - const container = document.getElementById('file-list'); if (!folders || folders.length === 0) { container.innerHTML = '
No MP4 files found
'; return;