(src)
| 5502 | updateStatus(); |
| 5503 | |
| 5504 | const fetchOne = async (src) => { |
| 5505 | const sourceParam = `&sourceId=${encodeURIComponent(src.id)}`; |
| 5506 | try { |
| 5507 | const res = await fetch(withBase(`/api/pro/search/query.php?q=${encodeURIComponent(term)}&limit=${perSourceLimit}${sourceParam}`), { |
| 5508 | credentials: 'include', |
| 5509 | }); |
| 5510 | const data = await res.json(); |
| 5511 | if (!res.ok || !data.ok) { |
| 5512 | throw new Error(data.error || `HTTP ${res.status}`); |
| 5513 | } |
| 5514 | if (runId !== searchEverywhereRunId) return; |
| 5515 | statusById[src.id] = 'done'; |
| 5516 | if (data.reindexed) reindexedSources.add(src.id); |
| 5517 | const items = Array.isArray(data.items) ? data.items : []; |
| 5518 | items.forEach((item) => { |
| 5519 | const sourceKey = String(item?.sourceId || src.id || ''); |
| 5520 | const pathKey = String(item?.path || item?.folder || item?.name || ''); |
| 5521 | const key = `${sourceKey}::${pathKey}`; |
| 5522 | if (!item?.sourceId) item.sourceId = sourceKey; |
| 5523 | resultsMap.set(key, item); |
| 5524 | }); |
| 5525 | const sorted = sortSearchEverywhereItems(Array.from(resultsMap.values())); |
| 5526 | renderSearchEverywhereResults(sorted.slice(0, limit)); |
| 5527 | } catch (e) { |
| 5528 | if (runId !== searchEverywhereRunId) return; |
| 5529 | statusById[src.id] = 'error'; |
| 5530 | } finally { |
| 5531 | if (runId !== searchEverywhereRunId) return; |
| 5532 | updateStatus(); |
| 5533 | } |
| 5534 | }; |
| 5535 | |
| 5536 | await Promise.allSettled(uniqSources.map(src => fetchOne(src))); |
| 5537 |
no test coverage detected