2024-08-19 20:06:38 +02:00
|
|
|
import { apiRoute, applyConfig } from "@/api";
|
2024-09-16 15:29:09 +02:00
|
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
2024-11-19 15:24:15 +01:00
|
|
|
import { Note, User } from "@versia/kit/db";
|
2024-05-29 02:59:49 +02:00
|
|
|
import manifest from "~/package.json";
|
2024-11-19 15:24:15 +01:00
|
|
|
import { config } from "~/packages/config-manager";
|
2023-09-13 07:30:45 +02:00
|
|
|
|
2023-10-16 19:39:41 +02:00
|
|
|
export const meta = applyConfig({
|
2024-04-07 07:30:49 +02:00
|
|
|
auth: {
|
|
|
|
|
required: false,
|
|
|
|
|
},
|
|
|
|
|
ratelimits: {
|
|
|
|
|
duration: 60,
|
|
|
|
|
max: 500,
|
|
|
|
|
},
|
2024-04-26 03:57:57 +02:00
|
|
|
route: "/.well-known/nodeinfo/2.0",
|
2023-10-16 19:39:41 +02:00
|
|
|
});
|
|
|
|
|
|
2024-09-16 15:29:09 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "get",
|
|
|
|
|
path: "/.well-known/nodeinfo/2.0",
|
|
|
|
|
summary: "Well-known nodeinfo 2.0",
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Nodeinfo 2.0",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: 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-08-19 20:06:38 +02:00
|
|
|
export default apiRoute((app) =>
|
2024-11-19 15:24:15 +01:00
|
|
|
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();
|
|
|
|
|
|
2024-08-19 21:03:59 +02:00
|
|
|
return context.json({
|
2024-05-06 09:16:33 +02:00
|
|
|
version: "2.0",
|
2024-08-19 15:16:01 +02:00
|
|
|
software: { name: "versia-server", version: manifest.version },
|
|
|
|
|
protocols: ["versia"],
|
2024-05-06 09:16:33 +02:00
|
|
|
services: { outbound: [], inbound: [] },
|
|
|
|
|
usage: {
|
2024-11-19 15:24:15 +01:00
|
|
|
users: {
|
|
|
|
|
total: userCount,
|
|
|
|
|
activeMonth: userActiveMonth,
|
|
|
|
|
activeHalfyear: userActiveHalfyear,
|
|
|
|
|
},
|
|
|
|
|
localPosts: noteCount,
|
2024-05-06 09:16:33 +02:00
|
|
|
},
|
2024-11-19 15:29:21 +01:00
|
|
|
openRegistrations: config.signups.registration,
|
2024-11-19 15:24:15 +01:00
|
|
|
metadata: {
|
|
|
|
|
nodeName: config.instance.name,
|
|
|
|
|
nodeDescription: config.instance.description,
|
|
|
|
|
},
|
2024-05-06 09:16:33 +02:00
|
|
|
});
|
2024-08-19 20:06:38 +02:00
|
|
|
}),
|
|
|
|
|
);
|