MCPcopy Create free account
hub / github.com/error311/FileRise / fetchOne

Function fetchOne

public/js/fileListView.js:5504–5534  ·  view source on GitHub ↗
(src)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 5

withBaseFunction · 0.85
updateStatusFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected