diff --git a/main.go b/main.go index d036229..08e2756 100644 --- a/main.go +++ b/main.go @@ -80,10 +80,13 @@ func GetAllHandler(w http.ResponseWriter, r *http.Request) { } func GetFileHandler(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - file := vars["file"] + fileName, err := url.QueryUnescape(mux.Vars(r)["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) { @@ -141,8 +144,9 @@ func GetAllFilesHandler(w http.ResponseWriter, r *http.Request) { } func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) { - format := mux.Vars(r)["format"] - fileName, err := url.QueryUnescape(mux.Vars(r)["file"]) + vars := mux.Vars(r) + format := vars["format"] + fileName, err := url.QueryUnescape(vars["file"]) if err != nil { InternalServerError(w, err) return