Fixed some bugs with songs not found made the application crash. Now checking if song exists and if not, remove song from DB and find another one. Frontend is now decoupled from the backend.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"music-server/pkg/db"
|
||||
"music-server/pkg/helpers"
|
||||
"music-server/pkg/models"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -17,8 +18,6 @@ var songQue []models.SongData
|
||||
var lastFetched models.SongData
|
||||
|
||||
func GetSoundCheckSong() string {
|
||||
Reset()
|
||||
|
||||
files, err := ioutil.ReadDir("songs")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -51,9 +50,13 @@ func GetRandomSong() string {
|
||||
if games == nil || len(games) == 0 {
|
||||
games = db.FindAllGames()
|
||||
}
|
||||
songExists := false
|
||||
var song models.SongData
|
||||
|
||||
song := getSongFromList(games)
|
||||
|
||||
for !songExists {
|
||||
song = getSongFromList(games)
|
||||
songExists = helpers.CheckIfSongExists(song)
|
||||
}
|
||||
lastFetched = song
|
||||
return song.Path
|
||||
}
|
||||
@@ -75,8 +78,12 @@ func GetRandomSongLowChance() string {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
song := getSongFromList(listOfGames)
|
||||
songExists := false
|
||||
var song models.SongData
|
||||
for !songExists {
|
||||
song = getSongFromList(listOfGames)
|
||||
songExists = helpers.CheckIfSongExists(song)
|
||||
}
|
||||
|
||||
lastFetched = song
|
||||
return song.Path
|
||||
|
||||
Reference in New Issue
Block a user