MCPcopy Create free account
hub / github.com/error311/FileRise / findFirstAccessibleFolder

Function findFirstAccessibleFolder

public/js/folderManager.js:539–574  ·  view source on GitHub ↗

* 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')

Source from the content-addressed store, hash-verified

537 * - Hard limit to avoid endless walks
538 */
539async 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}
575function showNoAccessEmptyState() {
576 // 1) Hide actions bar
577 const actions = document.getElementById('fileListActions');

Callers 1

chooseInitialFolderFunction · 0.85

Calls 2

canViewFolderFunction · 0.85
fetchChildrenOnceFunction · 0.85

Tested by

no test coverage detected