MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / retrieveFilteredPlugins

Function retrieveFilteredPlugins

src/pages/plugins/plugins.js:450–542  ·  view source on GitHub ↗
(filterState)

Source from the content-addressed store, hash-verified

448 }
449
450 async function retrieveFilteredPlugins(filterState) {
451 if (!filterState) return { items: [], hasMore: false };
452
453 if (filterState.type === "orderBy") {
454 const page = filterState.nextPage || 1;
455 try {
456 let response;
457 if (filterState.value === "top_rated") {
458 response = await fetch(
459 withSupportedEditor(
460 `${config.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
461 ),
462 );
463 } else {
464 response = await fetch(
465 withSupportedEditor(
466 `${config.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
467 ),
468 );
469 }
470 const items = await response.json();
471 if (!Array.isArray(items)) {
472 return { items: [], hasMore: false };
473 }
474 filterState.nextPage = page + 1;
475 const hasMoreResults = items.length === LIMIT;
476 return { items, hasMore: hasMoreResults };
477 } catch (error) {
478 console.error("Failed to fetch ordered plugins:", error);
479 return { items: [], hasMore: false };
480 }
481 }
482
483 if (!Array.isArray(filterState.buffer)) {
484 filterState.buffer = [];
485 }
486 if (filterState.hasMoreSource === undefined) {
487 filterState.hasMoreSource = true;
488 }
489 if (!filterState.nextPage) {
490 filterState.nextPage = 1;
491 }
492
493 const items = [];
494
495 while (items.length < LIMIT) {
496 if (filterState.buffer.length) {
497 items.push(filterState.buffer.shift());
498 continue;
499 }
500
501 if (filterState.hasMoreSource === false) break;
502
503 try {
504 const page = filterState.nextPage;
505 const response = await fetch(
506 withSupportedEditor(
507 `${config.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,

Callers 1

getFilteredPluginsFunction · 0.85

Calls 3

matchesFilterFunction · 0.85
withSupportedEditorFunction · 0.50
errorMethod · 0.45

Tested by

no test coverage detected