forked from syuilo/joinmisskey.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstanceq.js
63 lines (49 loc) · 1.65 KB
/
instanceq.js
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
/* eslint-disable no-console */
const fetch = require("node-fetch")
const loadyaml = require("./scripts/builder/loadyaml")
const mylist = loadyaml("./data/instances.yml")
const ignorehosts = loadyaml("./data/ignorehosts.yml")
const duplicated = mylist.filter((e, i, arr) => arr.findIndex(x => x.url === e.url) !== i)
.map(e => e.url)
if (duplicated.length > 0) console.log(`Duplicated:\n ${duplicated.join(",\n ")}\n`);
else console.log("Duplicated:\n There is no duplicated instance!\n");
(async () => {
console.log(`Get Instances from the-federation.info`);
let nodes = []
const apinum = 60
let next = true
let offset = 0
while (next) {
const body = {
sort: "+pubSub",
limit: apinum + 1,
// notResponding: false,
offset
}
console.log(body)
const l = await fetch("https://misskey.io/api/federation/instances", {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json'
}
}).then(async res => {
const text = await res.text()
if (!text.startsWith("{") && !text.startsWith("[")) {
throw Error(text)
}
return JSON.parse(text)
})
next = l.length === apinum + 1
if (next) l.pop();
nodes = l.concat(nodes)
offset += apinum
}
const notIncluded = nodes.filter((e, i, arr) => (
!ignorehosts.some(x => x === e.host) &&
e.softwareName === 'misskey' &&
(e.latestStatus === null || (e.latestStatus >=200 && e.latestStatus < 300)) &&
!mylist.some(x => x.url === e.host)
))
console.log(notIncluded.map(e => e.host))
})()