From e29c7be4facd564ecd15f83cc0c347037e88d0b2 Mon Sep 17 00:00:00 2001 From: milarin Date: Thu, 16 Feb 2023 14:09:22 +0100 Subject: [PATCH] duplicate path variable parsing removed --- main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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