From 256aa8fbd0476463bde9f29793cf69b907ddb40c Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Sat, 26 Aug 2023 17:03:14 +0200 Subject: [PATCH] Improve /api/instances --- src/pages/api/instances.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pages/api/instances.ts b/src/pages/api/instances.ts index eae843b..3fd07c4 100644 --- a/src/pages/api/instances.ts +++ b/src/pages/api/instances.ts @@ -10,7 +10,7 @@ interface ProjectInstance { domain: string; score: number; active_users_monthly: number; - status: number; + total_users: number; } const PROJECTS = Object.values(FediverseProject); @@ -25,13 +25,17 @@ export const fetchInstances = async ( "Content-Type": "application/json", }, referrer: "https://api.fediverse.observer/", - body: `{"query":"{\\n nodes(softwarename: \\"${projectId}\\") {\\n domain\\n score\\n active_users_monthly\\n status\\n }\\n}\\n"}`, + body: JSON.stringify({ + query: `{nodes(status:"UP",softwarename:"${projectId}"){domain score active_users_monthly total_users}}`, + }), method: "POST", }); const json = await response.json(); const instances: ProjectInstance[] = json.data.nodes; return instances.filter( - (instance) => instance.score > 0 && instance.status === 1, + (instance) => + instance.score > 90 && + instance.total_users >= instance.active_users_monthly, ); };