duplicate path variable parsing removed

This commit is contained in:
milarin 2023-02-16 14:09:22 +01:00
parent 10e3025ddc
commit e29c7be4fa

14
main.go
View File

@ -80,10 +80,13 @@ func GetAllHandler(w http.ResponseWriter, r *http.Request) {
} }
func GetFileHandler(w http.ResponseWriter, r *http.Request) { func GetFileHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) fileName, err := url.QueryUnescape(mux.Vars(r)["file"])
file := vars["file"] if err != nil {
InternalServerError(w, err)
return
}
http.ServeFile(w, r, filepath.Join(LibraryPath, ".songs", file)) http.ServeFile(w, r, filepath.Join(LibraryPath, ".songs", fileName))
} }
func GetPlaylistHandler(w http.ResponseWriter, r *http.Request) { func GetPlaylistHandler(w http.ResponseWriter, r *http.Request) {
@ -141,8 +144,9 @@ func GetAllFilesHandler(w http.ResponseWriter, r *http.Request) {
} }
func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) { func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) {
format := mux.Vars(r)["format"] vars := mux.Vars(r)
fileName, err := url.QueryUnescape(mux.Vars(r)["file"]) format := vars["format"]
fileName, err := url.QueryUnescape(vars["file"])
if err != nil { if err != nil {
InternalServerError(w, err) InternalServerError(w, err)
return return