|
@@ -53,13 +53,62 @@ let isOnline = () => {
|
|
|
}
|
|
|
|
|
|
let newInstall = (req, onProgress) => {
|
|
|
- return wrap(fetch('/cosmos/api/newInstall', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/json'
|
|
|
- },
|
|
|
- body: JSON.stringify(req)
|
|
|
- }))
|
|
|
+ if(req.step == '2') {
|
|
|
+ const requestOptions = {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ body: JSON.stringify(req)
|
|
|
+ };
|
|
|
+
|
|
|
+ return fetch('/cosmos/api/newInstall', requestOptions)
|
|
|
+ .then(response => {
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error(response.statusText);
|
|
|
+ }
|
|
|
+
|
|
|
+ // The response body is a ReadableStream. This code reads the stream and passes chunks to the callback.
|
|
|
+ const reader = response.body.getReader();
|
|
|
+
|
|
|
+ // Read the stream and pass chunks to the callback as they arrive
|
|
|
+ return new ReadableStream({
|
|
|
+ start(controller) {
|
|
|
+ function read() {
|
|
|
+ return reader.read().then(({ done, value }) => {
|
|
|
+ if (done) {
|
|
|
+ controller.close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Decode the UTF-8 text
|
|
|
+ let text = new TextDecoder().decode(value);
|
|
|
+ // Split by lines in case there are multiple lines in one chunk
|
|
|
+ let lines = text.split('\n');
|
|
|
+ for (let line of lines) {
|
|
|
+ if (line) {
|
|
|
+ // Call the progress callback
|
|
|
+ onProgress(line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ controller.enqueue(value);
|
|
|
+ return read();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return read();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }).catch((e) => {
|
|
|
+ console.error(e);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return wrap(fetch('/cosmos/api/newInstall', {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ body: JSON.stringify(req)
|
|
|
+ }))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
let checkHost = (host) => {
|