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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user