|
@@ -2025,14 +2025,6 @@ func system_fs_specialURIEncode(inputPath string) string {
|
|
|
return inputPath
|
|
|
}
|
|
|
|
|
|
-func system_fs_matchFileExt(inputFilename string, extArray []string) bool {
|
|
|
- inputExt := filepath.Ext(inputFilename)
|
|
|
- if stringInSlice(inputExt, extArray) {
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
//Handle file properties request
|
|
|
func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
|
|
|
userinfo, err := userHandler.GetUserInfoFromRequest(w, r)
|
|
@@ -2137,7 +2129,6 @@ func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
|
|
|
*/
|
|
|
|
|
|
func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
|
-
|
|
|
currentDir, _ := mv(r, "dir", true)
|
|
|
//Commented this line to handle dirname that contains "+" sign
|
|
|
//currentDir, _ = url.QueryUnescape(currentDir)
|
|
@@ -2159,77 +2150,97 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
|
if currentDir[len(currentDir)-1:] != "/" {
|
|
|
currentDir = currentDir + "/"
|
|
|
}
|
|
|
- //Convert the virutal path to realpath
|
|
|
- realpath, err := userinfo.VirtualPathToRealPath(currentDir)
|
|
|
|
|
|
+ VirtualRootID, subpath, err := fs.GetIDFromVirtualPath(currentDir)
|
|
|
if err != nil {
|
|
|
- sendErrorResponse(w, "Error. Unable to parse path. "+err.Error())
|
|
|
+ sendErrorResponse(w, "Unable to resolve requested path: "+err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if !fileExists(realpath) {
|
|
|
- userRoot, _ := userinfo.VirtualPathToRealPath("user:/")
|
|
|
- if filepath.Clean(realpath) == filepath.Clean(userRoot) {
|
|
|
- //Initiate user folder (Initiaed in user object)
|
|
|
- userinfo.GetHomeDirectory()
|
|
|
- } else if !strings.Contains(filepath.ToSlash(filepath.Clean(currentDir)), "/") {
|
|
|
- //User root not created. Create the root folder
|
|
|
- os.MkdirAll(filepath.Clean(realpath), 0775)
|
|
|
- } else {
|
|
|
- //Folder not exists
|
|
|
- log.Println("[File Explorer] Requested path: ", realpath, " does not exists!")
|
|
|
- sendErrorResponse(w, "Folder not exists")
|
|
|
+ var parsedFilelist []fs.FileData
|
|
|
+ var realpath string = ""
|
|
|
+ //Handle some special virtual file systems / mount points
|
|
|
+ if VirtualRootID == "share" && subpath == "" {
|
|
|
+ userpgs := userinfo.GetUserPermissionGroupNames()
|
|
|
+ files, err := shareEntryTable.RouteShareVroot(subpath, userinfo.Username, userpgs)
|
|
|
+ if err != nil {
|
|
|
+ sendErrorResponse(w, "Error. Unable to parse path. "+err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ parsedFilelist = files
|
|
|
+ } else {
|
|
|
+ //Normal file systems
|
|
|
|
|
|
- }
|
|
|
- if sortMode == "" {
|
|
|
- sortMode = "default"
|
|
|
- }
|
|
|
-
|
|
|
- //Check for really special exception in where the path contains [ or ] which cannot be handled via Golang Glob function
|
|
|
- files, _ := system_fs_specialGlob(filepath.Clean(realpath) + "/*")
|
|
|
+ //Convert the virutal path to realpath
|
|
|
+ realpath, err = userinfo.VirtualPathToRealPath(currentDir)
|
|
|
|
|
|
- var parsedFilelist []fs.FileData
|
|
|
- var shortCutInfo *shortcut.ShortcutData = nil
|
|
|
- for _, v := range files {
|
|
|
- //Check if it is hidden file
|
|
|
- isHidden, _ := hidden.IsHidden(v, false)
|
|
|
- if showHidden != "true" && isHidden {
|
|
|
- //Skipping hidden files
|
|
|
- continue
|
|
|
+ if err != nil {
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- //Check if this is an aodb file
|
|
|
- if filepath.Base(v) == "aofs.db" || filepath.Base(v) == "aofs.db.lock" {
|
|
|
- //Database file (reserved)
|
|
|
- continue
|
|
|
+ if !fileExists(realpath) {
|
|
|
+ userRoot, _ := userinfo.VirtualPathToRealPath("user:/")
|
|
|
+ if filepath.Clean(realpath) == filepath.Clean(userRoot) {
|
|
|
+ //Initiate user folder (Initiaed in user object)
|
|
|
+ userinfo.GetHomeDirectory()
|
|
|
+ } else if !strings.Contains(filepath.ToSlash(filepath.Clean(currentDir)), "/") {
|
|
|
+ //User root not created. Create the root folder
|
|
|
+ os.MkdirAll(filepath.Clean(realpath), 0775)
|
|
|
+ } else {
|
|
|
+ //Folder not exists
|
|
|
+ log.Println("[File Explorer] Requested path: ", realpath, " does not exists!")
|
|
|
+ sendErrorResponse(w, "Folder not exists")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if sortMode == "" {
|
|
|
+ sortMode = "default"
|
|
|
}
|
|
|
|
|
|
- //Check if it is shortcut file. If yes, render a shortcut data struct
|
|
|
- if filepath.Ext(v) == ".shortcut" {
|
|
|
- //This is a shortcut file
|
|
|
- shorcutData, err := shortcut.ReadShortcut(v)
|
|
|
- if err == nil {
|
|
|
- shortCutInfo = shorcutData
|
|
|
+ //Check for really special exception in where the path contains [ or ] which cannot be handled via Golang Glob function
|
|
|
+ files, _ := system_fs_specialGlob(filepath.Clean(realpath) + "/*")
|
|
|
+ var shortCutInfo *shortcut.ShortcutData = nil
|
|
|
+ for _, v := range files {
|
|
|
+ //Check if it is hidden file
|
|
|
+ isHidden, _ := hidden.IsHidden(v, false)
|
|
|
+ if showHidden != "true" && isHidden {
|
|
|
+ //Skipping hidden files
|
|
|
+ continue
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- rawsize := fs.GetFileSize(v)
|
|
|
- modtime, _ := fs.GetModTime(v)
|
|
|
- thisFile := fs.FileData{
|
|
|
- Filename: filepath.Base(v),
|
|
|
- Filepath: currentDir + filepath.Base(v),
|
|
|
- Realpath: v,
|
|
|
- IsDir: IsDir(v),
|
|
|
- Filesize: rawsize,
|
|
|
- Displaysize: fs.GetFileDisplaySize(rawsize, 2),
|
|
|
- ModTime: modtime,
|
|
|
- IsShared: shareManager.FileIsShared(v),
|
|
|
- Shortcut: shortCutInfo,
|
|
|
- }
|
|
|
+ //Check if this is an aodb file
|
|
|
+ if filepath.Base(v) == "aofs.db" || filepath.Base(v) == "aofs.db.lock" {
|
|
|
+ //Database file (reserved)
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
- parsedFilelist = append(parsedFilelist, thisFile)
|
|
|
+ //Check if it is shortcut file. If yes, render a shortcut data struct
|
|
|
+ if filepath.Ext(v) == ".shortcut" {
|
|
|
+ //This is a shortcut file
|
|
|
+ shorcutData, err := shortcut.ReadShortcut(v)
|
|
|
+ if err == nil {
|
|
|
+ shortCutInfo = shorcutData
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ rawsize := fs.GetFileSize(v)
|
|
|
+ modtime, _ := fs.GetModTime(v)
|
|
|
+ thisFile := fs.FileData{
|
|
|
+ Filename: filepath.Base(v),
|
|
|
+ Filepath: currentDir + filepath.Base(v),
|
|
|
+ Realpath: v,
|
|
|
+ IsDir: IsDir(v),
|
|
|
+ Filesize: rawsize,
|
|
|
+ Displaysize: fs.GetFileDisplaySize(rawsize, 2),
|
|
|
+ ModTime: modtime,
|
|
|
+ IsShared: shareManager.FileIsShared(v),
|
|
|
+ Shortcut: shortCutInfo,
|
|
|
+ }
|
|
|
+
|
|
|
+ parsedFilelist = append(parsedFilelist, thisFile)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Sort the filelist
|
|
@@ -2272,6 +2283,12 @@ func system_fs_handleDirHash(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ VirtualRootID, subpath, _ := fs.GetIDFromVirtualPath(currentDir)
|
|
|
+ if VirtualRootID == "share" && subpath == "" {
|
|
|
+ sendTextResponse(w, hex.EncodeToString([]byte("0")))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
rpath, err := userinfo.VirtualPathToRealPath(currentDir)
|
|
|
if err != nil {
|
|
|
sendErrorResponse(w, "Invalid dir given")
|