|
1334 | 1334 | parts.length = 0; |
1335 | 1335 | }; |
1336 | 1336 |
|
1337 | | - const loadFiles = async list => { |
1338 | | - try { |
1339 | | - // Clear previous memory before loading new files |
1340 | | - clearMemory(); |
1341 | | - |
1342 | | - load(true, `Loading ${list.length} files...`); |
1343 | | - // Fast path: convert FileList to Array |
1344 | | - const all = Array.from(list); |
1345 | | - load(true, 'Filtering files...'); |
1346 | | - await new Promise(r => setTimeout(r, 0)); |
1347 | | - // Filter files - CRITICAL: Ensure all ignored files are removed here |
1348 | | - S.files = all.filter(f => !ign(f.webkitRelativePath)) |
1349 | | - .map(f => ({ |
1350 | | - path: f.webkitRelativePath, |
1351 | | - name: f.name, |
1352 | | - size: f.size, |
1353 | | - file: f |
1354 | | - })); |
1355 | | - // Auto-detect absolute base path when running in desktop/Electron environments |
1356 | | - // where File objects may expose a non-standard `path` property. |
1357 | | - if (!S.basePathSet) { |
1358 | | - const cand = S.files.find(ff => ff.file && ff.file.path); |
1359 | | - if (cand && cand.file && cand.file.path) { |
1360 | | - try { |
1361 | | - const full = String(cand.file.path); |
1362 | | - const rel = String(cand.path); |
1363 | | - const sep = full.indexOf('\\') !== -1 ? '\\' : '/'; |
1364 | | - const relConv = rel.split('/').join(sep); |
1365 | | - let base = ''; |
1366 | | - if (full.endsWith(relConv)) { |
1367 | | - base = full.slice(0, full.length - relConv.length); |
1368 | | - base = base.replace(/[\\/]+$/, ''); |
1369 | | - } else { |
1370 | | - const idx = full.indexOf(relConv); |
1371 | | - if (idx !== -1) base = full.slice(0, idx).replace(/[\\/]+$/, ''); |
1372 | | - } |
1373 | | - if (base) { |
1374 | | - S.basePath = base; |
1375 | | - S.basePathSet = true; |
1376 | | - console.info('Auto-detected base path:', base); |
1377 | | - } |
1378 | | - } catch (e) { |
1379 | | - // ignore; leave base path unset |
1380 | | - } |
1381 | | - } |
1382 | | - } |
1383 | | - if (S.files.length === 0) { toast('No valid files', 'warning'); load(false); return; } |
1384 | | - if (S.files.length > 5000) { toast(`Large directory (${S.files.length} files) - rendering first 1000`, 'warning'); } |
1385 | | - load(true, 'Building file tree...'); |
1386 | | - S.root = S.files[0].path.split('/')[0]; |
1387 | | - // Let UI update before building tree |
1388 | | - await new Promise(r => setTimeout(r, 0)); |
1389 | | - S.tree = build(S.files.slice(0, 3000)); // Limit tree size, but build from fully filtered list |
1390 | | - load(true, 'Rendering tree...'); |
1391 | | - await new Promise(r => setTimeout(r, 0)); |
1392 | | - // Render tree |
1393 | | - const items = render(S.tree); |
1394 | | - D.tree.innerHTML = items.map(x => x.html).join(''); |
1395 | | - S.rendered = items.length; |
1396 | | - stats(); |
1397 | | - toast(`Loaded ${S.files.length} files`, 'success'); |
1398 | | - } catch (e) { |
1399 | | - console.error('Load error:', e); |
1400 | | - toast('Load failed', 'error'); |
1401 | | - } finally { |
1402 | | - load(false); |
1403 | | - } |
1404 | | - }; |
1405 | | - // (removed orphaned code) |
1406 | | - |
1407 | 1337 | const genStruct = (nodes, pfx = '') => { |
1408 | 1338 | let r = ''; |
1409 | 1339 | nodes.forEach((nd, i) => { |
|
1563 | 1493 | }; |
1564 | 1494 | if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); |
1565 | 1495 | else init(); |
1566 | | -}})(); |
| 1496 | +})(); |
0 commit comments