Compare commits

...

2 Commits

Author SHA1 Message Date
e29c7be4fa duplicate path variable parsing removed 2023-02-16 14:09:22 +01:00
10e3025ddc url decode filename 2023-02-16 14:08:01 +01:00

19
main.go
View File

@ -8,6 +8,7 @@ import (
"fmt"
"math/rand"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
@ -79,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) {
@ -140,8 +144,13 @@ func GetAllFilesHandler(w http.ResponseWriter, r *http.Request) {
}
func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) {
fileName := mux.Vars(r)["file"]
format := mux.Vars(r)["format"]
vars := mux.Vars(r)
format := vars["format"]
fileName, err := url.QueryUnescape(vars["file"])
if err != nil {
InternalServerError(w, err)
return
}
inputFilePath := filepath.Join(LibraryPath, ".songs", fileName)
outputFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("%d.%s", rand.Int(), format))