mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
feat(federation): ✨ Implement user statistics and node data in nodeinfo
This commit is contained in:
parent
1837a6feb4
commit
055ee417cb
|
|
@ -1,6 +1,8 @@
|
||||||
import { apiRoute, applyConfig } from "@/api";
|
import { apiRoute, applyConfig } from "@/api";
|
||||||
import { createRoute, z } from "@hono/zod-openapi";
|
import { createRoute, z } from "@hono/zod-openapi";
|
||||||
|
import { Note, User } from "@versia/kit/db";
|
||||||
import manifest from "~/package.json";
|
import manifest from "~/package.json";
|
||||||
|
import { config } from "~/packages/config-manager";
|
||||||
|
|
||||||
export const meta = applyConfig({
|
export const meta = applyConfig({
|
||||||
auth: {
|
auth: {
|
||||||
|
|
@ -51,18 +53,34 @@ const route = createRoute({
|
||||||
});
|
});
|
||||||
|
|
||||||
export default apiRoute((app) =>
|
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({
|
return context.json({
|
||||||
version: "2.0",
|
version: "2.0",
|
||||||
software: { name: "versia-server", version: manifest.version },
|
software: { name: "versia-server", version: manifest.version },
|
||||||
protocols: ["versia"],
|
protocols: ["versia"],
|
||||||
services: { outbound: [], inbound: [] },
|
services: { outbound: [], inbound: [] },
|
||||||
usage: {
|
usage: {
|
||||||
users: { total: 0, activeMonth: 0, activeHalfyear: 0 },
|
users: {
|
||||||
localPosts: 0,
|
total: userCount,
|
||||||
|
activeMonth: userActiveMonth,
|
||||||
|
activeHalfyear: userActiveHalfyear,
|
||||||
|
},
|
||||||
|
localPosts: noteCount,
|
||||||
},
|
},
|
||||||
openRegistrations: false,
|
openRegistrations: false,
|
||||||
metadata: {},
|
metadata: {
|
||||||
|
nodeName: config.instance.name,
|
||||||
|
nodeDescription: config.instance.description,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue