-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeinfo-registration.js
More file actions
68 lines (54 loc) · 1.37 KB
/
nodeinfo-registration.js
File metadata and controls
68 lines (54 loc) · 1.37 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
// Put inside the backticks the space/newline separated list of instance domains
const input = `
`
main(input.trim().split(/\s+/))
async function main(domains) {
console.log("Fetching nodeinfo data, this may take a while ...")
const closed = []
const open = []
const failed = []
for (const domain of domains) {
try {
const { software, openRegistrations } = await fetchNodeInfo(domain)
const list = openRegistrations ? open : closed
list.push({
domain,
software: `${software.name} ${software.version}`
})
} catch (error) {
failed.push({
domain,
error: error.message
})
}
}
console.log("Done !", "\n")
renderList(closed, "Closed", true)
renderList(open, "Open", true)
renderList(failed, "Failed to access registration state", false)
}
function fetchNodeInfo(domain) {
return fetchJson(new URL("/.well-known/nodeinfo", `https://${domain}`))
.then(index => fetchJson(index.links[0].href))
}
function fetchJson(url) {
return fetch(url).then(response => {
if (response.ok) {
return response.json()
} else {
throw new Error(`${response.status} ${response.statusText}`)
}
})
}
function renderList(list, label, required) {
if (!required && !list.length) {
return
}
(required ? console.group : console.groupCollapsed)(`${label}`)
if (list.length) {
console.table(list)
} else {
console.log("Empty")
}
console.groupEnd()
}