From 8a088b8d74c0ac5b9244ccb852d78c9e73274dfb Mon Sep 17 00:00:00 2001 From: April John Date: Mon, 4 Sep 2023 18:10:54 +0200 Subject: [PATCH] [AkkomaFE] Ship Mastodon instance with nodeinfo --- packages/backend/src/server/index.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index 593bf2aba..251830823 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -35,6 +35,9 @@ import { koaBody } from "koa-body"; import removeTrailingSlash from "koa-remove-trailing-slashes"; import { v4 as uuid } from "uuid"; import { Cache } from "@/misc/cache.js"; +import { getInstance } from "./api/mastodon/endpoints/meta.js"; +import { convertAccount } from "./api/mastodon/converters.js"; +import { getClient } from "./api/mastodon/ApiMastodonCompatibleService.js"; export const serverLogger = new Logger("server", "gray", false); @@ -158,11 +161,29 @@ const cache = new Cache>>( mastoRouter.get("/nodeinfo/2.0.json", async (ctx) => { const base = await cache.fetch(null, () => nodeinfo2()); + const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; + const accessTokens = ctx.request.headers.authorization; + const client = getClient(BASE_URL, accessTokens); + const data = await client.getInstance(); + const admin = await Users.findOne({ + where: { + host: IsNull(), + isAdmin: true, + isDeleted: false, + isSuspended: false, + }, + order: { id: "ASC" }, + }); + const contact = + admin == null + ? null + : convertAccount((await client.getAccount(admin.id)).data); + const masto = { ...getInstance(data.data, contact), ...base }; // @ts-ignore base.software.repository = undefined; - ctx.body = { version: "2.0", ...base }; + ctx.body = { version: "2.0", ...masto }; ctx.set("Cache-Control", "public, max-age=600"); });