[AkkomaAPI] Add endpoint /nodeinfo/2.0.json

This commit is contained in:
April John 2023-09-04 17:55:17 +02:00
parent e17691df43
commit f967da4dda
2 changed files with 19 additions and 2 deletions

View File

@ -24,7 +24,7 @@ import * as Acct from "@/misc/acct.js";
import { envOption } from "@/env.js"; import { envOption } from "@/env.js";
import megalodon, { MegalodonInterface } from "megalodon"; import megalodon, { MegalodonInterface } from "megalodon";
import activityPub from "./activitypub.js"; import activityPub from "./activitypub.js";
import nodeinfo from "./nodeinfo.js"; import nodeinfo, { nodeinfo2 } from "./nodeinfo.js";
import wellKnown from "./well-known.js"; import wellKnown from "./well-known.js";
import apiServer from "./api/index.js"; import apiServer from "./api/index.js";
import fileServer from "./file/index.js"; import fileServer from "./file/index.js";
@ -34,6 +34,7 @@ import { initializeStreamingServer } from "./api/streaming.js";
import { koaBody } from "koa-body"; import { koaBody } from "koa-body";
import removeTrailingSlash from "koa-remove-trailing-slashes"; import removeTrailingSlash from "koa-remove-trailing-slashes";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import { Cache } from "@/misc/cache.js";
export const serverLogger = new Logger("server", "gray", false); export const serverLogger = new Logger("server", "gray", false);
@ -149,6 +150,22 @@ mastoRouter.get("/oauth/authorize", async (ctx) => {
); );
}); });
const cache = new Cache<Awaited<ReturnType<typeof nodeinfo2>>>(
"nodeinfo",
60 * 10,
);
mastoRouter.get("/nodeinfo/2.0.json", async (ctx) => {
const base = await cache.fetch(null, () => nodeinfo2());
// @ts-ignore
base.software.repository = undefined;
ctx.body = { version: "2.0", ...base };
ctx.set("Cache-Control", "public, max-age=600");
});
mastoRouter.post("/oauth/token", async (ctx) => { mastoRouter.post("/oauth/token", async (ctx) => {
const body: any = ctx.request.body || ctx.request.query; const body: any = ctx.request.body || ctx.request.query;
console.log("token-request", body); console.log("token-request", body);

View File

@ -23,7 +23,7 @@ export const links = [
}, },
]; ];
const nodeinfo2 = async () => { export const nodeinfo2 = async () => {
const now = Date.now(); const now = Date.now();
const [meta, total, activeHalfyear, activeMonth, localPosts] = const [meta, total, activeHalfyear, activeMonth, localPosts] =
await Promise.all([ await Promise.all([