Przeglądaj źródła

Added save indicator

Toby Chui 2 lat temu
rodzic
commit
5c63c17e98
2 zmienionych plików z 49 dodań i 57 usunięć
  1. 29 50
      file_system.go
  2. 20 7
      web/SystemAO/file_system/file_explorer.html

+ 29 - 50
file_system.go

@@ -519,9 +519,6 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 			if msg == "done" {
 				//Start the merging process
 				break
-			} else {
-				//Unknown operations
-
 			}
 		} else if mt == 2 {
 			//File block. Save it to tmp folder
@@ -631,7 +628,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	for _, filesrc := range chunkName {
+	for counter, filesrc := range chunkName {
 		var srcChunkReader arozfs.File
 		if isHugeFile {
 			srcChunkReader, err = fshAbs.Open(filesrc)
@@ -644,7 +641,9 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 			c.WriteMessage(1, []byte(`{\"error\":\"Failed to open Source Chunk\"}`))
 			return
 		}
+
 		io.Copy(out, srcChunkReader)
+
 		srcChunkReader.Close()
 
 		//Delete file immediately to save space
@@ -654,6 +653,9 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 			os.Remove(filesrc)
 		}
 
+		//Write to websocket for the percentage of upload is written fro tmp to dest
+		moveProg := strconv.Itoa(int(math.Round(float64(counter)/float64(len(chunkName))*100))) + "%"
+		c.WriteMessage(1, []byte(`{\"move\":\"`+moveProg+`"}`))
 	}
 
 	out.Close()
@@ -2257,7 +2259,7 @@ func system_fs_removeUserPreferences(username string) {
 }
 
 func system_fs_listDrives(w http.ResponseWriter, r *http.Request) {
-	if authAgent.CheckAuth(r) == false {
+	if !authAgent.CheckAuth(r) {
 		utils.SendErrorResponse(w, "User not logged in")
 		return
 	}
@@ -2370,36 +2372,6 @@ func system_fs_listRoot(w http.ResponseWriter, r *http.Request) {
 	You can also pass in normal path for globing if you are not sure.
 */
 
-func system_fs_specialGlob(path string) ([]string, error) {
-	//Quick fix for foldername containing -] issue
-	path = strings.ReplaceAll(path, "[", "[[]")
-	files, err := filepath.Glob(path)
-	if err != nil {
-		return []string{}, err
-	}
-
-	if strings.Contains(path, "[") == true || strings.Contains(path, "]") == true {
-		if len(files) == 0 {
-			//Handle reverse check. Replace all [ and ] with *
-			newSearchPath := strings.ReplaceAll(path, "[", "?")
-			newSearchPath = strings.ReplaceAll(newSearchPath, "]", "?")
-			//Scan with all the similar structure except [ and ]
-			tmpFilelist, _ := filepath.Glob(newSearchPath)
-			for _, file := range tmpFilelist {
-				file = filepath.ToSlash(file)
-				if strings.Contains(file, filepath.ToSlash(filepath.Dir(path))) {
-					files = append(files, file)
-				}
-			}
-		}
-	}
-	//Convert all filepaths to slash
-	for i := 0; i < len(files); i++ {
-		files[i] = filepath.ToSlash(files[i])
-	}
-	return files, nil
-}
-
 func system_fs_specialURIDecode(inputPath string) string {
 	inputPath = strings.ReplaceAll(inputPath, "+", "{{plus_sign}}")
 	inputPath, _ = url.QueryUnescape(inputPath)
@@ -2407,12 +2379,14 @@ func system_fs_specialURIDecode(inputPath string) string {
 	return inputPath
 }
 
+/*
 func system_fs_specialURIEncode(inputPath string) string {
 	inputPath = strings.ReplaceAll(inputPath, " ", "{{space_sign}}")
 	inputPath, _ = url.QueryUnescape(inputPath)
 	inputPath = strings.ReplaceAll(inputPath, "{{space_sign}}", "%20")
 	return inputPath
 }
+*/
 
 // Handle file properties request
 func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
@@ -2709,23 +2683,24 @@ func system_fs_handleDirHash(w http.ResponseWriter, r *http.Request) {
 	}
 
 	//Get a list of files in this directory
-	currentDir = filepath.ToSlash(filepath.Clean(rpath)) + "/"
 	/*
-		filesInDir, err := fshAbs.Glob(currentDir + "*")
-		if err != nil {
-			utils.SendErrorResponse(w, err.Error())
-			return
-		}
+		currentDir = filepath.ToSlash(filepath.Clean(rpath)) + "/"
 
-
-		filenames := []string{}
-		for _, file := range filesInDir {
-			if len(filepath.Base(file)) > 0 && string([]rune(filepath.Base(file))[0]) != "." {
-				//Ignore hidden files
-				filenames = append(filenames, filepath.Base(file))
+			filesInDir, err := fshAbs.Glob(currentDir + "*")
+			if err != nil {
+				utils.SendErrorResponse(w, err.Error())
+				return
 			}
 
-		}
+
+			filenames := []string{}
+			for _, file := range filesInDir {
+				if len(filepath.Base(file)) > 0 && string([]rune(filepath.Base(file))[0]) != "." {
+					//Ignore hidden files
+					filenames = append(filenames, filepath.Base(file))
+				}
+
+			}
 	*/
 	finfos, err := fshAbs.ReadDir(rpath)
 	if err != nil {
@@ -3139,6 +3114,10 @@ func system_fs_handleFilePermission(w http.ResponseWriter, r *http.Request) {
 	}
 
 	fsh, subpath, err := GetFSHandlerSubpathFromVpath(file)
+	if err != nil {
+		utils.SendErrorResponse(w, err.Error())
+		return
+	}
 	fshAbs := fsh.FileSystemAbstraction
 	rpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
 	if err != nil {
@@ -3186,13 +3165,13 @@ func system_fs_handleFilePermission(w http.ResponseWriter, r *http.Request) {
 			//Always ok as this is owned by the user
 		} else if fsh.Hierarchy == "public" {
 			//Require admin
-			if userinfo.IsAdmin() == false {
+			if !userinfo.IsAdmin() {
 				utils.SendErrorResponse(w, "Permission Denied")
 				return
 			}
 		} else {
 			//Not implemeneted. Require admin
-			if userinfo.IsAdmin() == false {
+			if !userinfo.IsAdmin() {
 				utils.SendErrorResponse(w, "Permission Denied")
 				return
 			}

+ 20 - 7
web/SystemAO/file_system/file_explorer.html

@@ -4558,13 +4558,13 @@
                         if ($(this).attr("taskID") == uuid){
                             //Update this progress bar
                             $(this).find(".bar").css("width",progress + "%");
-                            $(this).find(".progress.percentage").text(progress.toFixed(1) + "%");
-                            console.log(progress.toFixed(1) + "%");
+                            $(this).find(".progress.percentage").html(`<i class="ui upload icon"></i> ${progress.toFixed(1)}%`);
+                            //console.log(progress.toFixed(1) + "%");
                             if (progress == 100){
                                 //When progress = 100 and the server is not response with 200,
                                 //That means the upload has finish and server is processing the upload
-                                $(this).find(".progress").addClass("active");
-                                $(this).find(".progress.percentage").hide();
+                                $(this).find(".progress").addClass("indicating");
+                                //$(this).find(".progress.percentage").hide();
                             }
                         }
                     });
@@ -4671,9 +4671,11 @@
                             if ($(this).attr("taskID") == taskUUID){
                                 //Update this progress bar to completed
                                 $(this).find(".bar").css("width","100%");
-                                $(this).find(".progress").attr("class", "ui tiny success progress");
+                                $(this).find(".progress:not(.percentage)").attr("class", "ui tiny success progress");
+                                $(this).find(".progress.percentage").hide();
                                 $(this).find(".uploadTaskRemoveIcon").show();
                                 $(this).addClass("ended");
+                               
                                 
                                 $.when($(this).delay(1000).fadeOut("fast")).then(function(){
                                     $(this).remove();
@@ -4686,7 +4688,7 @@
                         //Try to parse it as JSON
                         try{
                             var resp = JSON.parse(incomingValue.split('\\' + '"').join("\""));
-                            console.log(resp);
+                            //console.log(resp);
                             if (resp.error !== undefined){
                                 //This is an error message
                                 msgbox("red remove",resp.error);
@@ -4696,9 +4698,20 @@
                                     if ($(this).attr("taskID") == taskUUID){
                                         //Update this progress bar to completed
                                         $(this).find(".bar").css("width","100%");
-                                        $(this).find(".progress").attr("class","ui tiny error progress");
+                                        $(this).find(".progress:not(.percentage)").attr("class","ui tiny error progress");
                                         $(this).find(".uploadTaskRemoveIcon").show();
                                         $(this).addClass("ended");
+                                        $(this).find(".progress.percentage").hide();
+                                    }
+                                });
+                            }else if (resp.move !== undefined){
+                                //File move from tmp to archive progress
+                                //Update the progress bar to show move progress
+                                $(".uploadTask").each(function(){
+                                    if ($(this).attr("taskID") == taskUUID){
+                                        $(this).find(".bar").css("width","100%");
+                                        $(this).find(".progress:not(.percentage)").attr("class","ui small indicating violet progress");
+                                        $(this).find(".progress.percentage").html(`<i class="ui save icon"></i> ${resp.move}`);
                                     }
                                 });
                             }