-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathnodeinfo.js
More file actions
101 lines (90 loc) · 2.83 KB
/
nodeinfo.js
File metadata and controls
101 lines (90 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// 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';
const router = express.Router();
router.get('/', async (req, res) => {
const domain = req.app.get('domain');
if (req.originalUrl === '/.well-known/nodeinfo') {
const thisNode = {
links: [
{
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);
}
if (req.originalUrl === '/nodeinfo/2.0') {
const bookmarksDb = req.app.get('bookmarksDb');
const bookmarkCount = await bookmarksDb.getBookmarkCount();
const nodeInfo = {
version: 2.0,
software: {
name: instanceType,
version: instanceVersion,
},
protocols: ['activitypub'],
services: {
outbound: ['atom1.0'],
inbound: [],
},
usage: {
users: {
total: 1,
activeMonth: 1,
activeHalfyear: 1,
},
localPosts: bookmarkCount,
},
openRegistrations: false,
metadata: {},
};
// 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://sharepostmarks.org',
},
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);
}
});
export default router;