diff --git a/main.go b/main.go index 4075d0a..9db6cb2 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "io" "math/rand" "net/http" - "net/url" "os" "os/exec" "path/filepath" @@ -82,7 +81,7 @@ func GetAllHandler(w http.ResponseWriter, r *http.Request) { } func GetFileHandler(w http.ResponseWriter, r *http.Request) { - fileName, err := url.QueryUnescape(mux.Vars(r)["file"]) + fileName, err := DecodeBase64String(mux.Vars(r)["file"]) if err != nil { InternalServerError(w, err) return @@ -92,7 +91,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) { } func GetFileHashHandler(w http.ResponseWriter, r *http.Request) { - fileName, err := url.QueryUnescape(mux.Vars(r)["file"]) + fileName, err := DecodeBase64String(mux.Vars(r)["file"]) if err != nil { InternalServerError(w, err) return @@ -121,7 +120,11 @@ func GetFileHashHandler(w http.ResponseWriter, r *http.Request) { } func GetPlaylistHandler(w http.ResponseWriter, r *http.Request) { - playlistName := mux.Vars(r)["playlist"] + playlistName, err := DecodeBase64String(mux.Vars(r)["playlist"]) + if err != nil { + InternalServerError(w, err) + return + } songs, err := GetSongsByPlaylist(playlistName) if err != nil { @@ -177,7 +180,8 @@ func GetAllFilesHandler(w http.ResponseWriter, r *http.Request) { func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) format := vars["format"] - fileName, err := url.QueryUnescape(vars["file"]) + + fileName, err := DecodeBase64String(vars["file"]) if err != nil { InternalServerError(w, err) return diff --git a/utils.go b/utils.go index 2339512..101c16b 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,7 @@ package main import ( + "encoding/base64" "log" "net/http" "os" @@ -56,3 +57,12 @@ func IsHidden(entry os.DirEntry) bool { func FsEntry2Name(entry os.DirEntry) string { return entry.Name() } + +func DecodeBase64String(str string) (string, error) { + data, err := base64.StdEncoding.DecodeString(str) + return string(data), err +} + +func EncodeBase64String(str string) string { + return base64.StdEncoding.EncodeToString([]byte(str)) +}