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

Function getFilteredPlugins

src/sidebarApps/extensions/index.js:536–629  ·  view source on GitHub ↗
(filterState)

Source from the content-addressed store, hash-verified

534}
535
536async function getFilteredPlugins(filterState) {
537 if (!filterState) return { items: [], hasMore: false };
538
539 if (filterState.type === "orderBy") {
540 const page = filterState.nextPage || 1;
541 try {
542 let response;
543 if (filterState.value === "top_rated") {
544 response = await fetch(
545 withSupportedEditor(
546 `${config.API_BASE}/plugins?explore=random&page=${page}&limit=${LIMIT}`,
547 ),
548 );
549 } else {
550 response = await fetch(
551 withSupportedEditor(
552 `${config.API_BASE}/plugin?orderBy=${filterState.value}&page=${page}&limit=${LIMIT}`,
553 ),
554 );
555 }
556 const items = await response.json();
557 if (!Array.isArray(items)) {
558 return { items: [], hasMore: false };
559 }
560 filterState.nextPage = page + 1;
561 const hasMore = items.length === LIMIT;
562 return { items, hasMore };
563 } catch (error) {
564 console.error(`Failed to get Filtered Plugins: `, error);
565 return { items: [], hasMore: false };
566 }
567 }
568
569 if (!Array.isArray(filterState.buffer)) {
570 filterState.buffer = [];
571 }
572 if (filterState.hasMoreSource === undefined) {
573 filterState.hasMoreSource = true;
574 }
575 if (!filterState.nextPage) {
576 filterState.nextPage = 1;
577 }
578
579 const items = [];
580
581 while (items.length < LIMIT) {
582 if (filterState.buffer.length) {
583 items.push(filterState.buffer.shift());
584 continue;
585 }
586
587 if (filterState.hasMoreSource === false) break;
588
589 try {
590 const page = filterState.nextPage;
591 const response = await fetch(
592 withSupportedEditor(
593 `${config.API_BASE}/plugins?page=${page}&limit=${LIMIT}`,

Callers 1

loadFilteredPluginsFunction · 0.70

Calls 4

doesPluginMatchFilterFunction · 0.85
logMethod · 0.80
withSupportedEditorFunction · 0.70
errorMethod · 0.45

Tested by

no test coverage detected