Browse Source

Fixed webdavfs vpath2rpath conv

Toby Chui 3 years ago
parent
commit
3ff436b567

+ 4 - 0
mod/filesystem/abstractions/smbfs/smbfs.go

@@ -246,6 +246,10 @@ func (a ServerMessageBlockFileSystemAbstraction) ReadDir(filename string) ([]fs.
 	}
 	}
 	dirEntires := []fs.DirEntry{}
 	dirEntires := []fs.DirEntry{}
 	for _, fi := range fis {
 	for _, fi := range fis {
+		if fi.Name() == "System Volume Information" || fi.Name() == "$RECYCLE.BIN" || fi.Name() == "$MFT" {
+			//System folders. Hide it
+			continue
+		}
 		dirEntires = append(dirEntires, newDirEntryFromFileInfo(fi))
 		dirEntires = append(dirEntires, newDirEntryFromFileInfo(fi))
 	}
 	}
 	return dirEntires, nil
 	return dirEntires, nil

+ 6 - 55
mod/filesystem/abstractions/webdavfs/webdavfs.go

@@ -137,7 +137,11 @@ func (e WebDAVFileSystem) RealPathToVirtualPath(rpath string, username string) (
 	if e.Hierarchy == "user" && strings.HasPrefix(rpath, "/users/"+username) {
 	if e.Hierarchy == "user" && strings.HasPrefix(rpath, "/users/"+username) {
 		rpath = strings.TrimPrefix(rpath, "/users/"+username)
 		rpath = strings.TrimPrefix(rpath, "/users/"+username)
 	}
 	}
-	return e.UUID + ":" + filepath.ToSlash(rpath), nil
+	rpath = filepath.ToSlash(rpath)
+	if !strings.HasPrefix(rpath, "/") {
+		rpath = "/" + rpath
+	}
+	return e.UUID + ":" + rpath, nil
 }
 }
 func (e WebDAVFileSystem) FileExists(filename string) bool {
 func (e WebDAVFileSystem) FileExists(filename string) bool {
 	filename = filterFilepath(filepath.ToSlash(filepath.Clean(filename)))
 	filename = filterFilepath(filepath.ToSlash(filepath.Clean(filename)))
@@ -168,61 +172,7 @@ func (e WebDAVFileSystem) Glob(wildcard string) ([]string, error) {
 	chunks := strings.Split(strings.TrimPrefix(wildcard, "/"), "/")
 	chunks := strings.Split(strings.TrimPrefix(wildcard, "/"), "/")
 	results, err := e.globpath("/", chunks, 0)
 	results, err := e.globpath("/", chunks, 0)
 	return results, err
 	return results, err
-	/*
-		//Get the longest path without *
-		chunksWithoutStar := []string{}
-		chunks := strings.Split(wildcard, "/")
-		for _, chunk := range chunks {
-			if !strings.Contains(chunk, "*") {
-				chunksWithoutStar = append(chunksWithoutStar, chunk)
-			} else {
-				//Cut off
-				break
-			}
-		}
-
-		if strings.Count(wildcard, "*") <= 1 && strings.Contains(chunks[len(chunks)-1], "*") {
-			//Fast Glob
-			fileInfos, err := e.c.ReadDir(filterFilepath(filepath.ToSlash(filepath.Clean(filepath.Dir(wildcard)))))
-			if err != nil {
-				return []string{}, err
-			}
-
-			validFiles := []string{}
-			matchingRule := wildCardToRegexp(wildcard)
-			for _, thisFileInfo := range fileInfos {
-				thisFileFullpath := filepath.ToSlash(filepath.Join(filepath.Dir(wildcard), thisFileInfo.Name()))
-				match, _ := regexp.MatchString(matchingRule, thisFileFullpath)
-				if match {
-					validFiles = append(validFiles, thisFileFullpath)
-				}
-			}
-			return validFiles, nil
-		} else {
-			//Slow Glob
-			walkRoot := strings.Join(chunksWithoutStar, "/")
-			if !strings.HasPrefix(walkRoot, "/") {
-				walkRoot = "/" + walkRoot
-			}
-
-			allFiles := []string{}
-			e.Walk(walkRoot, func(path string, info fs.FileInfo, err error) error {
-				allFiles = append(allFiles, path)
-				return nil
-			})
-
-			validFiles := []string{}
-			matchingRule := wildCardToRegexp(wildcard) + "$"
-			for _, thisFilepath := range allFiles {
-				match, _ := regexp.MatchString(matchingRule, thisFilepath)
-				if match {
-					validFiles = append(validFiles, thisFilepath)
-				}
-			}
 
 
-			return validFiles, nil
-		}
-	*/
 }
 }
 func (e WebDAVFileSystem) GetFileSize(filename string) int64 {
 func (e WebDAVFileSystem) GetFileSize(filename string) int64 {
 	filename = filterFilepath(filepath.ToSlash(filepath.Clean(filename)))
 	filename = filterFilepath(filepath.ToSlash(filepath.Clean(filename)))
@@ -256,6 +206,7 @@ func (e WebDAVFileSystem) ReadFile(filename string) ([]byte, error) {
 	return bytes, nil
 	return bytes, nil
 }
 }
 func (e WebDAVFileSystem) ReadDir(filename string) ([]fs.DirEntry, error) {
 func (e WebDAVFileSystem) ReadDir(filename string) ([]fs.DirEntry, error) {
+	filename = filterFilepath(filepath.ToSlash(filepath.Clean(filename)))
 	fis, err := e.c.ReadDir(filename)
 	fis, err := e.c.ReadDir(filename)
 	if err != nil {
 	if err != nil {
 		return []fs.DirEntry{}, err
 		return []fs.DirEntry{}, err

+ 31 - 25
web/Music/functions/listSong.js

@@ -225,9 +225,9 @@ function handleUserRequest(){
                     var thisRoot = thisMusicDir.split("/").shift() + "/";
                     var thisRoot = thisMusicDir.split("/").shift() + "/";
                     var objcetsInRoot = [];
                     var objcetsInRoot = [];
                     if (thisRoot == "user:/"){
                     if (thisRoot == "user:/"){
-                        objcetsInRoot = filelib.glob(thisRoot + "Music/*");
+                        objcetsInRoot = filelib.readdir(thisRoot + "Music");
                     }else{
                     }else{
-                        objcetsInRoot = filelib.glob(thisRoot + "*");
+                        objcetsInRoot = filelib.readdir(thisRoot);
                         thisMusicDir = thisRoot;
                         thisMusicDir = thisRoot;
                     }
                     }
                     
                     
@@ -241,10 +241,11 @@ function handleUserRequest(){
                     var files = [];
                     var files = [];
                     var folders = [];
                     var folders = [];
                     for (var j = 0; j < objcetsInRoot.length; j++){
                     for (var j = 0; j < objcetsInRoot.length; j++){
-                        if (filelib.isDir(objcetsInRoot[j])){
-                            folders.push(objcetsInRoot[j]);
+                        var thisObject = objcetsInRoot[j];
+                        if (thisObject.IsDir){
+                            folders.push(thisObject.Filepath);
                         }else{
                         }else{
-                            files.push(objcetsInRoot[j]);
+                            files.push(thisObject.Filepath);
                         }
                         }
                     }
                     }
 
 
@@ -258,16 +259,19 @@ function handleUserRequest(){
             }else{
             }else{
                 //List information about other folders
                 //List information about other folders
                 var targetpath = decodeURIComponent(listdir);
                 var targetpath = decodeURIComponent(listdir);
-                var filelist = filelib.aglob(targetpath + "*");
+                var filelist = filelib.readdir(targetpath);
                 var files = [];
                 var files = [];
+                var fileSizes = [];
                 var folders = [];
                 var folders = [];
                 for (var j = 0; j < filelist.length; j++){
                 for (var j = 0; j < filelist.length; j++){
-                    if (filelib.isDir(filelist[j])){
-                        folders.push(filelist[j]);
+                    var thisFile = filelist[j];
+                    if (thisFile.IsDir){
+                        folders.push(thisFile.Filepath);
                     }else{
                     }else{
-                        var ext = filelist[j].split(".").pop();
-                        if (IsSupportExt(ext)  && !IsMetaFile(filelist[j])){
-                            files.push(filelist[j]);
+                        var ext = thisFile.Ext.substr(1);
+                        if (IsSupportExt(ext)  && !IsMetaFile(thisFile.Filepath)){
+                            files.push(thisFile.Filepath);
+                            fileSizes.push(thisFile.Filesize);
                         }
                         }
                     }
                     }
                 }
                 }
@@ -275,32 +279,35 @@ function handleUserRequest(){
                 //For each folder, get its information
                 //For each folder, get its information
                 var folderInfo = [];
                 var folderInfo = [];
                 
                 
-                for (var i = 0; i < folders.length; i++){
+                for (var i = 0; i < folders.length; i++){ 
                     var thisFolderInfo = [];
                     var thisFolderInfo = [];
                     var folderName = folders[i].split("/").pop();
                     var folderName = folders[i].split("/").pop();
+                    /*
                     var thisFolderSubfolder = [];
                     var thisFolderSubfolder = [];
                     var thisFolderSubfiles = [];
                     var thisFolderSubfiles = [];
-                    var subFolderFileList = filelib.aglob(folders[i] + "/*")
+                    var subFolderFileList = filelib.readdir(folders[i])
                     for (var j = 0; j < subFolderFileList.length; j++){
                     for (var j = 0; j < subFolderFileList.length; j++){
-                        if (filelib.isDir(subFolderFileList[j])){
-                            var thisFolderName = subFolderFileList[j].split("/").pop();
+                        var thisFileinfo = subFolderFileList[j];
+                        if (thisFileinfo.IsDir){
+                            var thisFolderName = thisFileinfo.Filename;
                             if (thisFolderName.substring(0,1) != "."){
                             if (thisFolderName.substring(0,1) != "."){
-                                thisFolderSubfolder.push(subFolderFileList[j]);
+                                thisFolderSubfolder.push(thisFileinfo.Filepath);
                             }
                             }
                         }else{
                         }else{
-                            var ext = subFolderFileList[j].split(".").pop();
-                            if (IsSupportExt(ext) && !IsMetaFile(subFolderFileList[j])){
-                                thisFolderSubfiles.push(subFolderFileList[j]);
+                            var ext = thisFileinfo.Ext.substr(1);
+                            if (IsSupportExt(ext) && !IsMetaFile(thisFileinfo.Filepath)){
+                                thisFolderSubfiles.push(thisFileinfo.Filepath);
                             }
                             }
                             
                             
                         }
                         }
                     }
                     }
-
+                    */
                     thisFolderInfo.push(folderName);
                     thisFolderInfo.push(folderName);
                     thisFolderInfo.push(folders[i] + "/");
                     thisFolderInfo.push(folders[i] + "/");
-                    thisFolderInfo.push((thisFolderSubfiles).length + "");
-                    thisFolderInfo.push((thisFolderSubfolder).length + "");
-                    
+                    //thisFolderInfo.push((thisFolderSubfiles).length + "");
+                    //thisFolderInfo.push((thisFolderSubfolder).length + "");
+                    thisFolderInfo.push(-1);
+                    thisFolderInfo.push(-1);
                     folderInfo.push(thisFolderInfo)
                     folderInfo.push(thisFolderInfo)
                 }
                 }
                 
                 
@@ -314,7 +321,7 @@ function handleUserRequest(){
                     filename = filename.join(".");
                     filename = filename.join(".");
                     var ext = files[i].split(".").pop()
                     var ext = files[i].split(".").pop()
 
 
-                    var filesize = filelib.filesize(files[i]);
+                    var filesize = fileSizes[i];
                     filesize = bytesToSize(filesize);
                     filesize = bytesToSize(filesize);
 
 
                     thisFileInfo.push("/media?file=" + files[i]);
                     thisFileInfo.push("/media?file=" + files[i]);
@@ -329,7 +336,6 @@ function handleUserRequest(){
                 results.push(folderInfo);
                 results.push(folderInfo);
                 results.push(fileInfo);
                 results.push(fileInfo);
                 sendJSONResp(JSON.stringify(results));
                 sendJSONResp(JSON.stringify(results));
-                
             }
             }
             
             
 
 

+ 18 - 5
web/Music/index.html

@@ -1725,10 +1725,21 @@
 	                //This is directory inside normal folders. 
 	                //This is directory inside normal folders. 
 	                box = replaceAll("{foldername}",folderName,box);
 	                box = replaceAll("{foldername}",folderName,box);
 	            }
 	            }
-	            var fileinfo = "[" + fileCount + " files]"
-	            if (folderCount > 0){
-	                fileinfo = "[" + fileCount + " files, " + folderCount  +" folders]"
-	            }
+
+				/*
+				var fileinfo = fileinfo = "[No playable files]";
+				console.log(folderCount, fileCount);
+				if (folderCount > 0 && fileCount > 0){
+					fileinfo = "[" + fileCount + " files, " + folderCount  +" folders]"
+				}else if (fileCount > 0){
+					fileinfo = "[" + fileCount + " files]";
+				}else if (fileCount == -1 && folderCount == -1){
+					fileinfo = "";
+				}
+				*/
+				var fileinfo = folderPath;
+				
+	           
 	            box = replaceAll("{fileinfo}",fileinfo,box);
 	            box = replaceAll("{fileinfo}",fileinfo,box);
 				rootPaths.push(folderPath);
 				rootPaths.push(folderPath);
 	            $("#mainList").append(box);
 	            $("#mainList").append(box);
@@ -1873,7 +1884,9 @@
     	            var fileinfo = "[" + fileCount + " files]"
     	            var fileinfo = "[" + fileCount + " files]"
     	            if (folderCount > 0){
     	            if (folderCount > 0){
     	                fileinfo = "[" + fileCount + " files, " + folderCount  +" folders]"
     	                fileinfo = "[" + fileCount + " files, " + folderCount  +" folders]"
-    	            }
+    	            }else if (folderCount == -1){
+						fileinfo = folderPath;
+					}
     	            box = replaceAll("{fileinfo}",fileinfo,box);
     	            box = replaceAll("{fileinfo}",fileinfo,box);
     	             $("#mainList").append(box);
     	             $("#mainList").append(box);
     	        }
     	        }