|
@@ -55,6 +55,9 @@ func media_server_validateSourceFile(w http.ResponseWriter, r *http.Request) (st
|
|
|
|
|
|
targetfile, _ := common.Mv(r, "file", false)
|
|
targetfile, _ := common.Mv(r, "file", false)
|
|
targetfile, err = url.QueryUnescape(targetfile)
|
|
targetfile, err = url.QueryUnescape(targetfile)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
if targetfile == "" {
|
|
if targetfile == "" {
|
|
return "", errors.New("Missing paramter 'file'")
|
|
return "", errors.New("Missing paramter 'file'")
|
|
}
|
|
}
|
|
@@ -143,19 +146,31 @@ func serverMedia(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
//Serve the file
|
|
//Serve the file
|
|
if downloadMode {
|
|
if downloadMode {
|
|
- userAgent := r.Header.Get("User-Agent")
|
|
|
|
- filename := strings.ReplaceAll(url.QueryEscape(filepath.Base(realFilepath)), "+", "%20")
|
|
|
|
- //log.Println(r.Header.Get("User-Agent"))
|
|
|
|
-
|
|
|
|
- if strings.Contains(userAgent, "Safari/") {
|
|
|
|
- //This is Safari. Use speial header
|
|
|
|
- w.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(realFilepath))
|
|
|
|
- } else {
|
|
|
|
- //Fixing the header issue on Golang url encode lib problems
|
|
|
|
- w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+filename)
|
|
|
|
|
|
+ escapedRealFilepath, err := url.PathUnescape(realFilepath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ common.SendErrorResponse(w, err.Error())
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- //w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
|
|
|
+ filename := filepath.Base(escapedRealFilepath)
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ //12 Jul 2022 Update: Deprecated the browser detection logic
|
|
|
|
+ userAgent := r.Header.Get("User-Agent")
|
|
|
|
+ if strings.Contains(userAgent, "Safari/")) {
|
|
|
|
+ //This is Safari. Use speial header
|
|
|
|
+ w.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(realFilepath))
|
|
|
|
+ } else {
|
|
|
|
+ //Fixing the header issue on Golang url encode lib problems
|
|
|
|
+ w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+filename)
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
|
|
|
|
+ w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
|
|
+
|
|
|
|
+ http.ServeFile(w, r, escapedRealFilepath)
|
|
|
|
+ } else {
|
|
|
|
+ http.ServeFile(w, r, realFilepath)
|
|
}
|
|
}
|
|
|
|
|
|
- http.ServeFile(w, r, realFilepath)
|
|
|
|
}
|
|
}
|