backend: refactor server/nodeinfo.ts
Some checks failed
ci/woodpecker/pr/lint-client Pipeline failed
ci/woodpecker/pr/test Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/lint-foundkey-js Pipeline was successful
ci/woodpecker/pr/lint-backend Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful

This fixes a few type errors like removing `software.respository` in
NodeInfo 2.0 and updating `metadata.repositoryUrl` to not use the
now removed meta `repositoryUrl` field.
This commit is contained in:
Norm 2022-10-31 18:54:02 -04:00
parent 0db0db9a87
commit 52ad5049de
Signed by: norm
GPG key ID: 7123E30E441E80DE

View file

@ -18,7 +18,33 @@ export const links = [{
href: config.url + nodeinfo2_0path,
}];
const nodeinfo2 = async () => {
const repository = 'https://akkoma.dev/FoundKeyGang/FoundKey';
type NodeInfo2Base = {
software: {
name: string;
version: string;
repository?: string; // Not used in NodeInfo 2.0; used in 2.1
};
protocols: string[];
services: {
inbound: string[];
outbound: string[];
};
openRegistrations: boolean;
usage: {
users: {
total: number;
activeHalfyear: number;
activeMonth: number;
};
localPosts: number;
localComments: number;
};
metadata: Record<string, any>;
};
const nodeinfo2 = async (): Promise<NodeInfo2Base> => {
const now = Date.now();
const [
meta,
@ -40,7 +66,7 @@ const nodeinfo2 = async () => {
software: {
name: 'foundkey',
version: config.version,
repository: 'https://akkoma.dev/FoundKeyGang/FoundKey',
repository,
},
protocols: ['activitypub'],
services: {
@ -62,7 +88,7 @@ const nodeinfo2 = async () => {
},
langs: meta.langs,
tosUrl: meta.ToSUrl,
repositoryUrl: meta.repositoryUrl,
repositoryUrl: repository,
feedbackUrl: 'ircs://irc.akkoma.dev/foundkey',
disableRegistration: meta.disableRegistration,
disableLocalTimeline: meta.disableLocalTimeline,
@ -82,7 +108,7 @@ const nodeinfo2 = async () => {
};
};
const cache = new Cache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);
const cache = new Cache<NodeInfo2Base>(1000 * 60 * 10);
router.get(nodeinfo2_1path, async ctx => {
const base = await cache.fetch(null, () => nodeinfo2());