(sourceId = '')
| 682 | } |
| 683 | |
| 684 | async function loadPortalFolderList(sourceId = '') { |
| 685 | const sourceKey = normalizePortalSourceId(sourceId) || getPortalSourceFallbackId(); |
| 686 | if (__portalFolderListLoaded[sourceKey]) return __portalFolderOptions[sourceKey] || []; |
| 687 | try { |
| 688 | const sourceParam = sourceKey ? `&sourceId=${encodeURIComponent(sourceKey)}` : ''; |
| 689 | const res = await fetch(`/api/folder/getFolderList.php?counts=0${sourceParam}`, { credentials: 'include' }); |
| 690 | const data = await res.json(); |
| 691 | let list = data; |
| 692 | |
| 693 | // Support both shapes: ["A/B", "C/D"] or [{ folder: "A/B" }, ...] |
| 694 | if (Array.isArray(list) && list.length && typeof list[0] === 'object' && list[0].folder) { |
| 695 | list = list.map(it => it.folder); |
| 696 | } |
| 697 | |
| 698 | __portalFolderOptions[sourceKey] = (list || []) |
| 699 | .filter(Boolean) |
| 700 | .filter(f => f !== 'trash' && f !== 'profile_pics'); |
| 701 | |
| 702 | __portalFolderListLoaded[sourceKey] = true; |
| 703 | } catch (e) { |
| 704 | console.error('Error loading portal folder list', e); |
| 705 | __portalFolderOptions[sourceKey] = []; |
| 706 | __portalFolderListLoaded[sourceKey] = true; |
| 707 | } |
| 708 | return __portalFolderOptions[sourceKey]; |
| 709 | } |
| 710 | |
| 711 | // ───────────────────────────────────────── |
| 712 | // Public entry point from adminPanel.js |
no test coverage detected