Ver Fonte

[release] v0.7.9

Yann Stepienik há 2 anos atrás
pai
commit
eec4b3cbdb
7 ficheiros alterados com 78 adições e 12 exclusões
  1. 1 1
      changelog.md
  2. 56 7
      client/src/api/index.jsx
  3. 1 1
      docker.arm64.sh
  4. 1 1
      docker.sh
  5. 1 1
      package.json
  6. 16 1
      src/docker/run.go
  7. 2 0
      src/newInstall.go

+ 1 - 1
changelog.md

@@ -1,4 +1,4 @@
-## Version 0.7.1 -> 0.7.8
+## Version 0.7.1 -> 0.7.9
  - Fix issue where multiple DBs get created at the setup
  - Fix issue where multiple DBs get created at the setup
  - Add more special characters to be used for password validation
  - Add more special characters to be used for password validation
  - Add configurable default data path for binds
  - Add configurable default data path for binds

+ 56 - 7
client/src/api/index.jsx

@@ -53,13 +53,62 @@ let isOnline = () => {
 }
 }
 
 
 let newInstall = (req, onProgress) => {
 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) => {
 let checkHost = (host) => {

+ 1 - 1
docker.arm64.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 
 
-VERSION=$(grep -o '\"version\": \"[^\"]*\"' package.json | sed 's/[^0-9a-z.-]//g')
+VERSION=$(grep -o '\"version\": \"[^\"]*\"' package.json | sed 's/[^0-9a-z.-]//g' | sed 's/version//g')
 LATEST="latest"
 LATEST="latest"
 
 
 # if branch is unstable in git for circle ci
 # if branch is unstable in git for circle ci

+ 1 - 1
docker.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 
 
-VERSION=$(grep -o '\"version\": \"[^\"]*\"' package.json | sed 's/[^0-9a-z.-]//g')
+VERSION=$(grep -o '\"version\": \"[^\"]*\"' package.json | sed 's/[^0-9a-z.-]//g'| sed 's/version//g')
 LATEST="latest"
 LATEST="latest"
 
 
 # if branch is unstable in git for circle ci
 # if branch is unstable in git for circle ci

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "cosmos-server",
   "name": "cosmos-server",
-  "version": "0.7.8",
+  "version": "0.7.9",
   "description": "",
   "description": "",
   "main": "test-server.js",
   "main": "test-server.js",
   "bugs": {
   "bugs": {

+ 16 - 1
src/docker/run.go

@@ -5,7 +5,8 @@ import (
 	"io"
 	"io"
 	"os"
 	"os"
 	"net/http"
 	"net/http"
-
+	"fmt"
+	"errors"
 
 
 	// "github.com/docker/docker/client"
 	// "github.com/docker/docker/client"
 	"github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/api/types/container"
@@ -22,6 +23,18 @@ type VolumeMount struct {
 }
 }
 
 
 func NewDB(w http.ResponseWriter, req *http.Request) (string, error) {
 func NewDB(w http.ResponseWriter, req *http.Request) (string, error) {
+	w.Header().Set("X-Content-Type-Options", "nosniff")
+	w.Header().Set("Transfer-Encoding", "chunked")
+	
+	flusher, ok := w.(http.Flusher)
+	if !ok {
+			http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
+			return "", errors.New("Streaming unsupported!")
+	}
+
+	fmt.Fprintf(w, "NewInstall: Create DB\n")
+	flusher.Flush()
+
 	id := utils.GenerateRandomString(3)
 	id := utils.GenerateRandomString(3)
 	mongoUser := "cosmos-" + utils.GenerateRandomString(5) 
 	mongoUser := "cosmos-" + utils.GenerateRandomString(5) 
 	mongoPass := utils.GenerateRandomString(24)
 	mongoPass := utils.GenerateRandomString(24)
@@ -72,6 +85,8 @@ func NewDB(w http.ResponseWriter, req *http.Request) (string, error) {
 	err := CreateService(service, 
 	err := CreateService(service, 
 		func (msg string) {
 		func (msg string) {
 			utils.Log(msg)
 			utils.Log(msg)
+			fmt.Fprintf(w, msg + "\n")
+			flusher.Flush()
 		},
 		},
 	)
 	)
 
 

+ 2 - 0
src/newInstall.go

@@ -98,6 +98,8 @@ func NewInstallRoute(w http.ResponseWriter, req *http.Request) {
 				utils.LoadBaseMainConfig(newConfig)
 				utils.LoadBaseMainConfig(newConfig)
 				utils.Log("NewInstall: MongoDB created, waiting for it to be ready")
 				utils.Log("NewInstall: MongoDB created, waiting for it to be ready")
 				waitForDB()
 				waitForDB()
+				w.WriteHeader(http.StatusOK)
+				return
 			} else {
 			} else {
 				utils.Log("NewInstall: Invalid MongoDBMode")
 				utils.Log("NewInstall: Invalid MongoDBMode")
 				utils.Error("NewInstall: Invalid MongoDBMode", nil)
 				utils.Error("NewInstall: Invalid MongoDBMode", nil)