Skip to content

Commit

Permalink
Merge pull request #181 from andypiper/nodeinfo-2.1
Browse files Browse the repository at this point in the history
feat: add nodeinfo 2.1 document (parallel with 2.0).
  • Loading branch information
ckolderup authored Jan 25, 2024
2 parents 44c6775 + 6c238c1 commit 58d1ca1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ app.use('/', routes.core);
app.use('/api/inbox', cors(), routes.inbox);
app.use('/.well-known/nodeinfo', routes.nodeinfo);
app.use('/nodeinfo/2.0', routes.nodeinfo);
app.use('/nodeinfo/2.1', routes.nodeinfo);
app.use('/opensearch.xml', routes.opensearch);

app.listen(PORT, () => console.log(`App listening on port ${PORT}`));
50 changes: 46 additions & 4 deletions src/routes/activitypub/nodeinfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// implementation of http://nodeinfo.diaspora.software/protocol.html
// implementation of http://nodeinfo.diaspora.software/
// TODO: activeMonth and activeHalfyear should be dynamic, currently static
// TODO: enable override of nodeName and nodeDescription from settings
// homepage and repository may want to be updated for user-specific forks
// NB openRegistrations will always be false for a single-instance server

import express from 'express';
import { instanceType, instanceVersion } from '../../util.js';
Expand All @@ -15,6 +19,10 @@ router.get('/', async (req, res) => {
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
href: `https://${domain}/nodeinfo/2.0`,
},
{
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.1',
href: `https://${domain}/nodeinfo/2.1`,
},
],
};
res.json(thisNode);
Expand All @@ -24,7 +32,6 @@ router.get('/', async (req, res) => {
const bookmarksDb = req.app.get('bookmarksDb');
const bookmarkCount = await bookmarksDb.getBookmarkCount();

// TODO: activeMonth and activeHalfyear should be dynamic, currently static
const nodeInfo = {
version: 2.0,
software: {
Expand All @@ -48,10 +55,45 @@ router.get('/', async (req, res) => {
metadata: {},
};

// spec requires setting this, majority of implementations
// appear to not bother with it?
// spec says servers *should* set this, majority of implementations
// appear to not bother with this detail, but we'll do right by the spec
res.type('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"');
res.json(nodeInfo);
}

if (req.originalUrl === '/nodeinfo/2.1') {
const bookmarksDb = req.app.get('bookmarksDb');
const bookmarkCount = await bookmarksDb.getBookmarkCount();

const nodeInfo = {
version: 2.1,
software: {
name: instanceType,
version: instanceVersion,
repository: 'https://github.com/ckolderup/postmarks',
homepage: 'https://postmarks.glitch.me',
},
protocols: ['activitypub'],
services: {
outbound: ['atom1.0'],
inbound: [],
},
usage: {
users: {
total: 1,
activeMonth: 1,
activeHalfyear: 1,
},
localPosts: bookmarkCount,
},
openRegistrations: false,
metadata: {
nodeName: 'Postmarks',
nodeDescription: 'A single-user bookmarking website designed to live on the Fediverse.',
},
};

res.type('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"');
res.json(nodeInfo);
}
});
Expand Down

0 comments on commit 58d1ca1

Please sign in to comment.