Fix long loading
This commit is contained in:
1 parent
4f37419701
commit
61f7b082e4
2 files changed
+18
-13
No files matched your search
+17
-12
@@ -112,25 +112,30 @@ def api_recount_progress():
|
|||||||
def api_mp4_files():
|
def api_mp4_files():
|
||||||
folders = {}
|
folders = {}
|
||||||
output = Path(OUTPUT_DIR)
|
output = Path(OUTPUT_DIR)
|
||||||
if output.exists():
|
if not output.exists():
|
||||||
for f in sorted(output.rglob("*.mp4"), key=lambda p: p.stat().st_mtime, reverse=True):
|
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()
|
st = f.stat()
|
||||||
rel = f.relative_to(output)
|
files.append({
|
||||||
folder = str(rel.parent) if str(rel.parent) != "." else ""
|
|
||||||
if folder not in folders:
|
|
||||||
folders[folder] = []
|
|
||||||
folders[folder].append({
|
|
||||||
"name": f.name,
|
"name": f.name,
|
||||||
"path": str(f),
|
"path": str(f),
|
||||||
"size": st.st_size,
|
"size": st.st_size,
|
||||||
"mtime": datetime.fromtimestamp(st.st_mtime).isoformat(),
|
"mtime": datetime.fromtimestamp(st.st_mtime).isoformat(),
|
||||||
})
|
})
|
||||||
|
folders[folder_name] = files
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for folder, files in sorted(folders.items(), key=lambda x: x[0], reverse=True):
|
for folder, files in sorted(folders.items(), reverse=True):
|
||||||
result.append({
|
result.append({"folder": folder, "files": files})
|
||||||
"folder": folder,
|
|
||||||
"files": files,
|
|
||||||
})
|
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -505,10 +505,10 @@ function applyState(data) {
|
|||||||
// --- File list ---
|
// --- File list ---
|
||||||
|
|
||||||
async function loadFiles() {
|
async function loadFiles() {
|
||||||
|
const container = document.getElementById('file-list');
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/mp4-files');
|
const res = await fetch('/api/mp4-files');
|
||||||
const folders = await res.json();
|
const folders = await res.json();
|
||||||
const container = document.getElementById('file-list');
|
|
||||||
if (!folders || folders.length === 0) {
|
if (!folders || folders.length === 0) {
|
||||||
container.innerHTML = '<div style="font-size:10px;color:var(--text-secondary);text-align:center;padding:20px;">No MP4 files found</div>';
|
container.innerHTML = '<div style="font-size:10px;color:var(--text-secondary);text-align:center;padding:20px;">No MP4 files found</div>';
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user