|
@@ -109,7 +109,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
} else if len(subpathElements) >= 3 {
|
|
|
- //E.g. /share/{id}/myfile.txt => Enter download mode
|
|
|
+ //E.g. /share/download/{uuid} or /share/preview/{uuid}
|
|
|
id = subpathElements[2]
|
|
|
if subpathElements[1] == "download" {
|
|
|
directDownload = true
|
|
@@ -121,9 +121,23 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
} else if subpathElements[1] == "preview" {
|
|
|
directServe = true
|
|
|
}
|
|
|
+ } else if len(subpathElements) == 1 {
|
|
|
+ //ID is missing. Serve the id input page
|
|
|
+ content, err := ioutil.ReadFile("system/share/index.html")
|
|
|
+ if err != nil {
|
|
|
+ //Handling index not found. Is server updated correctly?
|
|
|
+ w.WriteHeader(http.StatusInternalServerError)
|
|
|
+ w.Write([]byte("500 - Internal Server Error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- log.Println(len(subpathElements[3:]), subpathElements[3:], relpath)
|
|
|
+ t := fasttemplate.New(string(content), "{{", "}}")
|
|
|
+ s := t.ExecuteString(map[string]interface{}{
|
|
|
+ "hostname": s.options.HostName,
|
|
|
+ })
|
|
|
|
|
|
+ w.Write([]byte(s))
|
|
|
+ return
|
|
|
} else {
|
|
|
http.NotFound(w, r)
|
|
|
return
|
|
@@ -160,7 +174,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
if shareOption.Permission == "anyone" {
|
|
|
//OK to proceed
|
|
|
} else if shareOption.Permission == "signedin" {
|
|
|
- if s.options.AuthAgent.CheckAuth(r) == false {
|
|
|
+ if !s.options.AuthAgent.CheckAuth(r) {
|
|
|
//Redirect to login page
|
|
|
if directDownload || directServe {
|
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
@@ -288,7 +302,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
Filesize string
|
|
|
IsDir bool
|
|
|
}
|
|
|
- if directDownload == true {
|
|
|
+ if directDownload {
|
|
|
if relpath != "" {
|
|
|
//User specified a specific file within the directory. Escape the relpath
|
|
|
targetFilepath := filepath.Join(shareOption.FileRealPath, relpath)
|
|
@@ -342,6 +356,11 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
http.ServeFile(w, r, targetZipFilename)
|
|
|
}
|
|
|
|
|
|
+ } else if directServe {
|
|
|
+ //Folder provide no direct serve method.
|
|
|
+ w.WriteHeader(http.StatusBadRequest)
|
|
|
+ w.Write([]byte("400 - Cannot preview folder type shares"))
|
|
|
+ return
|
|
|
} else {
|
|
|
//Show download page. Do not allow serving
|
|
|
content, err := ioutil.ReadFile("./system/share/downloadPageFolder.html")
|
|
@@ -389,6 +408,12 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
return nil
|
|
|
})
|
|
|
|
|
|
+ if err != nil {
|
|
|
+ w.WriteHeader(http.StatusInternalServerError)
|
|
|
+ w.Write([]byte("500 - Internal Server Error"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
tl, _ := json.Marshal(treeList)
|
|
|
|
|
|
//Get modification time
|
|
@@ -415,6 +440,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
+ //This share is a file
|
|
|
if directDownload {
|
|
|
//Serve the file directly
|
|
|
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+strings.ReplaceAll(url.QueryEscape(filepath.Base(shareOption.FileRealPath)), "+", "%20"))
|
|
@@ -441,7 +467,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
//Load the preview template
|
|
|
templateRoot := "./system/share/"
|
|
|
- previewTemplate := filepath.Join(templateRoot, "defaultTemplate.html")
|
|
|
+ previewTemplate := ""
|
|
|
if ext == ".mp4" || ext == ".webm" {
|
|
|
previewTemplate = filepath.Join(templateRoot, "video.html")
|
|
|
} else if ext == ".mp3" || ext == ".wav" || ext == ".flac" || ext == ".ogg" {
|
|
@@ -470,8 +496,6 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
fmodtime, _ := filesystem.GetModTime(shareOption.FileRealPath)
|
|
|
timeString := time.Unix(fmodtime, 0).Format("02-01-2006 15:04:05")
|
|
|
|
|
|
- downloadURI := "../../share/download/" + id + "/" + filepath.Base(shareOption.FileRealPath)
|
|
|
-
|
|
|
//Check if ext match with filepath ext
|
|
|
displayExt := ext
|
|
|
if ext != filepath.Ext(shareOption.FileRealPath) {
|
|
@@ -485,8 +509,8 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
"ext": displayExt,
|
|
|
"size": filesystem.GetFileDisplaySize(fsize, 2),
|
|
|
"modtime": timeString,
|
|
|
- "downloadurl": downloadURI,
|
|
|
- "preview_url": "/share/preview/?id=" + id + "&serve=true",
|
|
|
+ "downloadurl": "../../share/download/" + id + "/" + filepath.Base(shareOption.FileRealPath),
|
|
|
+ "preview_url": "/share/preview/" + id + "/",
|
|
|
"filename": filepath.Base(shareOption.FileRealPath),
|
|
|
"reqtime": strconv.Itoa(int(time.Now().Unix())),
|
|
|
})
|