Fix: add filename when download file
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
@@ -111,6 +112,12 @@ func (api *API) HandleGetFileDirect(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// set header for filename
|
||||
filename := file.Filename
|
||||
// encode filename to URL
|
||||
filename = url.PathEscape(filename)
|
||||
w.Header().Set("Content-Disposition", "inline; filename*=UTF-8''"+filename)
|
||||
|
||||
log.Println("[api] Get direct raw file", path)
|
||||
|
||||
http.ServeFile(w, r, path)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"msw-open-music/pkg/database"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
@@ -66,6 +67,13 @@ func (api *API) HandleGetFileStream(w http.ResponseWriter, r *http.Request) {
|
||||
api.HandleErrorStringCode(w, r, `ffmpeg config not found`, 404)
|
||||
return
|
||||
}
|
||||
|
||||
// set headers for filename
|
||||
filename := file.Filename + "." + ffmpegConfig.Name + "." + ffmpegConfig.Format
|
||||
filename = url.PathEscape(filename)
|
||||
// replace invalid characters
|
||||
w.Header().Set("Content-Disposition", "inline; filename*=UTF-8''"+filename)
|
||||
|
||||
args := strings.Split(ffmpegConfig.Args, " ")
|
||||
startArgs := []string{"-threads", strconv.FormatInt(api.APIConfig.FfmpegThreads, 10), "-i", path}
|
||||
endArgs := []string{"-f", ffmpegConfig.Format, "-"}
|
||||
@@ -191,6 +199,12 @@ func (api *API) HandleGetFileStreamDirect(w http.ResponseWriter, r *http.Request
|
||||
api.Tmpfs.Record(path)
|
||||
}
|
||||
|
||||
// set headers for filename
|
||||
filename := ids[0] + "." + ffmpegConfig.Name + "." + ffmpegConfig.Format
|
||||
filename = url.PathEscape(filename)
|
||||
// replace invalid characters
|
||||
w.Header().Set("Content-Disposition", "inline; filename*=UTF-8''"+filename)
|
||||
|
||||
log.Println("[api] Get direct cached file", path)
|
||||
|
||||
http.ServeFile(w, r, path)
|
||||
|
||||
Reference in New Issue
Block a user