Skip to content

Commit

Permalink
feat: nodeinfo 2.1 (#11805)
Browse files Browse the repository at this point in the history
* feat: enable nodeinfo 2.1

Since 9dd06a7, nodeinfo 2.1 has been released.

Signed-off-by: xtex <[email protected]>

* feat: only add software.repository to nodeinfo 2.1

jhass/nodeinfo@e54c48e
Signed-off-by: xtex <[email protected]>

* feat: add software.homepage url to nodeinfo 2.1

jhass/nodeinfo@507822c
Signed-off-by: xtex <[email protected]>

* fix: set proper Content-Type for nodeinfo

Signed-off-by: xtex <[email protected]>

* style: fix lint warnings

Signed-off-by: xtex <[email protected]>

---------

Signed-off-by: xtex <[email protected]>
  • Loading branch information
xtexChooser authored Sep 10, 2023
1 parent 8749716 commit 054ba3f
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions packages/backend/src/server/NodeinfoServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ export class NodeinfoServerService {

@bindThis
public getLinks() {
return [/* (awaiting release) {
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
href: config.url + nodeinfo2_1path
}, */{
return [{
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
href: this.config.url + nodeinfo2_1path
}, {
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
href: this.config.url + nodeinfo2_0path,
}];
}

@bindThis
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) {
const nodeinfo2 = async () => {
const nodeinfo2 = async (version: number) => {
const now = Date.now();

const notesChart = await this.notesChart.getChart('hour', 1, null);
Expand All @@ -73,11 +73,11 @@ export class NodeinfoServerService {

const basePolicies = { ...DEFAULT_POLICIES, ...meta.policies };

return {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const document: any = {
software: {
name: 'misskey',
version: this.config.version,
repository: meta.repositoryUrl,
},
protocols: ['activitypub'],
services: {
Expand Down Expand Up @@ -114,23 +114,36 @@ export class NodeinfoServerService {
themeColor: meta.themeColor ?? '#86b300',
},
};
if (version >= 21) {
document.software.repository = meta.repositoryUrl;
document.software.homepage = meta.repositoryUrl;
}
return document;
};

const cache = new MemorySingleCache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);

fastify.get(nodeinfo2_1path, async (request, reply) => {
const base = await cache.fetch(() => nodeinfo2());
const base = await cache.fetch(() => nodeinfo2(21));

reply.header('Cache-Control', 'public, max-age=600');
reply
.type(
'application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"',
)
.header('Cache-Control', 'public, max-age=600');
return { version: '2.1', ...base };
});

fastify.get(nodeinfo2_0path, async (request, reply) => {
const base = await cache.fetch(() => nodeinfo2());
const base = await cache.fetch(() => nodeinfo2(20));

delete (base as any).software.repository;

reply.header('Cache-Control', 'public, max-age=600');
reply
.type(
'application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"',
)
.header('Cache-Control', 'public, max-age=600');
return { version: '2.0', ...base };
});

Expand Down

0 comments on commit 054ba3f

Please sign in to comment.