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

@@ -109,28 +109,20 @@ func addNewGame(name string, path string) {
}
func checkSongs(gameDir string, gameId int) {
songs := make([]models.SongData, 0)
findSongsFromGame := db.FindSongsFromGame(gameId)
files, err := ioutil.ReadDir(gameDir)
if err != nil {
log.Println(err)
}
db.ClearSongs(gameId)
for _, entry := range files {
path := gameDir + entry.Name()
fileName := entry.Name()
if isSong(entry) {
songs = append(songs, models.SongData{GameId: gameId, SongName: fileName, Path: path})
db.AddSong(models.SongData{GameId: gameId, SongName: fileName, Path: path})
} else if isCoverImage(entry) {
//TODO: Later add cover art image here in db
}
}
if len(songs) != len(findSongsFromGame) {
db.ClearSongs(gameId)
for _, song := range songs {
db.AddSong(song)
}
}
//TODO: Add number of songs here
}