|
@@ -20,6 +20,7 @@ import (
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
|
"math"
|
|
|
+ "mime"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
"os"
|
|
@@ -681,17 +682,25 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
} else {
|
|
|
//This share is a file
|
|
|
+ contentType := mime.TypeByExtension(filepath.Ext(fileRuntimeAbsPath))
|
|
|
if directDownload {
|
|
|
//Serve the file directly
|
|
|
w.Header().Set("Content-Disposition", "attachment; filename=\""+filepath.Base(shareOption.FileVirtualPath)+"\"")
|
|
|
- w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
- f, _ := targetFshAbs.ReadStream(fileRuntimeAbsPath)
|
|
|
- io.Copy(w, f)
|
|
|
- f.Close()
|
|
|
+ w.Header().Set("Content-Type", contentType)
|
|
|
+ w.Header().Set("Content-Length", strconv.Itoa(int(targetFshAbs.GetFileSize(fileRuntimeAbsPath))))
|
|
|
+
|
|
|
+ if targetFsh.RequireBuffer {
|
|
|
+ f, _ := targetFshAbs.ReadStream(fileRuntimeAbsPath)
|
|
|
+ io.Copy(w, f)
|
|
|
+ f.Close()
|
|
|
+ } else {
|
|
|
+ http.ServeFile(w, r, fileRuntimeAbsPath)
|
|
|
+ }
|
|
|
+
|
|
|
} else if directServe {
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
|
- w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
+ w.Header().Set("Content-Type", contentType)
|
|
|
f, _ := targetFshAbs.ReadStream(fileRuntimeAbsPath)
|
|
|
io.Copy(w, f)
|
|
|
f.Close()
|
|
@@ -755,7 +764,7 @@ func (s *Manager) HandleShareAccess(w http.ResponseWriter, r *http.Request) {
|
|
|
"ext": displayExt,
|
|
|
"size": filesystem.GetFileDisplaySize(fsize, 2),
|
|
|
"modtime": timeString,
|
|
|
- "downloadurl": "../../share/download/" + id + "/" + filepath.Base(fileRuntimeAbsPath),
|
|
|
+ "downloadurl": "/share/download/" + id + "/" + filepath.Base(fileRuntimeAbsPath),
|
|
|
"preview_url": "/share/preview/" + id + "/",
|
|
|
"filename": filepath.Base(fileRuntimeAbsPath),
|
|
|
"opg_image": "/share/opg/" + strconv.Itoa(int(time.Now().Unix())) + "/" + id,
|