|
1
|
|
|
const decoder = new TextDecoder(); |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
async function tailLog(response, element) { |
|
4
|
|
|
const reader = response.body.getReader(); |
|
5
|
|
|
|
|
6
|
|
|
while (true) { |
|
7
|
|
|
const {value, done} = await reader.read(); |
|
8
|
|
|
if (done) break; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
const text = decoder.decode(value); |
|
11
|
|
|
|
|
12
|
|
|
let result = null |
|
13
|
|
|
|
|
14
|
|
|
try { |
|
15
|
|
|
let strings = text.split("\n"); |
|
16
|
|
|
result = JSON.parse(strings.pop()); |
|
17
|
|
|
|
|
18
|
|
|
element.innerHTML += strings.join("\n"); |
|
19
|
|
|
element.scrollTop = element.scrollHeight; |
|
20
|
|
|
} catch (e) { |
|
21
|
|
|
element.innerHTML += text; |
|
22
|
|
|
element.scrollTop = element.scrollHeight; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
if (result) { |
|
26
|
|
|
if (!result.success) { |
|
27
|
|
|
throw new Error('update failed'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return result |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
throw new Error('Unexpected end of stream'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
const installButton = document.getElementById('install-start'); |
|
38
|
|
|
const updateButton = document.getElementById('update-start'); |
|
39
|
|
|
const logCard = document.getElementById('log-card'); |
|
40
|
|
|
const logOutput = document.getElementById('log-output'); |
|
41
|
|
|
const logError = document.getElementById('log-error'); |
|
42
|
|
|
|
|
43
|
|
|
if (installButton) { |
|
44
|
|
|
installButton.onclick = async function () { |
|
45
|
|
|
logCard.style.removeProperty('display'); |
|
46
|
|
|
|
|
47
|
|
|
installButton.disabled = true; |
|
48
|
|
|
|
|
49
|
|
|
const folder = document.getElementById('folder'); |
|
50
|
|
|
|
|
51
|
|
|
const installResponse = await fetch(`${baseUrl}/install/_run?folder=` + folder.value, {method: 'POST'}); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
try { |
|
54
|
|
|
const result = await tailLog(installResponse, logOutput); |
|
55
|
|
|
if (result.newLocation) { |
|
|
|
|
|
|
56
|
|
|
window.location = result.newLocation; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} catch (e) { |
|
59
|
|
|
console.log(e); |
|
|
|
|
|
|
60
|
|
|
return showLog(); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (updateButton) { |
|
66
|
|
|
updateButton.onclick = async function () { |
|
67
|
|
|
updateButton.disabled = true; |
|
68
|
|
|
logCard.style.removeProperty('display'); |
|
69
|
|
|
|
|
70
|
|
|
const prepareUpdate = await fetch(`${baseUrl}/update/_prepare`, {method: 'POST'}) |
|
|
|
|
|
|
71
|
|
|
if (prepareUpdate.status !== 200) { |
|
72
|
|
|
logOutput.innerHTML += 'Failed to prepare update' + "\n" |
|
73
|
|
|
return showLog(); |
|
74
|
|
|
} else { |
|
|
|
|
|
|
75
|
|
|
try { |
|
76
|
|
|
await tailLog(prepareUpdate, logOutput); |
|
77
|
|
|
} catch (e) { |
|
78
|
|
|
return showLog(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (!isFlexProject) { |
|
|
|
|
|
|
83
|
|
|
logOutput.innerHTML += 'Updating to Flex Project' + "\n" |
|
84
|
|
|
|
|
85
|
|
|
const migrate = await fetch(`${baseUrl}/update/_migrate-template`, {method: 'POST'}) |
|
86
|
|
|
|
|
87
|
|
|
if (migrate.status !== 204 && migrate.status !== 200) { |
|
88
|
|
|
logOutput.innerHTML += 'Failed to update to Flex Project' + "\n" |
|
89
|
|
|
logOutput.innerHTML += await migrate.text(); |
|
90
|
|
|
return showLog(); |
|
91
|
|
|
} else { |
|
|
|
|
|
|
92
|
|
|
logOutput.innerHTML += 'Updated to Flex Project' + "\n" |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
const updateRun = await fetch(`${baseUrl}/update/_run`, {method: 'POST'}); |
|
97
|
|
|
|
|
98
|
|
|
try { |
|
99
|
|
|
await tailLog(updateRun, logOutput); |
|
100
|
|
|
} catch (e) { |
|
101
|
|
|
return showLog(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
const resetConfig = await fetch(`${baseUrl}/update/_reset_config`, {method: 'POST'}); |
|
105
|
|
|
|
|
106
|
|
|
if (resetConfig.status !== 200) { |
|
107
|
|
|
logOutput.innerHTML += 'Failed to update config files' + "\n" |
|
108
|
|
|
logOutput.innerHTML += await resetConfig.text(); |
|
109
|
|
|
} else { |
|
110
|
|
|
try { |
|
111
|
|
|
await tailLog(resetConfig, logOutput); |
|
112
|
|
|
} catch (e) { |
|
113
|
|
|
return showLog(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
const finishUpdate = await fetch(`${baseUrl}/update/_finish`, {method: 'POST'}) |
|
118
|
|
|
if (finishUpdate.status !== 200) { |
|
119
|
|
|
logOutput.innerHTML += 'Failed to prepare update' + "\n" |
|
120
|
|
|
logOutput.innerHTML += await finishUpdate.text(); |
|
121
|
|
|
} else { |
|
122
|
|
|
try { |
|
123
|
|
|
await tailLog(finishUpdate, logOutput); |
|
124
|
|
|
} catch (e) { |
|
125
|
|
|
return showLog(); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
window.location.href = `${baseUrl}/finish`; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
function showLog() { |
|
134
|
|
|
logError.style.removeProperty('display'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
const downloadLogButton = document.getElementById('download-log'); |
|
138
|
|
|
|
|
139
|
|
|
if (downloadLogButton) { |
|
140
|
|
|
downloadLogButton.onclick = function () { |
|
141
|
|
|
const text = new Blob([logOutput.innerText], {type: 'text/plain'}); |
|
|
|
|
|
|
142
|
|
|
const element = document.createElement('a'); |
|
143
|
|
|
element.href = URL.createObjectURL(text); |
|
|
|
|
|
|
144
|
|
|
element.setAttribute('download', 'log.txt'); |
|
145
|
|
|
|
|
146
|
|
|
element.style.display = 'none'; |
|
147
|
|
|
document.body.appendChild(element); |
|
148
|
|
|
|
|
149
|
|
|
element.click(); |
|
150
|
|
|
|
|
151
|
|
|
document.body.removeChild(element); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.