({ lastOpenedFolder, sourceId = '' } = {})
| 4413 | } |
| 4414 | |
| 4415 | async function findBestAccessibleFolder({ lastOpenedFolder, sourceId = '' } = {}) { |
| 4416 | try { |
| 4417 | const sourceParam = sourceId ? `&sourceId=${encodeURIComponent(sourceId)}` : ''; |
| 4418 | const res = await fetch(withBase(`/api/folder/getFolderList.php?counts=0${sourceParam}`), { credentials: 'include' }); |
| 4419 | const data = await safeJson(res); |
| 4420 | const names = Array.isArray(data) |
| 4421 | ? data.map(row => normalizeFolderPath(row?.folder || row)).filter(Boolean) |
| 4422 | : []; |
| 4423 | if (!names.length) return null; |
| 4424 | |
| 4425 | const unique = Array.from(new Set(names)); |
| 4426 | const preferred = normalizeFolderPath(lastOpenedFolder); |
| 4427 | if (preferred && unique.includes(preferred)) return preferred; |
| 4428 | |
| 4429 | unique.sort((a, b) => { |
| 4430 | const depthDiff = folderDepthScore(a) - folderDepthScore(b); |
| 4431 | return depthDiff !== 0 ? depthDiff : a.localeCompare(b); |
| 4432 | }); |
| 4433 | return unique[0] || null; |
| 4434 | } catch (e) { |
| 4435 | return null; |
| 4436 | } |
| 4437 | } |
| 4438 | |
| 4439 | // --- Folder capabilities + owner cache ---------------------- |
| 4440 | const _folderCapsCache = window.__FR_CAPS_CACHE || new Map(); |
no test coverage detected