Quellcode durchsuchen

Fixed websocket upload bug

Toby Chui vor 3 Jahren
Ursprung
Commit
1630bba27b

+ 16 - 36
file_system.go

@@ -4,6 +4,7 @@ import (
 	"crypto/sha256"
 	"encoding/hex"
 	"encoding/json"
+	"fmt"
 	"io"
 	"log"
 	"math"
@@ -406,11 +407,13 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 	//Check if it is huge file upload mode
 	isHugeFile := false
 	hugefile, _ := common.Mv(r, "hugefile", false)
-	if hugefile == "true" && !fsh.RequireBuffer {
-		//Huge file mode is not compatible with buffer typed FS
+	if hugefile == "true" && filesystem.FileExists(realUploadPath) {
+		//Huge file mode is only compatible with local file systems
+		//For remote file system, use buffer to tmp then upload method
 		isHugeFile = true
 	}
 
+	//Create destination folder if not exists
 	targetUploadLocation := filepath.Join(realUploadPath, filename)
 	if !fshAbs.FileExists(realUploadPath) {
 		fshAbs.MkdirAll(realUploadPath, 0755)
@@ -420,13 +423,10 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 	uploadUUID := uuid.NewV4().String()
 	uploadFolder := filepath.Join(*tmp_directory, "uploads", uploadUUID)
 	if isHugeFile {
-		//Upload to the same directory as the target location. This option do not allow buffered fs
+		//Change to upload directly to target disk
 		uploadFolder = filepath.Join(realUploadPath, ".metadata/.upload", uploadUUID)
-		fshAbs.MkdirAll(uploadFolder, 0700)
-	} else {
-		//Buffer to local tmp folder
-		os.MkdirAll(uploadFolder, 0700)
 	}
+	os.MkdirAll(uploadFolder, 0700)
 
 	//Start websocket connection
 	var upgrader = websocket.Upgrader{}
@@ -474,11 +474,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 			log.Println("Upload terminated by client. Cleaning tmp folder.")
 			//Clear the tmp folder
 			time.Sleep(1 * time.Second)
-			if isHugeFile {
-				fshAbs.RemoveAll(uploadFolder)
-			} else {
-				os.RemoveAll(uploadFolder)
-			}
+			os.RemoveAll(uploadFolder)
 			return
 		}
 		//The mt should be 2 = binary for file upload and 1 for control syntax
@@ -508,11 +504,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 				c.Close()
 
 				//Clear the tmp files
-				if isHugeFile {
-					fshAbs.RemoveAll(uploadFolder)
-				} else {
-					os.RemoveAll(uploadFolder)
-				}
+				os.RemoveAll(uploadFolder)
 				return
 			}
 
@@ -521,6 +513,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 
 			//Check if the file size is too big
 			totalFileSize += fs.GetFileSize(chunkFilepath)
+
 			if totalFileSize > max_upload_size {
 				//File too big
 				c.WriteMessage(1, []byte(`{\"error\":\"File size too large\"}`))
@@ -531,12 +524,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 				c.Close()
 
 				//Clear the tmp files
-				if isHugeFile {
-					fshAbs.RemoveAll(uploadFolder)
-				} else {
-					os.RemoveAll(uploadFolder)
-				}
-
+				os.RemoveAll(uploadFolder)
 				return
 			} else if !userinfo.StorageQuota.HaveSpace(totalFileSize) {
 				//Quota exceeded
@@ -548,11 +536,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 				c.Close()
 
 				//Clear the tmp files
-				if isHugeFile {
-					fshAbs.RemoveAll(uploadFolder)
-				} else {
-					os.RemoveAll(uploadFolder)
-				}
+				os.RemoveAll(uploadFolder)
 			}
 			blockCounter++
 
@@ -574,10 +558,10 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 
 	//Merge the file. Merge file location must be on local machine
 	mergeFileLocation := decodedUploadLocation
-	if fsh.RequireBuffer && !isHugeFile {
+	if fsh.RequireBuffer {
 		mergeFileLocation = getFsBufferFilepath(decodedUploadLocation, false)
 	}
-
+	fmt.Println(mergeFileLocation)
 	out, err := os.OpenFile(mergeFileLocation, os.O_CREATE|os.O_WRONLY, 0755)
 	if err != nil {
 		log.Println("Failed to open file:", err)
@@ -619,7 +603,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 	}
 
 	//Upload it to remote side if it fits the user quota && is buffer file
-	if fsh.RequireBuffer && !isHugeFile {
+	if fsh.RequireBuffer {
 		//This is buffer file. Upload to dest fsh
 		f, err := os.Open(mergeFileLocation)
 		if err != nil {
@@ -656,11 +640,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 
 	//Clear the tmp folder
 	time.Sleep(300 * time.Millisecond)
-	if isHugeFile {
-		fshAbs.RemoveAll(uploadFolder)
-	} else {
-		os.RemoveAll(uploadFolder)
-	}
+	os.RemoveAll(uploadFolder)
 
 	//Close WebSocket connection after finished
 	c.WriteControl(8, []byte{}, time.Now().Add(time.Second))

+ 3 - 0
mod/filesystem/abstractions/localfs/localfs.go

@@ -157,6 +157,9 @@ func (l LocalFileSystemAbstraction) RealPathToVirtualPath(fullpath string, usern
 	}
 	fullpath = filepath.ToSlash(filepath.Clean(fullpath))
 	subPath := strings.TrimPrefix(fullpath, prefix)
+	if !strings.HasPrefix(subPath, "/") {
+		subPath = "/" + subPath
+	}
 
 	return l.UUID + ":" + filepath.ToSlash(subPath), nil
 }

+ 1 - 1
mod/share/share.go

@@ -1236,7 +1236,7 @@ func (s *Manager) CanModifyShareEntry(userinfo *user.User, vpath string) bool {
 		return false
 	}
 	rpath, _ := fsh.FileSystemAbstraction.VirtualPathToRealPath(vpath, userinfo.Username)
-	if fsh.Hierarchy == "public" && fsh.FileSystemAbstraction.FileExists(rpath) {
+	if userinfo.CanWrite(vpath) && fsh.Hierarchy == "public" && fsh.FileSystemAbstraction.FileExists(rpath) {
 		return true
 	}
 

+ 4 - 1
web/SystemAO/file_system/file_explorer.html

@@ -4662,7 +4662,10 @@
                       
                     }else{
                         console.log("[File Explorer] Setting huge file cutoff size at: " + ao_module_utils.formatBytes(data.Avilable/16));
-                        largeFileCutoffSize = data.Avilable/16 - 4096;
+                        if (!isNaN(data.Avilable) && data.Avilable > 0){
+                            largeFileCutoffSize = data.Avilable/16 - 4096;
+                        }
+                        
                     }
                 },
                 error: function(){