Updated swagger file and version info

This commit is contained in:
2021-10-28 21:21:56 +02:00
parent a742aead0a
commit 015620add6
3 changed files with 20 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
version: "2.1.0" version: "2.1.3"
title: "Music Server" 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: contact:
email: "zarnor91@gmail.com" email: "zarnor91@gmail.com"
servers: servers:

View File

@@ -16,9 +16,17 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
testf() testf()
data := VersionData{Version: "2.1.1", data := VersionData{Version: "2.1.3",
Changelog: "Fixed bug where wrong song was showed as currently played.", Changelog: "Added a check to see if song exists before returning it, if not a new song will be picked up.",
History: []VersionData{ 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", Version: "2.1.0",
Changelog: "Added /addQue to add the last received song to the songQue. " + Changelog: "Added /addQue to add the last received song to the songQue. " +

View File

@@ -210,11 +210,11 @@ func musicHandler(w http.ResponseWriter, r *http.Request) {
} }
} else { } else {
s := getSong(song) s := getSong(song)
sendFile(w, s) sendSong(w, s)
} }
} else if r.URL.Path == "/music/first" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/first" && r.Method == http.MethodGet {
song := getSoundCheckSong() song := getSoundCheckSong()
sendFile(w, song) sendSong(w, song)
} else if r.URL.Path == "/music/reset" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/reset" && r.Method == http.MethodGet {
reset() reset()
@@ -222,11 +222,11 @@ func musicHandler(w http.ResponseWriter, r *http.Request) {
} else if r.URL.Path == "/music/rand" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/rand" && r.Method == http.MethodGet {
song := getRandomSong() song := getRandomSong()
sendFile(w, song) sendSong(w, song)
} else if r.URL.Path == "/music/rand/low" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/rand/low" && r.Method == http.MethodGet {
chance := getRandomSongLowChance() chance := getRandomSongLowChance()
sendFile(w, chance) sendSong(w, chance)
} else if r.URL.Path == "/music/info" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/info" && r.Method == http.MethodGet {
w.Header().Add("Content-Type", "application/json") 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" { } else if r.URL.Path == "/music/next" {
song := getNextSong() song := getNextSong()
sendFile(w, song) sendSong(w, song)
} else if r.URL.Path == "/music/previous" { } else if r.URL.Path == "/music/previous" {
song := getPreviousSong() song := getPreviousSong()
sendFile(w, song) sendSong(w, song)
} else if r.URL.Path == "/music/all" && r.Method == http.MethodGet { } else if r.URL.Path == "/music/all" && r.Method == http.MethodGet {
w.Header().Add("Content-Type", "application/json") 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) fmt.Println("Client requests: " + Filename)
//Check if file exists and open //Check if file exists and open
openFile, err := os.Open(Filename) openFile, err := os.Open(Filename)
if err != nil { if err != nil {
//File not found, send 404 //File not found, send 404
http.Error(writer, "File not found.", 404) http.Error(writer, "Song not found.", 404)
return return
} }
defer func(openFile *os.File) { defer func(openFile *os.File) {