Improve /api/instances

This commit is contained in:
Nikita Karamov 2023-08-26 17:03:14 +02:00
parent 08c71218b2
commit 256aa8fbd0
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD

View file

@ -10,7 +10,7 @@ interface ProjectInstance {
domain: string; domain: string;
score: number; score: number;
active_users_monthly: number; active_users_monthly: number;
status: number; total_users: number;
} }
const PROJECTS = Object.values(FediverseProject); const PROJECTS = Object.values(FediverseProject);
@ -25,13 +25,17 @@ export const fetchInstances = async (
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
referrer: "https://api.fediverse.observer/", 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", method: "POST",
}); });
const json = await response.json(); const json = await response.json();
const instances: ProjectInstance[] = json.data.nodes; const instances: ProjectInstance[] = json.data.nodes;
return instances.filter( return instances.filter(
(instance) => instance.score > 0 && instance.status === 1, (instance) =>
instance.score > 90 &&
instance.total_users >= instance.active_users_monthly,
); );
}; };