-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.htm
131 lines (107 loc) · 3.3 KB
/
update.htm
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
<!--
This is the source file for the built-in update dialog in HomeDing devices.
like http://plug02/$update
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web Update</title>
</head>
<body style="width:300px">
<h1>Web Update</h1>
<div style="display:grid">
<progress value=0 max=20></progress>
<span id='l' style="height:2rem"></span>
</div>
<div style="text-align: right;"><button>Start</button></div>
<script>
var d = document;
var s = 0;
// s == 0 => fetching list
// s == 1 => fetching sysinfo
// s == 2 => cleanweb
// s == 3 => copy file
// s == 4 => wait for file finished
var repo = 'https://homeding.github.io/';
var eBar = d.querySelector('progress');
var oBtn = d.querySelector('button');
var x = 0; // done
var a = 0; // active
var w; ///< working list
var si; // sysinfo
var t = 0; // timer
var r; // for fetch
var seed = "?" + new Date().valueOf();
function log(t) {
d.querySelector('#l').innerText = t;
} // log
if (location.hash) {
repo += location.hash.substring(1) + '/';
} else {
repo += 'v09/';
}
log('loading from:\n' + repo);
// grab next file
async function doF() {
var theItem = w.shift();
// set progress
log(theItem);
if (theItem[0] !== '-') {
r = await fetch(repo + theItem + seed);
r = await r.arrayBuffer();
var formData = new FormData();
formData.append('file', new Blob([r]), '/' + theItem);
await fetch('/', { method: 'POST', body: formData });
}
} // doF()
d.querySelector('button').addEventListener('click', () => {
if (s === 0) {
oBtn.textContent = '-';
t = window.setInterval(async function() {
if (a) {
// wait
} else {
a = 1;
if (s == 0) { // not yet started
// fetch file list;
log('sysinfo...');
r = await fetch('/api/sysinfo' + seed);
si = await r.text();
} else if (s == 1) {
log('list...');
si = JSON.parse(si);
if (si.fsTotalBytes < 200000) {
repo = repo.replace(/(v\d+)\/$/, "$1m/");
}
r = await fetch(repo + 'list.txt' + seed);
r = await r.text();
w = r.replace(/\r?\n/g, ';').replace(/;$/, '').split(';');
eBar.max = w.length + 3;
} else if (s == 2) {
// clean files in filesystem first
log('clean...');
await fetch('/api/cleanweb');
} else if (s == 3) {
if (w.length > 0) {
await doF();
s--;
}
} else if (s == 4) {
window.clearInterval(t);
log('done');
oBtn.textContent = ">>>";
}
eBar.value = ++x;
s++;
a = 0;
}
}, 100);
} else if (s === 5) {
location.href = '/updateicons.htm';
}
});
</script>
</body>
</html>