2025-06-15 04:38:20 +02:00
|
|
|
import { config } from "@versia-server/config";
|
2025-06-15 23:50:34 +02:00
|
|
|
import { apiRoute } from "@versia-server/kit/api";
|
|
|
|
|
import { Note, User } from "@versia-server/kit/db";
|
2025-07-07 03:42:35 +02:00
|
|
|
import { describeRoute, resolver } from "hono-openapi";
|
|
|
|
|
import { z } from "zod/v4";
|
2025-06-29 22:56:52 +02:00
|
|
|
import manifest from "../../../../../../package.json" with { type: "json" };
|
2023-09-13 07:30:45 +02:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.get(
|
|
|
|
|
"/.well-known/nodeinfo/2.0",
|
|
|
|
|
describeRoute({
|
|
|
|
|
summary: "Well-known nodeinfo 2.0",
|
|
|
|
|
tags: ["Federation"],
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Nodeinfo 2.0",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: resolver(
|
|
|
|
|
z.object({
|
|
|
|
|
version: z.string(),
|
|
|
|
|
software: z.object({
|
|
|
|
|
name: z.string(),
|
|
|
|
|
version: z.string(),
|
|
|
|
|
}),
|
|
|
|
|
protocols: z.array(z.string()),
|
|
|
|
|
services: z.object({
|
|
|
|
|
outbound: z.array(z.string()),
|
|
|
|
|
inbound: z.array(z.string()),
|
|
|
|
|
}),
|
|
|
|
|
usage: z.object({
|
|
|
|
|
users: z.object({
|
|
|
|
|
total: z.number(),
|
|
|
|
|
activeMonth: z.number(),
|
|
|
|
|
activeHalfyear: z.number(),
|
|
|
|
|
}),
|
|
|
|
|
localPosts: z.number(),
|
|
|
|
|
}),
|
|
|
|
|
openRegistrations: z.boolean(),
|
|
|
|
|
metadata: z.object({}),
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-09-16 15:29:09 +02:00
|
|
|
},
|
|
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
}),
|
|
|
|
|
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();
|
2024-11-19 15:24:15 +01:00
|
|
|
|
2025-03-29 03:30:06 +01:00
|
|
|
return context.json({
|
|
|
|
|
version: "2.0",
|
|
|
|
|
software: { name: "versia-server", version: manifest.version },
|
|
|
|
|
protocols: ["versia"],
|
|
|
|
|
services: { outbound: [], inbound: [] },
|
|
|
|
|
usage: {
|
|
|
|
|
users: {
|
|
|
|
|
total: userCount,
|
|
|
|
|
activeMonth: userActiveMonth,
|
|
|
|
|
activeHalfyear: userActiveHalfyear,
|
|
|
|
|
},
|
|
|
|
|
localPosts: noteCount,
|
2024-11-19 15:24:15 +01:00
|
|
|
},
|
2025-03-29 03:30:06 +01:00
|
|
|
openRegistrations: config.registration.allow,
|
|
|
|
|
metadata: {
|
|
|
|
|
nodeName: config.instance.name,
|
|
|
|
|
nodeDescription: config.instance.description,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|