|
@@ -26,7 +26,7 @@ import (
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
"imuslab.com/arozos/mod/auth"
|
|
|
"imuslab.com/arozos/mod/database"
|
|
|
- fs "imuslab.com/arozos/mod/filesystem"
|
|
|
+ filesystem "imuslab.com/arozos/mod/filesystem"
|
|
|
"imuslab.com/arozos/mod/user"
|
|
|
)
|
|
|
|
|
@@ -252,7 +252,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
targetZipFilename := filepath.Join(tmpFolder, filepath.Base(shareOption.FileRealPath)) + ".zip"
|
|
|
|
|
|
//Build a filelist
|
|
|
- err := fs.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
|
|
|
+ err := filesystem.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
|
|
|
if err != nil {
|
|
|
//Failed to create zip file
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
@@ -275,33 +275,62 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Get file size
|
|
|
- fsize, fcount := fs.GetDirctorySize(shareOption.FileRealPath, false)
|
|
|
+ fsize, fcount := filesystem.GetDirctorySize(shareOption.FileRealPath, false)
|
|
|
|
|
|
//Build the filelist of the root folder
|
|
|
- rawFilelist, _ := fs.WGlob(filepath.Clean(shareOption.FileRealPath) + "/*")
|
|
|
+ rawFilelist, _ := filesystem.WGlob(filepath.Clean(shareOption.FileRealPath) + "/*")
|
|
|
|
|
|
rootVisableFiles := []File{}
|
|
|
for _, file := range rawFilelist {
|
|
|
if filepath.Base(file)[:1] != "." {
|
|
|
//Not hidden folder.
|
|
|
- fileSize := fs.GetFileSize(file)
|
|
|
- if fs.IsDir(file) {
|
|
|
- fileSize, _ = fs.GetDirctorySize(file, false)
|
|
|
+ fileSize := filesystem.GetFileSize(file)
|
|
|
+ if filesystem.IsDir(file) {
|
|
|
+ fileSize, _ = filesystem.GetDirctorySize(file, false)
|
|
|
}
|
|
|
|
|
|
rootVisableFiles = append(rootVisableFiles, File{
|
|
|
Filename: filepath.Base(file),
|
|
|
RelPath: "/",
|
|
|
- Filesize: fs.GetFileDisplaySize(fileSize, 2),
|
|
|
- IsDir: fs.IsDir(file),
|
|
|
+ Filesize: filesystem.GetFileDisplaySize(fileSize, 2),
|
|
|
+ IsDir: filesystem.IsDir(file),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Build the tree list of the folder
|
|
|
+ treeList := []File{}
|
|
|
+ err = filepath.Walk(filepath.Clean(shareOption.FileRealPath), func(file string, info os.FileInfo, err error) error {
|
|
|
+ if err != nil {
|
|
|
+ //If error skip this
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if filepath.Base(file)[:1] != "." {
|
|
|
+ fileSize := filesystem.GetFileSize(file)
|
|
|
+ if filesystem.IsDir(file) {
|
|
|
+ fileSize, _ = filesystem.GetDirctorySize(file, false)
|
|
|
+ }
|
|
|
+
|
|
|
+ relPath, err := filepath.Rel(shareOption.FileRealPath, file)
|
|
|
+ if err != nil {
|
|
|
+ relPath = "/"
|
|
|
+ }
|
|
|
+
|
|
|
+ treeList = append(treeList, File{
|
|
|
+ Filename: filepath.Base(file),
|
|
|
+ RelPath: filepath.ToSlash(relPath),
|
|
|
+ Filesize: filesystem.GetFileDisplaySize(fileSize, 2),
|
|
|
+ IsDir: filesystem.IsDir(file),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+
|
|
|
js, _ := json.Marshal(rootVisableFiles)
|
|
|
+ tl, _ := json.Marshal(treeList)
|
|
|
|
|
|
//Get modification time
|
|
|
- fmodtime, _ := fs.GetModTime(shareOption.FileRealPath)
|
|
|
+ fmodtime, _ := filesystem.GetModTime(shareOption.FileRealPath)
|
|
|
timeString := time.Unix(fmodtime, 0).Format("02-01-2006 15:04:05")
|
|
|
|
|
|
t := fasttemplate.New(string(content), "{{", "}}")
|
|
@@ -309,13 +338,14 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
"hostname": s.options.HostName,
|
|
|
"reqid": id,
|
|
|
"mime": "application/x-directory",
|
|
|
- "size": fs.GetFileDisplaySize(fsize, 2),
|
|
|
+ "size": filesystem.GetFileDisplaySize(fsize, 2),
|
|
|
"filecount": strconv.Itoa(fcount),
|
|
|
"modtime": timeString,
|
|
|
"downloadurl": "/share?id=" + id + "&download=true",
|
|
|
"filename": filepath.Base(shareOption.FileRealPath),
|
|
|
"reqtime": strconv.Itoa(int(time.Now().Unix())),
|
|
|
"filelist": js,
|
|
|
+ "treelist": tl,
|
|
|
})
|
|
|
|
|
|
w.Write([]byte(s))
|
|
@@ -340,7 +370,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
//Get file mime type
|
|
|
- mime, ext, err := fs.GetMime(shareOption.FileRealPath)
|
|
|
+ mime, ext, err := filesystem.GetMime(shareOption.FileRealPath)
|
|
|
if err != nil {
|
|
|
mime = "Unknown"
|
|
|
}
|
|
@@ -370,10 +400,10 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
content = []byte(strings.ReplaceAll(string(content), "{{previewer}}", string(tp)))
|
|
|
|
|
|
//Get file size
|
|
|
- fsize := fs.GetFileSize(shareOption.FileRealPath)
|
|
|
+ fsize := filesystem.GetFileSize(shareOption.FileRealPath)
|
|
|
|
|
|
//Get modification time
|
|
|
- fmodtime, _ := fs.GetModTime(shareOption.FileRealPath)
|
|
|
+ fmodtime, _ := filesystem.GetModTime(shareOption.FileRealPath)
|
|
|
timeString := time.Unix(fmodtime, 0).Format("02-01-2006 15:04:05")
|
|
|
|
|
|
t := fasttemplate.New(string(content), "{{", "}}")
|
|
@@ -382,7 +412,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
"reqid": id,
|
|
|
"mime": mime,
|
|
|
"ext": ext,
|
|
|
- "size": fs.GetFileDisplaySize(fsize, 2),
|
|
|
+ "size": filesystem.GetFileDisplaySize(fsize, 2),
|
|
|
"modtime": timeString,
|
|
|
"downloadurl": "/share?id=" + id + "&download=true",
|
|
|
"preview_url": "/share?id=" + id + "&serve=true",
|