37 lines
950 B
TypeScript
37 lines
950 B
TypeScript
import { RouteOptions } from "fastify";
|
|
import { IsNull } from "typeorm";
|
|
|
|
import MercuryDataSource from "~/db/index.js";
|
|
import { Blog } from "~/db/entities/blog.js";
|
|
import { Post } from "~/db/entities/post.js";
|
|
|
|
const route: RouteOptions = {
|
|
method: "GET",
|
|
url: "/nodeinfo/2.0",
|
|
handler: async (_, res) => {
|
|
const [userCount, postCount] = await Promise.all([
|
|
MercuryDataSource.getRepository(Blog).countBy({
|
|
host: IsNull(),
|
|
}),
|
|
MercuryDataSource.getRepository(Post).count({
|
|
relations: { blog: true },
|
|
where: { blog: { host: IsNull() } },
|
|
}),
|
|
]);
|
|
|
|
res.send({
|
|
version: "2.0",
|
|
software: { name: "mercury", version: "0.1.0-dev" },
|
|
protocols: ["activitypub"],
|
|
openRegistrations: false, // TODO: get from database
|
|
usage: {
|
|
users: {
|
|
total: userCount,
|
|
},
|
|
localPosts: postCount,
|
|
},
|
|
});
|
|
},
|
|
};
|
|
|
|
export default route;
|