forked from sousuke0422/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instanceq.js
72 lines (56 loc) · 1.72 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
64
65
66
67
68
69
70
71
72
import fetch from "node-fetch"
import loadyaml from "./loadyaml.js"
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 server!\n");
const invalid = mylist.filter(e => e.langs !== undefined && !Array.isArray(e.langs))
.map(e => e.url)
if (invalid.length > 0) console.log(`Invalid:\n ${invalid.join(",\n ")}\n`);
export default async () => {
console.log(`Get servers from misskey.io`);
const notIncluded = new Set();
const apinum = 60
let next = true
let offset = 0
while (next) {
const body = {
sort: "+pubSub",
limit: apinum + 1,
// notResponding: false,
offset
}
const hrstart = process.hrtime()
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 hrend = process.hrtime(hrstart)
console.log(body, hrend[0], hrend[1] / 1000000)
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();
for (const e of l) {
if (
!ignorehosts.some(x => x === e.host) &&
e.softwareName === 'misskey' &&
(e.latestStatus === null || e.isNotResponding === false) &&
!mylist.some(x => x.url === e.host)
) {
notIncluded.add(e.host);
}
}
offset += apinum
}
return Array.from(notIncluded)
}