From 055ee417cbb0ed1fb9364a5d9ededc0b92636ae1 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 19 Nov 2024 15:24:15 +0100 Subject: [PATCH] feat(federation): :sparkles: Implement user statistics and node data in nodeinfo --- api/well-known/nodeinfo/2.0/index.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/api/well-known/nodeinfo/2.0/index.ts b/api/well-known/nodeinfo/2.0/index.ts index 5d231bb7..55a94fd5 100644 --- a/api/well-known/nodeinfo/2.0/index.ts +++ b/api/well-known/nodeinfo/2.0/index.ts @@ -1,6 +1,8 @@ import { apiRoute, applyConfig } from "@/api"; import { createRoute, z } from "@hono/zod-openapi"; +import { Note, User } from "@versia/kit/db"; import manifest from "~/package.json"; +import { config } from "~/packages/config-manager"; export const meta = applyConfig({ auth: { @@ -51,18 +53,34 @@ const route = createRoute({ }); export default apiRoute((app) => - app.openapi(route, (context) => { + app.openapi(route, async (context) => { + const userCount = await User.getCount(); + const userActiveMonth = await User.getActiveInPeriod( + 1000 * 60 * 60 * 24 * 30, + ); + const userActiveHalfyear = await User.getActiveInPeriod( + 1000 * 60 * 60 * 24 * 30 * 6, + ); + const noteCount = await Note.getCount(); + return context.json({ version: "2.0", software: { name: "versia-server", version: manifest.version }, protocols: ["versia"], services: { outbound: [], inbound: [] }, usage: { - users: { total: 0, activeMonth: 0, activeHalfyear: 0 }, - localPosts: 0, + users: { + total: userCount, + activeMonth: userActiveMonth, + activeHalfyear: userActiveHalfyear, + }, + localPosts: noteCount, }, openRegistrations: false, - metadata: {}, + metadata: { + nodeName: config.instance.name, + nodeDescription: config.instance.description, + }, }); }), );