-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
250 lines (222 loc) · 8.68 KB
/
index.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>HitDNS Latest CI Artifacts Download</title>
<style type="text/css">
table {
border-collapse: collapse;
border-spacing: 0px;
}
table, th, td {
padding: 5px;
border: 1px solid black;
}
</style>
<script type="text/javascript">
var kvFallbackStorage = { __proto__: null };
function kvGet(key) {
if ((typeof sessionStorage) == 'object') {
return JSON.parse(sessionStorage.getItem(key));
}
return kvFallbackStorage[key];
}
function kvSet(key, value) {
if ((typeof sessionStorage) == 'object') {
return sessionStorage.setItem(key, JSON.stringify(value));
}
return (kvFallbackStorage[key] = value);
}
function kvClear() {
if ((typeof sessionStorage) == 'object') {
return sessionStorage.clear();
}
return (kvFallbackStorage = { __proto__: null });
}
function kvCheck() {
var METADATA_LAST_UPDATE = "metadata.lastUpdate";
kvGet(METADATA_LAST_UPDATE) || kvSet(METADATA_LAST_UPDATE, Date.now());
if (Math.abs(Date.now() - kvGet(METADATA_LAST_UPDATE)) > 10 * 60 * 1000) { // ten minutes
kvClear();
}
}
setTimeout(kvCheck, 0);
setInterval(kvCheck, 10 * 1000);
function lsBin() {
return new Promise(function (resolve, reject) {
var list = kvGet("LIST");
if (list) {
resolve(list);
return;
}
var xhr = new XMLHttpRequest();
xhr.onloadend = function (event) {
var ls = JSON.parse(xhr.responseText);
kvSet("LIST", ls);
resolve(ls);
};
xhr.open("GET", "https://api.github.com/repos/delta4chat/hitdns/contents/bin?ref=bin");
xhr.send();
});
}
function getLatest() {
return new Promise(function (resolve, reject) {
document.getElementById("updateStatus").innerHTML = "Get Latest...";
var latest = kvGet("LATEST");
if (latest) {
resolve(latest);
return;
}
var xhr = new XMLHttpRequest();
xhr.onloadend = function (event) {
var l = JSON.parse(xhr.responseText);
if (l.type != "symlink") {
reject(new Error("ref: hitdns/bin -> path: bin/latest is not a symlink"));
return;
}
l = l.target;
kvSet("LATEST", l);
resolve(l);
};
xhr.open("GET", "https://api.github.com/repos/delta4chat/hitdns/contents/bin/latest?ref=bin");
xhr.send();
});
}
function listBinaries(dirname) {
document.getElementById("updateStatus").innerHTML = "Listing " + dirname + "...";
return new Promise(function (resolve, reject) {
var key = "binaries." + dirname;
var binaries = kvGet(key);
if (binaries) {
resolve(binaries);
return;
}
var url = "https://api.github.com/repos/delta4chat/hitdns/contents/bin/" + dirname + "?ref=bin";
var xhr = new XMLHttpRequest();
xhr.onloadend = function (event) {
var b = JSON.parse(xhr.responseText);
kvSet(key, b);
resolve(b);
};
xhr.open("GET", url);
xhr.send();
});
}
function listLatest() {
return new Promise(function (resolve, reject) {
getLatest()
.then(listBinaries)
.then(resolve)
.catch(reject);
});
}
function fileSize(bytes) {
var K = 1024;
var M = 1024 * K;
var G = 1024 * M;
var T = 1024 * G;
if (bytes < K) {
return "" + bytes + " " + (bytes == 1 ? "byte" : "bytes");
}
if (bytes < M) {
return "" + (bytes / K).toFixed(3) + " KiB";
}
if (bytes < G) {
return "" + (bytes / M).toFixed(3) + " MiB";
}
if (bytes < T) {
return "" + (bytes / G).toFixed(3) + " GiB";
}
return "" + (bytes / T).toFixed(3) + " TiB";
}
function updateBinaries(binaries) {
var html = "HitDNS - Download links of CI builds: <br/>";
var listof = true;
var binaries_len = binaries.length;
for (var i = 0; i < binaries_len; ++i) {
var it = binaries[i];
if (listof) {
listof = false;
html += '<span style="font-size: 25px;"> (List of ' + it.path.split("/")[1] + ') </span> <br/>';
//html += '<table><thead><tr><th>File</th><th>Size</th></tr></thead><tbody>';
html += '<table><tbody><tr><td>File</td><td>Size</td></tr>';
}
html += '<tr><td><a href="' + it.download_url + '">' + it.name + '</a></td><td>' + fileSize(it.size) + '</td></tr>';
}
html += '<tr><td>File</td><td>Size</td></tr></tbody></table>';
document.getElementById("binaries").innerHTML = html;
document.getElementById("updateStatus").innerHTML = "OK";
}
function updateLatest() {
return new Promise(function (resolve, reject) {
listLatest()
.then(updateBinaries)
.then(resolve)
.catch(reject)
});
}
function main() {
return new Promise(function (resolve, reject) {
updateLatest().catch(reject);
document.getElementById("buildSelect").onchange = function (event) {
var selected = document.getElementById("buildSelect").value;
kvSet("SELECTED", selected);
if (selected == "latest") {
updateLatest().catch(asyncErrorHandler);
} else {
listBinaries(selected).then(updateBinaries).catch(asyncErrorHandler);
}
};
lsBin().then(function (ls) {
var html = '<option value="latest">Latest</option>';
var ls_len = ls.length;
for (var i = 0; i < ls_len; ++i) {
var it = ls[i];
if (it.type != "dir") {
continue;
}
var selected = '';
if (it.name == kvGet("SELECTED")) {
selected = ' selected="selected"';
}
html += '<option value="' + it.name + '"' + selected + '>' + it.name + '</option>';
}
var buildSelect = document.getElementById("buildSelect");
buildSelect.innerHTML = html;
setTimeout(buildSelect.onchange, 0);
});
});
}
function asyncErrorHandler(err) {
alert("error (from promise): " + err + "\n" + err.stack);
}
function syncErrorHandler(err) {
alert("error (from sync): " + err + "\n" + err.stack);
}
setTimeout(function () {
try {
main().catch(asyncErrorHandler);
} catch (err) {
syncErrorHandler(err);
}
}, 0);
</script>
</head>
<body>
<h1 id="binariesTitle">HitDNS Latest CI Artifacts Download</h1>
<div>
select build by date/commit:
<select id="buildSelect">
<option value="latest">Latest</option>
</select>
</div>
<hr />
Status: <span id="updateStatus">Idle</span><br />
<div id="binaries" style="font-size: 50px">
Loading data from GitHub API... <br />
If you are stuck in the loading process, you can enable JavaScript in your browser settings or
plugins/addons.<br />
Or, if you dislike JavaScript, use this <a href="https://hitdns.pages.dev/">NO-JS version</a>.
</div>
</body>
</html>