Add nodeinfo support

This commit is contained in:
Shadowfacts 2019-09-17 14:36:54 -04:00
parent 8490156176
commit 38b8c34a05
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 63 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import comments from "./comments";
import federate from "./federate"; import federate from "./federate";
import followers from "./followers"; import followers from "./followers";
import inbox from "./inbox"; import inbox from "./inbox";
import nodeinfo from "./nodeinfo";
import webfinger from "./webfinger"; import webfinger from "./webfinger";
export = { export = {
@ -13,5 +14,6 @@ export = {
federate, federate,
followers, followers,
inbox, inbox,
nodeinfo,
webfinger webfinger
}; };

View File

@ -0,0 +1,59 @@
import {Request, Response, Router} from "express";
import { promises as fs } from "fs";
import {getConnection} from "typeorm";
import Article from "../entity/Article";
import Note from "../entity/Note";
const domain = process.env.DOMAIN;
export default async function nodeinfo(router: Router) {
router.get("/.well-known/nodeinfo", (req, res) => {
res.json({
links: [
{
href: `https://${domain}/nodeinfo/2.0.json`,
rel: "https://nodeinfo.diaspora.software/ns/schema/2.0"
},
{
href: `https://${domain}/nodeinfo/2.1.json`,
rel: "https://nodeinfo.diaspora.software/ns/schema/2.1"
}
]
});
res.end();
});
router.get("/nodeinfo/2.0.json", await handleNodeInfo("2.0"));
router.get("/nodeinfo/2.1.json", await handleNodeInfo("2.1"));
}
async function handleNodeInfo(version: string) {
const softwareVersion = JSON.parse((await fs.readFile("package.json")).toString()).version;
const postCount = await getConnection().getRepository(Article).count();
return async (req: Request, res: Response) => {
res.json({
version: version,
software: {
name: "shadowfacts_blog",
version: softwareVersion,
repository: version === "2.1" ? "https://git.shadowfacts.net/shadowfacts/shadowfacts.net" : undefined
},
protocols: ["activitypub"],
services: {
inbound: [],
outbound: ["atom1.0"]
},
openRegistrations: false,
usage: {
users: {
total: 1,
activeHalfyear: 1,
activeMonth: 1
},
localPosts: postCount,
localComments: await getConnection().getRepository(Note).count()
}
});
res.end();
};
}

View File

@ -68,6 +68,7 @@ async function generate(): Promise<Page[]> {
activitypub.comments(apRouter); activitypub.comments(apRouter);
activitypub.followers(apRouter); activitypub.followers(apRouter);
activitypub.inbox(apRouter); activitypub.inbox(apRouter);
await activitypub.nodeinfo(apRouter);
activitypub.webfinger(apRouter); activitypub.webfinger(apRouter);
activitypub.articles.route(apRouter); activitypub.articles.route(apRouter);
app.use(apRouter); app.use(apRouter);