()
| 3841 | }; |
| 3842 | |
| 3843 | const loadSourceOptions = async () => { |
| 3844 | try { |
| 3845 | const res = await fetch(withBase('/api/pro/sources/list.php'), { |
| 3846 | method: 'GET', |
| 3847 | credentials: 'include', |
| 3848 | headers: { 'Accept': 'application/json' }, |
| 3849 | }); |
| 3850 | const data = await safeJson(res); |
| 3851 | if (!data || data.ok !== true) { |
| 3852 | throw new Error(data?.error || 'Failed to load sources.'); |
| 3853 | } |
| 3854 | |
| 3855 | const sources = Array.isArray(data.sources) ? data.sources : []; |
| 3856 | const options = []; |
| 3857 | sources.forEach((src) => { |
| 3858 | const id = String(src?.id || '').trim(); |
| 3859 | if (!id) return; |
| 3860 | const name = String(src?.name || id).trim() || id; |
| 3861 | const type = String(src?.type || '').trim(); |
| 3862 | const enabled = src?.enabled !== false; |
| 3863 | const status = enabled ? '' : ` (${tf('disabled', 'Disabled')})`; |
| 3864 | const typePart = type ? ` [${type}]` : ''; |
| 3865 | options.push({ id, label: `${id} - ${name}${typePart}${status}` }); |
| 3866 | }); |
| 3867 | if (!options.some((s) => s.id === 'local')) { |
| 3868 | options.unshift({ id: 'local', label: 'local - Local' }); |
| 3869 | } |
| 3870 | state.sourceOptions = options; |
| 3871 | renderSourceOptions(sourceIdEl?.value || 'local'); |
| 3872 | } catch (err) { |
| 3873 | state.sourceOptions = [{ id: 'local', label: 'local - Local' }]; |
| 3874 | renderSourceOptions(sourceIdEl?.value || 'local'); |
| 3875 | } |
| 3876 | }; |
| 3877 | |
| 3878 | const setType = (type) => { |
| 3879 | const t = String(type || 'sftp').toLowerCase(); |
no test coverage detected