* BFS: starting at `startFolder`, find the first folder the user can view. * - Skips "trash" and "profile_pics" * - Honors server-side "locked" from listChildren, but still double-checks capabilities * - Hard limit to avoid endless walks
(startFolder = 'root')
| 537 | * - Hard limit to avoid endless walks |
| 538 | */ |
| 539 | async function findFirstAccessibleFolder(startFolder = 'root') { |
| 540 | const MAX_VISITS = 3000; |
| 541 | const visited = new Set(); |
| 542 | const q = [startFolder]; |
| 543 | |
| 544 | while (q.length && visited.size < MAX_VISITS) { |
| 545 | const f = q.shift(); |
| 546 | if (!f || visited.has(f)) continue; |
| 547 | visited.add(f); |
| 548 | |
| 549 | // Check viewability |
| 550 | if (await canViewFolder(f)) return f; |
| 551 | |
| 552 | // Enqueue children for BFS |
| 553 | try { |
| 554 | const payload = await fetchChildrenOnce(f); |
| 555 | const items = (payload?.items || []); |
| 556 | for (const it of items) { |
| 557 | const name = (typeof it === 'string') ? it : (it && it.name); |
| 558 | if (!name) continue; |
| 559 | const lower = String(name).toLowerCase(); |
| 560 | if ( |
| 561 | lower === 'trash' || |
| 562 | lower === 'profile_pics' || |
| 563 | lower.startsWith('resumable_') |
| 564 | ) { |
| 565 | continue; |
| 566 | } |
| 567 | const child = (f === 'root') ? name : `${f}/${name}`; |
| 568 | if (!visited.has(child)) q.push(child); |
| 569 | } |
| 570 | // If there are more pages, we only need one page to keep BFS order lightweight |
| 571 | } catch (e) { /* ignore and continue */ } |
| 572 | } |
| 573 | return null; // none found |
| 574 | } |
| 575 | function showNoAccessEmptyState() { |
| 576 | // 1) Hide actions bar |
| 577 | const actions = document.getElementById('fileListActions'); |
no test coverage detected