-
Notifications
You must be signed in to change notification settings - Fork 74
/
mastodon.js
65 lines (55 loc) · 1.6 KB
/
mastodon.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
/**
* Returns an array of objects containing the following fields;
* "domain": <string>,
* "version": <string>,
* "description": <string>,
* "languages": Array<string> - containing ISO 639-1 language codes (en, fr, de),
* "region": <string>,
* "categories": Array<string> - A list of catgories
* "proxied_thumbnail": <string>,
* "total_users": <int>,
* "last_week_users": <int>,
* "approval_required": <boolean>,
* "language": <string> - containing ISO 639-1 language code (en, fr, de),
* "category": <string>
*
* @returns {Promise<Array>}
*/
const serverList = async function () {
/**
*
* @type {Promise<Response>}
*/
let servers = await (await fetch('https://api.joinmastodon.org/servers'))
.json();
// Sort servers by total_users
servers = servers.sort((a, b) => {
if (a.total_users > b.total_users) {
return -1;
}
if (a.total_users < b.total_users) {
return 1;
}
return 0;
});
// Separately add the two Instances by Mastodon GmbH themselves.
servers.unshift({
domain: "mastodon.social"
}, {
domain: "mastodon.online"
});
return servers
.slice(0, 99);
}
// Compile server list
const compile = async function () {
const result = (await serverList());
const mastodonRules = result.map((element) => {
if (!element.hasOwnProperty('domain')) {
throw Error("Domain key not found in server list")
}
return `||${element.domain}^`
});
return mastodonRules;
}
module.exports = compile