(force = false, sourceId = "")
| 203 | let __allFoldersCache = new Map(); |
| 204 | |
| 205 | async function getAllFolders(force = false, sourceId = "") { |
| 206 | const key = sourceId || getFolderAccessSourceId() || ''; |
| 207 | if (!force && __allFoldersCache.has(key)) return __allFoldersCache.get(key).slice(); |
| 208 | |
| 209 | const url = '/api/folder/getFolderList.php?counts=0&ts=' + Date.now() |
| 210 | + (key ? `&sourceId=${encodeURIComponent(key)}` : ''); |
| 211 | const res = await fetch(url, { |
| 212 | credentials: 'include', |
| 213 | cache: 'no-store', |
| 214 | headers: { 'Cache-Control': 'no-store' } |
| 215 | }); |
| 216 | const data = await safeJson(res).catch(() => []); |
| 217 | const list = Array.isArray(data) |
| 218 | ? data.map(x => (typeof x === 'string' ? x : x.folder)).filter(Boolean) |
| 219 | : []; |
| 220 | |
| 221 | const hidden = new Set(['profile_pics', 'trash']); |
| 222 | const cleaned = list |
| 223 | .filter(f => f && !hidden.has(f.toLowerCase())) |
| 224 | .sort((a, b) => (a === 'root' ? -1 : b === 'root' ? 1 : a.localeCompare(b))); |
| 225 | |
| 226 | __allFoldersCache.set(key, cleaned); |
| 227 | return cleaned.slice(); |
| 228 | } |
| 229 | |
| 230 | async function getUserGrants(username, sourceId = "") { |
| 231 | const key = sourceId || getFolderAccessSourceId() || ''; |
no test coverage detected