forked from mirrorz-org/mirrorz-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geekpie.js
55 lines (50 loc) · 1.26 KB
/
geekpie.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
const cname = require("./utils").cname;
const statusConverter = function(s) {
let c = "S";
if (!s.Idle) {
c = "YO"
} else if (!s.Result) {
c = "FO"
}
const t = Math.round(new Date(s.LastFinished).getTime()/1000).toString();
return c + t;
};
const TYPE_DICT = {
'system': 'os',
'software': 'app',
'font': 'font',
}
module.exports = async function (siteUrl) {
const name_func = await cname();
const site = await (await fetch(siteUrl)).json();
const summary = await (await fetch("https://mirrors.shanghaitech.edu.cn/summary")).json();
const downloads = await (await fetch("https://mirrors.shanghaitech.edu.cn/downloads")).json();
const mirrors = []
for (const k in summary.WorkerStatus) {
const cname = name_func(k)
const url = "/" + k;
const status = statusConverter(summary.WorkerStatus[k])
mirrors.push({
cname,
url,
status,
})
}
const info = Object.values(downloads).map((item) => {
return {
distro: name_func(item.display),
category: TYPE_DICT[item.type] ?? 'os',
urls: item.links.map((link) => {
return {
name: link.name + " (" + link.external + ")",
url: link.link,
}
}),
};
});
return {
site,
info,
mirrors,
}
};