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:
2024-05-18 11:03:03 +02:00
parent 16f2e07bd1
commit a863702b22
8 changed files with 57 additions and 59 deletions

View File

@@ -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