|
@@ -29,6 +29,7 @@ import (
|
|
"imuslab.com/arozos/mod/filesystem"
|
|
"imuslab.com/arozos/mod/filesystem"
|
|
"imuslab.com/arozos/mod/filesystem/arozfs"
|
|
"imuslab.com/arozos/mod/filesystem/arozfs"
|
|
fsp "imuslab.com/arozos/mod/filesystem/fspermission"
|
|
fsp "imuslab.com/arozos/mod/filesystem/fspermission"
|
|
|
|
+ "imuslab.com/arozos/mod/filesystem/fssort"
|
|
"imuslab.com/arozos/mod/filesystem/fuzzy"
|
|
"imuslab.com/arozos/mod/filesystem/fuzzy"
|
|
hidden "imuslab.com/arozos/mod/filesystem/hidden"
|
|
hidden "imuslab.com/arozos/mod/filesystem/hidden"
|
|
"imuslab.com/arozos/mod/filesystem/localversion"
|
|
"imuslab.com/arozos/mod/filesystem/localversion"
|
|
@@ -2472,8 +2473,6 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
fshAbs := fsh.FileSystemAbstraction
|
|
|
|
|
|
- var parsedFilelist []filesystem.FileData
|
|
|
|
-
|
|
|
|
//Normal file systems
|
|
//Normal file systems
|
|
realpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
|
|
realpath, err := fshAbs.VirtualPathToRealPath(subpath, userinfo.Username)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -2502,65 +2501,19 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
sortMode = "default"
|
|
sortMode = "default"
|
|
}
|
|
}
|
|
|
|
|
|
- //Check for really special exception in where the path contains [ or ] which cannot be handled via Golang Glob function
|
|
|
|
- /*
|
|
|
|
- files, err := fshAbs.Glob(realpath + "/*")
|
|
|
|
- if err != nil {
|
|
|
|
- systemWideLogger.PrintAndLog("File System", "Unable to list dir: "+err.Error(), err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //Check if this is an aodb file
|
|
|
|
- if filepath.Base(v) == "aofs.db" || filepath.Base(v) == "aofs.db.lock" {
|
|
|
|
- //Database file (reserved)
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fstat, _ := fshAbs.Stat(v)
|
|
|
|
-
|
|
|
|
- rawsize := fstat.Size()
|
|
|
|
- modtime := fstat.ModTime().Unix()
|
|
|
|
- thisvPath, _ := fshAbs.RealPathToVirtualPath(v, userinfo.Username)
|
|
|
|
- thisFile := filesystem.FileData{
|
|
|
|
- Filename: filepath.Base(v),
|
|
|
|
- Filepath: currentDir + filepath.Base(v),
|
|
|
|
- Realpath: v,
|
|
|
|
- IsDir: fstat.IsDir(),
|
|
|
|
- Filesize: rawsize,
|
|
|
|
- Displaysize: filesystem.GetFileDisplaySize(rawsize, 2),
|
|
|
|
- ModTime: modtime,
|
|
|
|
- IsShared: shareManager.FileIsShared(userinfo, thisvPath),
|
|
|
|
- Shortcut: shortCutInfo,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- parsedFilelist = append(parsedFilelist, thisFile)
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
files, err := fshAbs.ReadDir(realpath)
|
|
files, err := fshAbs.ReadDir(realpath)
|
|
if err != nil {
|
|
if err != nil {
|
|
systemWideLogger.PrintAndLog("File System", "Unable to read dir: "+err.Error(), err)
|
|
systemWideLogger.PrintAndLog("File System", "Unable to read dir: "+err.Error(), err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Remapping use parsed list
|
|
|
|
+ parsedFilelist := map[string]filesystem.FileData{}
|
|
|
|
+
|
|
|
|
+ //Sorting use list
|
|
|
|
+ realpathList := []string{}
|
|
|
|
+ fileInfoList := []fs.FileInfo{}
|
|
|
|
+
|
|
for _, f := range files {
|
|
for _, f := range files {
|
|
//Check if it is hidden file
|
|
//Check if it is hidden file
|
|
isHidden, _ := hidden.IsHidden(f.Name(), false)
|
|
isHidden, _ := hidden.IsHidden(f.Name(), false)
|
|
@@ -2585,7 +2538,10 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- statInfo, _ := f.Info()
|
|
|
|
|
|
+ statInfo, err := f.Info()
|
|
|
|
+ if err != nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
thisvPath, _ := fshAbs.RealPathToVirtualPath(filepath.Join(realpath, f.Name()), userinfo.Username)
|
|
thisvPath, _ := fshAbs.RealPathToVirtualPath(filepath.Join(realpath, f.Name()), userinfo.Username)
|
|
thisFile := filesystem.FileData{
|
|
thisFile := filesystem.FileData{
|
|
Filename: f.Name(),
|
|
Filename: f.Name(),
|
|
@@ -2599,31 +2555,23 @@ func system_fs_handleList(w http.ResponseWriter, r *http.Request) {
|
|
Shortcut: shortCutInfo,
|
|
Shortcut: shortCutInfo,
|
|
}
|
|
}
|
|
|
|
|
|
- parsedFilelist = append(parsedFilelist, thisFile)
|
|
|
|
|
|
+ parsedFilelist[currentDir+f.Name()] = thisFile
|
|
|
|
+ realpathList = append(realpathList, currentDir+f.Name())
|
|
|
|
+ fileInfoList = append(fileInfoList, statInfo)
|
|
}
|
|
}
|
|
|
|
|
|
//Sort the filelist
|
|
//Sort the filelist
|
|
- if sortMode == "default" {
|
|
|
|
- //Sort by name, convert filename to window sorting methods
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool {
|
|
|
|
- return strings.ToLower(parsedFilelist[i].Filename) < strings.ToLower(parsedFilelist[j].Filename)
|
|
|
|
- })
|
|
|
|
- } else if sortMode == "reverse" {
|
|
|
|
- //Sort by reverse name
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool {
|
|
|
|
- return strings.ToLower(parsedFilelist[i].Filename) > strings.ToLower(parsedFilelist[j].Filename)
|
|
|
|
- })
|
|
|
|
- } else if sortMode == "smallToLarge" {
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool { return parsedFilelist[i].Filesize < parsedFilelist[j].Filesize })
|
|
|
|
- } else if sortMode == "largeToSmall" {
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool { return parsedFilelist[i].Filesize > parsedFilelist[j].Filesize })
|
|
|
|
- } else if sortMode == "mostRecent" {
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool { return parsedFilelist[i].ModTime > parsedFilelist[j].ModTime })
|
|
|
|
- } else if sortMode == "leastRecent" {
|
|
|
|
- sort.Slice(parsedFilelist, func(i, j int) bool { return parsedFilelist[i].ModTime < parsedFilelist[j].ModTime })
|
|
|
|
|
|
+ sortedRealpathList := fssort.SortFileList(realpathList, fileInfoList, sortMode)
|
|
|
|
+ results := []filesystem.FileData{}
|
|
|
|
+
|
|
|
|
+ for _, thisRpath := range sortedRealpathList {
|
|
|
|
+ val, ok := parsedFilelist[thisRpath]
|
|
|
|
+ if ok {
|
|
|
|
+ results = append(results, val)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- jsonString, _ := json.Marshal(parsedFilelist)
|
|
|
|
|
|
+ jsonString, _ := json.Marshal(results)
|
|
common.SendJSONResponse(w, string(jsonString))
|
|
common.SendJSONResponse(w, string(jsonString))
|
|
|
|
|
|
}
|
|
}
|