|
@@ -103,6 +103,8 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
directServe = true
|
|
|
}
|
|
|
|
|
|
+ relpath, _ := mv(r, "rel", false)
|
|
|
+
|
|
|
//Check if id exists
|
|
|
val, ok := s.urlToFileMap.Load(id)
|
|
|
if ok {
|
|
@@ -242,29 +244,35 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
IsDir bool
|
|
|
}
|
|
|
if directDownload == true {
|
|
|
- //Download this folder as zip
|
|
|
- //Build the filelist to download
|
|
|
+ if relpath != "" {
|
|
|
+ //User specified a specific file within the directory. Escape the relpath
|
|
|
+ log.Println(shareOption.FileRealPath, relpath)
|
|
|
+ sendOK(w)
|
|
|
+ } else {
|
|
|
+ //Download this folder as zip
|
|
|
+ //Build the filelist to download
|
|
|
|
|
|
- //Create a zip using ArOZ Zipper, tmp zip files are located under tmp/share-cache/*.zip
|
|
|
- tmpFolder := s.options.TmpFolder
|
|
|
- tmpFolder = filepath.Join(tmpFolder, "share-cache")
|
|
|
- os.MkdirAll(tmpFolder, 0755)
|
|
|
- targetZipFilename := filepath.Join(tmpFolder, filepath.Base(shareOption.FileRealPath)) + ".zip"
|
|
|
+ //Create a zip using ArOZ Zipper, tmp zip files are located under tmp/share-cache/*.zip
|
|
|
+ tmpFolder := s.options.TmpFolder
|
|
|
+ tmpFolder = filepath.Join(tmpFolder, "share-cache")
|
|
|
+ os.MkdirAll(tmpFolder, 0755)
|
|
|
+ targetZipFilename := filepath.Join(tmpFolder, filepath.Base(shareOption.FileRealPath)) + ".zip"
|
|
|
|
|
|
- //Build a filelist
|
|
|
- err := filesystem.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
|
|
|
- if err != nil {
|
|
|
- //Failed to create zip file
|
|
|
- w.WriteHeader(http.StatusInternalServerError)
|
|
|
- w.Write([]byte("500 - Internal Server Error: Zip file creation failed"))
|
|
|
- log.Println("Failed to create zip file for share download: " + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
+ //Build a filelist
|
|
|
+ err := filesystem.ArozZipFile([]string{shareOption.FileRealPath}, targetZipFilename, false)
|
|
|
+ if err != nil {
|
|
|
+ //Failed to create zip file
|
|
|
+ w.WriteHeader(http.StatusInternalServerError)
|
|
|
+ w.Write([]byte("500 - Internal Server Error: Zip file creation failed"))
|
|
|
+ log.Println("Failed to create zip file for share download: " + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- //Serve thje zip file
|
|
|
- w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+strings.ReplaceAll(url.QueryEscape(filepath.Base(shareOption.FileRealPath)), "+", "%20")+".zip")
|
|
|
- w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
- http.ServeFile(w, r, targetZipFilename)
|
|
|
+ //Serve thje zip file
|
|
|
+ w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+strings.ReplaceAll(url.QueryEscape(filepath.Base(shareOption.FileRealPath)), "+", "%20")+".zip")
|
|
|
+ w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
+ http.ServeFile(w, r, targetZipFilename)
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
//Show download page. Do not allow serving
|