|
@@ -277,29 +277,8 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
//Get file size
|
|
|
fsize, fcount := filesystem.GetDirctorySize(shareOption.FileRealPath, false)
|
|
|
|
|
|
- //Build the filelist of the root folder
|
|
|
- rawFilelist, _ := filesystem.WGlob(filepath.Clean(shareOption.FileRealPath) + "/*")
|
|
|
-
|
|
|
- rootVisableFiles := []File{}
|
|
|
- for _, file := range rawFilelist {
|
|
|
- if filepath.Base(file)[:1] != "." {
|
|
|
- //Not hidden folder.
|
|
|
- fileSize := filesystem.GetFileSize(file)
|
|
|
- if filesystem.IsDir(file) {
|
|
|
- fileSize, _ = filesystem.GetDirctorySize(file, false)
|
|
|
- }
|
|
|
-
|
|
|
- rootVisableFiles = append(rootVisableFiles, File{
|
|
|
- Filename: filepath.Base(file),
|
|
|
- RelPath: "/",
|
|
|
- Filesize: filesystem.GetFileDisplaySize(fileSize, 2),
|
|
|
- IsDir: filesystem.IsDir(file),
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
//Build the tree list of the folder
|
|
|
- treeList := []File{}
|
|
|
+ treeList := map[string][]File{}
|
|
|
err = filepath.Walk(filepath.Clean(shareOption.FileRealPath), func(file string, info os.FileInfo, err error) error {
|
|
|
if err != nil {
|
|
|
//If error skip this
|
|
@@ -313,10 +292,18 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
relPath, err := filepath.Rel(shareOption.FileRealPath, file)
|
|
|
if err != nil {
|
|
|
- relPath = "/"
|
|
|
+ relPath = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ relPath = filepath.ToSlash(filepath.Clean(relPath))
|
|
|
+ relDir := filepath.ToSlash(filepath.Dir(relPath))
|
|
|
+
|
|
|
+ if relPath == "." {
|
|
|
+ //The root file object. Skip this
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
- treeList = append(treeList, File{
|
|
|
+ treeList[relDir] = append(treeList[relDir], File{
|
|
|
Filename: filepath.Base(file),
|
|
|
RelPath: filepath.ToSlash(relPath),
|
|
|
Filesize: filesystem.GetFileDisplaySize(fileSize, 2),
|
|
@@ -326,7 +313,6 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
return nil
|
|
|
})
|
|
|
|
|
|
- js, _ := json.Marshal(rootVisableFiles)
|
|
|
tl, _ := json.Marshal(treeList)
|
|
|
|
|
|
//Get modification time
|
|
@@ -344,7 +330,6 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
"downloadurl": "/share?id=" + id + "&download=true",
|
|
|
"filename": filepath.Base(shareOption.FileRealPath),
|
|
|
"reqtime": strconv.Itoa(int(time.Now().Unix())),
|
|
|
- "filelist": js,
|
|
|
"treelist": tl,
|
|
|
})
|
|
|
|