diff --git a/doc/swagger.yaml b/doc/swagger.yaml index 007a14c..3af5da0 100644 --- a/doc/swagger.yaml +++ b/doc/swagger.yaml @@ -1,8 +1,8 @@ openapi: 3.0.3 info: - version: "2.1.0" + version: "2.1.3" title: "Music Server" - description: "Added /addQue to add the last received song to the songQue. Changed /rand and /rand/low to not add song to the que. Changed /next to not call /rand when the end of the que is reached, instead the last song in the que will be resent." + description: "Added a check to see if song exists before returning it, if not a new song will be picked up." contact: email: "zarnor91@gmail.com" servers: diff --git a/indexFacade.go b/indexFacade.go index 8e76ddd..3de7806 100644 --- a/indexFacade.go +++ b/indexFacade.go @@ -16,9 +16,17 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { testf() - data := VersionData{Version: "2.1.1", - Changelog: "Fixed bug where wrong song was showed as currently played.", + data := VersionData{Version: "2.1.3", + Changelog: "Added a check to see if song exists before returning it, if not a new song will be picked up.", History: []VersionData{ + { + Version: "2.1.2", + Changelog: "Added test server to swagger file.", + }, + { + Version: "2.1.1", + Changelog: "Fixed bug where wrong song was showed as currently played.", + }, { Version: "2.1.0", Changelog: "Added /addQue to add the last received song to the songQue. " + diff --git a/musicFacade.go b/musicFacade.go index 97040c6..2f3a828 100644 --- a/musicFacade.go +++ b/musicFacade.go @@ -210,11 +210,11 @@ func musicHandler(w http.ResponseWriter, r *http.Request) { } } else { s := getSong(song) - sendFile(w, s) + sendSong(w, s) } } else if r.URL.Path == "/music/first" && r.Method == http.MethodGet { song := getSoundCheckSong() - sendFile(w, song) + sendSong(w, song) } else if r.URL.Path == "/music/reset" && r.Method == http.MethodGet { reset() @@ -222,11 +222,11 @@ func musicHandler(w http.ResponseWriter, r *http.Request) { } else if r.URL.Path == "/music/rand" && r.Method == http.MethodGet { song := getRandomSong() - sendFile(w, song) + sendSong(w, song) } else if r.URL.Path == "/music/rand/low" && r.Method == http.MethodGet { chance := getRandomSongLowChance() - sendFile(w, chance) + sendSong(w, chance) } else if r.URL.Path == "/music/info" && r.Method == http.MethodGet { w.Header().Add("Content-Type", "application/json") @@ -238,11 +238,11 @@ func musicHandler(w http.ResponseWriter, r *http.Request) { } else if r.URL.Path == "/music/next" { song := getNextSong() - sendFile(w, song) + sendSong(w, song) } else if r.URL.Path == "/music/previous" { song := getPreviousSong() - sendFile(w, song) + sendSong(w, song) } else if r.URL.Path == "/music/all" && r.Method == http.MethodGet { w.Header().Add("Content-Type", "application/json") @@ -263,14 +263,14 @@ func musicHandler(w http.ResponseWriter, r *http.Request) { } } -func sendFile(writer http.ResponseWriter, Filename string) { +func sendSong(writer http.ResponseWriter, Filename string) { fmt.Println("Client requests: " + Filename) //Check if file exists and open openFile, err := os.Open(Filename) if err != nil { //File not found, send 404 - http.Error(writer, "File not found.", 404) + http.Error(writer, "Song not found.", 404) return } defer func(openFile *os.File) {