fix mastodon api stats

This commit is contained in:
CutestNekoAqua 2023-02-22 09:44:47 +01:00
parent 4c0ae44e74
commit 684f2e883a

View file

@ -1,9 +1,13 @@
import { Entity } from "@calckey/megalodon"; import { Entity } from "@calckey/megalodon";
import { fetchMeta } from "@/misc/fetch-meta.js"; import { fetchMeta } from "@/misc/fetch-meta.js";
import { Users, Notes } from "@/models/index.js";
import { IsNull, MoreThan } from "typeorm";
// TODO: add calckey features // TODO: add calckey features
export async function getInstance(response: Entity.Instance) { export async function getInstance(response: Entity.Instance) {
const meta = await fetchMeta(true); const meta = await fetchMeta(true);
const totalUsers = Users.count({ where: { host: IsNull() } });
const totalStatuses = Notes.count({ where: { userHost: IsNull() } });
return { return {
uri: response.uri, uri: response.uri,
title: response.title || "", title: response.title || "",
@ -12,7 +16,11 @@ export async function getInstance(response: Entity.Instance) {
email: response.email || "", email: response.email || "",
version: "3.0.0 compatible (Calckey)", version: "3.0.0 compatible (Calckey)",
urls: response.urls, urls: response.urls,
stats: response.stats, stats: {
user_count: totalUsers,
status_count: totalStatuses,
domain_count: response.stats.domain_count
},
thumbnail: response.thumbnail || "", thumbnail: response.thumbnail || "",
languages: meta.langs, languages: meta.langs,
registrations: !meta.disableRegistration || response.registrations, registrations: !meta.disableRegistration || response.registrations,