|
@@ -39,6 +39,8 @@ func mediaServer_init() {
|
|
http.HandleFunc("/media/getMime/", serveMediaMime)
|
|
http.HandleFunc("/media/getMime/", serveMediaMime)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Download API always bypass gzip no matter if gzip mode is enabled
|
|
|
|
+ http.HandleFunc("/media/download/", serverMedia)
|
|
}
|
|
}
|
|
|
|
|
|
//This function validate the incoming media request and return the real path for the targed file
|
|
//This function validate the incoming media request and return the real path for the targed file
|
|
@@ -138,6 +140,11 @@ func serverMedia(w http.ResponseWriter, r *http.Request) {
|
|
downloadMode = true
|
|
downloadMode = true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //New download implementations, allow /download to be used instead of &download=true
|
|
|
|
+ if strings.Contains(r.RequestURI, "media/download/?file=") {
|
|
|
|
+ downloadMode = true
|
|
|
|
+ }
|
|
|
|
+
|
|
//Serve the file
|
|
//Serve the file
|
|
if downloadMode {
|
|
if downloadMode {
|
|
userAgent := r.Header.Get("User-Agent")
|
|
userAgent := r.Header.Get("User-Agent")
|
|
@@ -152,14 +159,6 @@ func serverMedia(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+filename)
|
|
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+filename)
|
|
}
|
|
}
|
|
//w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
//w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
|
-
|
|
|
|
- //Serve content length by trying to get filesize
|
|
|
|
- /*
|
|
|
|
- fi, err := os.Stat(filepath.Clean(realFilepath))
|
|
|
|
- if err == nil {
|
|
|
|
- w.Header().Set("Content-Length", strconv.Itoa(int(fi.Size())))
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
}
|
|
}
|
|
|
|
|
|
http.ServeFile(w, r, realFilepath)
|
|
http.ServeFile(w, r, realFilepath)
|