From e2ad9a94ec7079e3f0c17502cd89b1bbfe9715b2 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Wed, 22 Feb 2023 09:44:47 +0100 Subject: [PATCH] fix mastodon api stats --- .../backend/src/server/api/mastodon/endpoints/meta.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 5fba6f8a6..a19acbaa1 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -1,9 +1,13 @@ import { Entity } from "@calckey/megalodon"; import { fetchMeta } from "@/misc/fetch-meta.js"; +import { Users, Notes } from "@/models/index.js"; +import { IsNull, MoreThan } from "typeorm"; // TODO: add calckey features export async function getInstance(response: Entity.Instance) { const meta = await fetchMeta(true); + const totalUsers = Users.count({ where: { host: IsNull() } }); + const totalStatuses = Notes.count({ where: { userHost: IsNull() } }); return { uri: response.uri, title: response.title || "", @@ -12,7 +16,11 @@ export async function getInstance(response: Entity.Instance) { email: response.email || "", version: "3.0.0 compatible (Calckey)", urls: response.urls, - stats: response.stats, + stats: { + user_count: totalUsers, + status_count: totalStatuses, + domain_count: response.stats.domain_count + }, thumbnail: response.thumbnail || "", languages: meta.langs, registrations: !meta.disableRegistration || response.registrations,