Upgraded Go version and the version of all dependencies. Fixed som more bugs.

This commit is contained in:
2024-05-18 13:11:15 +02:00
parent a863702b22
commit 59f1e2c75c
11 changed files with 227 additions and 1111 deletions

View File

@@ -10,9 +10,13 @@ func TestDB() {
}
func GetVersionHistory() models.VersionData {
data := models.VersionData{Version: "3.1",
Changelog: "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.",
data := models.VersionData{Version: "3.2",
Changelog: "Upgraded Go version and the version of all dependencies. Fixed som more bugs.",
History: []models.VersionData{
{
Version: "3.1",
Changelog: "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.",
},
{
Version: "3.0",
Changelog: "Changed routing framework from mux to Gin. Swagger doc is now included in the application. A fronted can now be hosted from the application.",

View File

@@ -1,15 +1,12 @@
package server
import (
"io/ioutil"
"log"
"math/rand"
"music-server/pkg/db"
"music-server/pkg/helpers"
"music-server/pkg/models"
"os"
"strconv"
"time"
)
var currentSong = -1
@@ -18,7 +15,7 @@ var songQue []models.SongData
var lastFetched models.SongData
func GetSoundCheckSong() string {
files, err := ioutil.ReadDir("songs")
files, err := os.ReadDir("songs")
if err != nil {
log.Fatal(err)
}
@@ -50,13 +47,8 @@ func GetRandomSong() string {
if games == nil || len(games) == 0 {
games = db.FindAllGames()
}
songExists := false
var song models.SongData
for !songExists {
song = getSongFromList(games)
songExists = helpers.CheckIfSongExists(song)
}
song := getSongFromList(games)
lastFetched = song
return song.Path
}
@@ -78,12 +70,7 @@ func GetRandomSongLowChance() string {
}
}
}
songExists := false
var song models.SongData
for !songExists {
song = getSongFromList(listOfGames)
songExists = helpers.CheckIfSongExists(song)
}
song := getSongFromList(games)
lastFetched = song
return song.Path
@@ -157,7 +144,6 @@ func GetAllGamesRandom() []string {
for _, game := range games {
jsonArray = append(jsonArray, game.GameName)
}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(jsonArray), func(i, j int) { jsonArray[i], jsonArray[j] = jsonArray[j], jsonArray[i] })
return jsonArray
}
@@ -212,7 +198,7 @@ func getSongFromList(games []models.GameData) models.SongData {
if err != nil {
//File not found
db.RemoveBrokenSong(song)
log.Fatal("Song not found, song '" + song.SongName + "' deleted from game '" + game.GameName + "' songPath: " + song.Path)
log.Println("Song not found, song '" + song.SongName + "' deleted from game '" + game.GameName + "' songPath: " + song.Path)
} else {
songFound = true
}

View File

@@ -3,7 +3,6 @@ package server
import (
"fmt"
"io/fs"
"io/ioutil"
"log"
"music-server/pkg/db"
"music-server/pkg/models"
@@ -27,7 +26,7 @@ func SyncGames() {
db.SetGameDeletionDate()
checkBrokenSongs()
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
log.Fatal(err)
}
@@ -38,13 +37,17 @@ func SyncGames() {
path := dir + file.Name() + "/"
fmt.Println(path)
innerFiles, err := ioutil.ReadDir(path)
entries, err := os.ReadDir(path)
if err != nil {
log.Println(err)
}
id := -1
for _, song := range innerFiles {
id = getIdFromFile(song)
for _, entry := range entries {
fileInfo, err := entry.Info()
if err != nil {
log.Println(err)
}
id = getIdFromFile(fileInfo)
if id != -1 {
break
}
@@ -87,6 +90,7 @@ func checkIfChanged(id int, name string, path string) {
} else if name != nameFromDb {
fmt.Println("Diff name")
db.UpdateGameName(id, name, path)
checkBrokenSongs()
}
db.RemoveDeletionDate(id)
}
@@ -101,7 +105,7 @@ func addNewGame(name string, path string) {
fileName := path + "/." + strconv.Itoa(newId) + ".id"
fmt.Printf("fileName = %v", fileName)
err := ioutil.WriteFile(fileName, nil, 0644)
err := os.WriteFile(fileName, nil, 0644)
if err != nil {
panic(err)
}
@@ -109,12 +113,15 @@ func addNewGame(name string, path string) {
}
func checkSongs(gameDir string, gameId int) {
files, err := ioutil.ReadDir(gameDir)
files, err := os.ReadDir(gameDir)
if err != nil {
log.Println(err)
}
db.ClearSongs(gameId)
for _, entry := range files {
for _, file := range files {
entry, err := file.Info()
if err != nil {
log.Println(err)
}
path := gameDir + entry.Name()
fileName := entry.Name()
if isSong(entry) {