|
@@ -2058,30 +2058,6 @@ func system_fs_specialURIEncode(inputPath string) string {
|
|
|
|
|
|
//Handle file properties request
|
|
//Handle file properties request
|
|
func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
|
|
func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
|
|
- userinfo, err := userHandler.GetUserInfoFromRequest(w, r)
|
|
|
|
- if err != nil {
|
|
|
|
- sendErrorResponse(w, err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- vpath, err := mv(r, "path", true)
|
|
|
|
- if err != nil {
|
|
|
|
- sendErrorResponse(w, "path not defined")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rpath, err := userinfo.VirtualPathToRealPath(vpath)
|
|
|
|
- if err != nil {
|
|
|
|
- sendErrorResponse(w, err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fileStat, err := os.Stat(rpath)
|
|
|
|
- if err != nil {
|
|
|
|
- sendErrorResponse(w, err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
type fileProperties struct {
|
|
type fileProperties struct {
|
|
VirtualPath string
|
|
VirtualPath string
|
|
StoragePath string
|
|
StoragePath string
|
|
@@ -2098,69 +2074,116 @@ func system_fs_getFileProperties(w http.ResponseWriter, r *http.Request) {
|
|
Owner string
|
|
Owner string
|
|
}
|
|
}
|
|
|
|
|
|
- mime := "text/directory"
|
|
|
|
- if !fileStat.IsDir() {
|
|
|
|
- m, _, err := fs.GetMime(rpath)
|
|
|
|
|
|
+ result := fileProperties{}
|
|
|
|
+
|
|
|
|
+ userinfo, err := userHandler.GetUserInfoFromRequest(w, r)
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vpath, err := mv(r, "path", true)
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendErrorResponse(w, "path not defined")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vrootID, subpath, _ := filesystem.GetIDFromVirtualPath(vpath)
|
|
|
|
+ if vrootID == "share" && subpath == "" {
|
|
|
|
+ result = fileProperties{
|
|
|
|
+ VirtualPath: vpath,
|
|
|
|
+ StoragePath: "(Emulated File System)",
|
|
|
|
+ Basename: "Share",
|
|
|
|
+ VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
|
|
|
|
+ StorageDirname: "N/A",
|
|
|
|
+ Ext: "N/A",
|
|
|
|
+ MimeType: "emulated/fs",
|
|
|
|
+ Filesize: -1,
|
|
|
|
+ Permission: "N/A",
|
|
|
|
+ LastModTime: "N/A",
|
|
|
|
+ LastModUnix: 0,
|
|
|
|
+ IsDirectory: true,
|
|
|
|
+ Owner: "system",
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ rpath, err := userinfo.VirtualPathToRealPath(vpath)
|
|
if err != nil {
|
|
if err != nil {
|
|
- mime = ""
|
|
|
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- mime = m
|
|
|
|
- }
|
|
|
|
|
|
|
|
- filesize := fileStat.Size()
|
|
|
|
- //Get file overall size if this is folder
|
|
|
|
- if fileStat.IsDir() {
|
|
|
|
- var size int64
|
|
|
|
- filepath.Walk(rpath, func(_ string, info os.FileInfo, err error) error {
|
|
|
|
|
|
+ fileStat, err := os.Stat(rpath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ sendErrorResponse(w, err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mime := "text/directory"
|
|
|
|
+ if !fileStat.IsDir() {
|
|
|
|
+ m, _, err := fs.GetMime(rpath)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return err
|
|
|
|
|
|
+ mime = ""
|
|
}
|
|
}
|
|
- if !info.IsDir() {
|
|
|
|
- size += info.Size()
|
|
|
|
- }
|
|
|
|
- return err
|
|
|
|
- })
|
|
|
|
- filesize = size
|
|
|
|
- }
|
|
|
|
|
|
+ mime = m
|
|
|
|
+ }
|
|
|
|
|
|
- //Get file owner
|
|
|
|
- owner := userinfo.GetFileOwner(rpath)
|
|
|
|
|
|
+ filesize := fileStat.Size()
|
|
|
|
+ //Get file overall size if this is folder
|
|
|
|
+ if fileStat.IsDir() {
|
|
|
|
+ var size int64
|
|
|
|
+ filepath.Walk(rpath, func(_ string, info os.FileInfo, err error) error {
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if !info.IsDir() {
|
|
|
|
+ size += info.Size()
|
|
|
|
+ }
|
|
|
|
+ return err
|
|
|
|
+ })
|
|
|
|
+ filesize = size
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Get file owner
|
|
|
|
+ owner := userinfo.GetFileOwner(rpath)
|
|
|
|
|
|
- if owner == "" {
|
|
|
|
- //Handle special virtual roots
|
|
|
|
- vrootID, subpath, _ := filesystem.GetIDFromVirtualPath(vpath)
|
|
|
|
- if vrootID == "share" {
|
|
|
|
- //Share objects
|
|
|
|
- shareOption, _ := shareEntryTable.ResolveShareOptionFromShareSubpath(subpath)
|
|
|
|
- if shareOption != nil {
|
|
|
|
- owner = shareOption.Owner
|
|
|
|
|
|
+ if owner == "" {
|
|
|
|
+ //Handle special virtual roots
|
|
|
|
+ vrootID, subpath, _ := filesystem.GetIDFromVirtualPath(vpath)
|
|
|
|
+ if vrootID == "share" {
|
|
|
|
+ //Share objects
|
|
|
|
+ shareOption, _ := shareEntryTable.ResolveShareOptionFromShareSubpath(subpath)
|
|
|
|
+ if shareOption != nil {
|
|
|
|
+ owner = shareOption.Owner
|
|
|
|
+ } else {
|
|
|
|
+ owner = "Unknown"
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
owner = "Unknown"
|
|
owner = "Unknown"
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- owner = "Unknown"
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ result = fileProperties{
|
|
|
|
+ VirtualPath: vpath,
|
|
|
|
+ StoragePath: filepath.Clean(rpath),
|
|
|
|
+ Basename: filepath.Base(rpath),
|
|
|
|
+ VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
|
|
|
|
+ StorageDirname: filepath.ToSlash(filepath.Dir(rpath)),
|
|
|
|
+ Ext: filepath.Ext(rpath),
|
|
|
|
+ MimeType: mime,
|
|
|
|
+ Filesize: filesize,
|
|
|
|
+ Permission: fileStat.Mode().Perm().String(),
|
|
|
|
+ LastModTime: timeToString(fileStat.ModTime()),
|
|
|
|
+ LastModUnix: fileStat.ModTime().Unix(),
|
|
|
|
+ IsDirectory: fileStat.IsDir(),
|
|
|
|
+ Owner: owner,
|
|
|
|
+ }
|
|
|
|
|
|
- result := fileProperties{
|
|
|
|
- VirtualPath: vpath,
|
|
|
|
- StoragePath: filepath.Clean(rpath),
|
|
|
|
- Basename: filepath.Base(rpath),
|
|
|
|
- VirtualDirname: filepath.ToSlash(filepath.Dir(vpath)),
|
|
|
|
- StorageDirname: filepath.ToSlash(filepath.Dir(rpath)),
|
|
|
|
- Ext: filepath.Ext(rpath),
|
|
|
|
- MimeType: mime,
|
|
|
|
- Filesize: filesize,
|
|
|
|
- Permission: fileStat.Mode().Perm().String(),
|
|
|
|
- LastModTime: timeToString(fileStat.ModTime()),
|
|
|
|
- LastModUnix: fileStat.ModTime().Unix(),
|
|
|
|
- IsDirectory: fileStat.IsDir(),
|
|
|
|
- Owner: owner,
|
|
|
|
}
|
|
}
|
|
|
|
|
|
jsonString, _ := json.Marshal(result)
|
|
jsonString, _ := json.Marshal(result)
|
|
sendJSONResponse(w, string(jsonString))
|
|
sendJSONResponse(w, string(jsonString))
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|