Fix: add filename when download file
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@@ -111,6 +112,12 @@ func (api *API) HandleGetFileDirect(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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)
|
log.Println("[api] Get direct raw file", path)
|
||||||
|
|
||||||
http.ServeFile(w, r, path)
|
http.ServeFile(w, r, path)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"msw-open-music/pkg/database"
|
"msw-open-music/pkg/database"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -66,6 +67,13 @@ func (api *API) HandleGetFileStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
api.HandleErrorStringCode(w, r, `ffmpeg config not found`, 404)
|
api.HandleErrorStringCode(w, r, `ffmpeg config not found`, 404)
|
||||||
return
|
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, " ")
|
args := strings.Split(ffmpegConfig.Args, " ")
|
||||||
startArgs := []string{"-threads", strconv.FormatInt(api.APIConfig.FfmpegThreads, 10), "-i", path}
|
startArgs := []string{"-threads", strconv.FormatInt(api.APIConfig.FfmpegThreads, 10), "-i", path}
|
||||||
endArgs := []string{"-f", ffmpegConfig.Format, "-"}
|
endArgs := []string{"-f", ffmpegConfig.Format, "-"}
|
||||||
@@ -191,6 +199,12 @@ func (api *API) HandleGetFileStreamDirect(w http.ResponseWriter, r *http.Request
|
|||||||
api.Tmpfs.Record(path)
|
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)
|
log.Println("[api] Get direct cached file", path)
|
||||||
|
|
||||||
http.ServeFile(w, r, path)
|
http.ServeFile(w, r, path)
|
||||||
|
|||||||
Reference in New Issue
Block a user