Fixed some small bugs that were still present
This commit is contained in:
@@ -5,8 +5,8 @@ COPY ./cmd/*.go /music-server/cmd/
|
||||
COPY ./cmd/swagger /music-server/cmd/swagger
|
||||
COPY ./pkg /music-server/pkg/
|
||||
|
||||
WORKDIR /music-server/
|
||||
RUN go mod download
|
||||
#WORKDIR /music-server/
|
||||
#RUN go mod download
|
||||
|
||||
WORKDIR /music-server/cmd
|
||||
|
||||
|
||||
@@ -31,19 +31,15 @@ func AddSong(song models.SongData) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckSong(path string) bool {
|
||||
query, err := pool.Query(context.Background(),
|
||||
"SELECT path FROM song WHERE path = $1", path)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "Exec failed: %v\n", err)
|
||||
}
|
||||
var result string
|
||||
err = query.Scan(&result)
|
||||
func CheckSong(songPath string) bool {
|
||||
var path string
|
||||
err := pool.QueryRow(context.Background(),
|
||||
"SELECT path FROM song WHERE path = $1", songPath).Scan(&path)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
return false
|
||||
}
|
||||
return result != ""
|
||||
println("CheckSong path", path)
|
||||
return path != ""
|
||||
}
|
||||
|
||||
func UpdateSong(songName string, fileName string, path string) {
|
||||
@@ -70,7 +66,7 @@ func FindSongsFromGame(id int) []models.SongData {
|
||||
var fileName string
|
||||
var timesPlayed int
|
||||
|
||||
err := rows.Scan(&songName, &path, ×Played)
|
||||
err := rows.Scan(&songName, &path, &fileName, ×Played)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func GetRandomSongClassic() string {
|
||||
|
||||
//Check if file exists and open
|
||||
openFile, err := os.Open(song.Path)
|
||||
if err != nil || gameData.Path+"/"+song.FileName != song.Path {
|
||||
if err != nil || gameData.Path+song.FileName != song.Path {
|
||||
//File not found
|
||||
db.RemoveBrokenSong(song)
|
||||
log.Println("Song not found, song '" + song.SongName + "' deleted from game '" + gameData.GameName + "' FileName: " + song.FileName)
|
||||
@@ -232,12 +232,21 @@ func getSongFromList(games []models.GameData) models.SongData {
|
||||
var song models.SongData
|
||||
for !songFound {
|
||||
game := getRandomGame(games)
|
||||
log.Println("game = ", game)
|
||||
songs := db.FindSongsFromGame(game.Id)
|
||||
log.Println("songs = ", songs)
|
||||
if len(songs) == 0 {
|
||||
continue
|
||||
}
|
||||
song = songs[rand.Intn(len(songs))]
|
||||
log.Println("song = ", song)
|
||||
|
||||
//Check if file exists and open
|
||||
openFile, err := os.Open(song.Path)
|
||||
if err != nil || game.Path+"/"+song.FileName != song.Path {
|
||||
log.Println("game.Path+song.FileName: ", game.Path+song.FileName)
|
||||
log.Println("song.Path: ", song.Path)
|
||||
log.Println("game.Path+song.FileName != song.Path: ", game.Path+song.FileName != song.Path)
|
||||
if err != nil || game.Path+song.FileName != song.Path {
|
||||
//File not found
|
||||
db.RemoveBrokenSong(song)
|
||||
log.Println("Song not found, song '" + song.SongName + "' deleted from game '" + game.GameName + "' FileName: " + song.FileName)
|
||||
|
||||
@@ -22,7 +22,7 @@ func SyncGames() {
|
||||
dir = "/Users/sebastian/Resilio Sync/Sorterat_test/"
|
||||
}
|
||||
fmt.Printf("dir: %s\n", dir)
|
||||
foldersToSkip := []string{".sync"}
|
||||
foldersToSkip := []string{".sync", "dist", "old"}
|
||||
fmt.Println(foldersToSkip)
|
||||
db.SetGameDeletionDate()
|
||||
checkBrokenSongs()
|
||||
@@ -127,9 +127,12 @@ func checkSongs(gameDir string, gameId int) {
|
||||
path := gameDir + entry.Name()
|
||||
fileName := entry.Name()
|
||||
songName, _ := strings.CutSuffix(fileName, ".mp3")
|
||||
println("path", path)
|
||||
if db.CheckSong(path) {
|
||||
println("db.CheckSong(path)", true)
|
||||
db.UpdateSong(songName, fileName, path)
|
||||
} else {
|
||||
println("db.CheckSong(path)", false)
|
||||
db.AddSong(models.SongData{GameId: gameId, SongName: songName, Path: path, FileName: fileName})
|
||||
}
|
||||
} else if isCoverImage(entry) {
|
||||
|
||||
Reference in New Issue
Block a user