Fixed some bugs
Images should not be included in the database Removes songs where the path doesn't work Started working on adding cover images Started adding vue directly in the application
This commit is contained in:
@@ -8,9 +8,13 @@ import (
|
||||
func GetVersionHistory() models.VersionData {
|
||||
db.Testf()
|
||||
|
||||
data := models.VersionData{Version: "2.2.0",
|
||||
Changelog: "Changed the structure of the whole application, should be no changes to functionality.",
|
||||
data := models.VersionData{Version: "2.3.0",
|
||||
Changelog: "Images should not be included in the database, removes songs where the path doesn't work.",
|
||||
History: []models.VersionData{
|
||||
{
|
||||
Version: "2.2.0",
|
||||
Changelog: "Changed the structure of the whole application, should be no changes to functionality.",
|
||||
},
|
||||
{
|
||||
Version: "2.1.4",
|
||||
Changelog: "Game list should now be sorted, a new endpoint with the game list in random order have been added.",
|
||||
|
||||
@@ -198,7 +198,8 @@ func getSongFromList(games []models.GameData) models.SongData {
|
||||
openFile, err := os.Open(song.Path)
|
||||
if err != nil {
|
||||
//File not found
|
||||
log.Fatal("Song not found, maybe delete song and/or game" + song.SongName + " songPath: " + song.Path)
|
||||
db.RemoveBrokenSong(song)
|
||||
log.Fatal("Song not found, song '" + song.SongName + "' deleted from game '" + game.GameName + "' songPath: " + song.Path)
|
||||
} else {
|
||||
songFound = true
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"music-server/pkg/db"
|
||||
@@ -24,6 +25,7 @@ func SyncGames() {
|
||||
foldersToSkip := []string{".sync"}
|
||||
fmt.Println(foldersToSkip)
|
||||
db.SetGameDeletionDate()
|
||||
checkBrokenSongs()
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
@@ -116,9 +118,11 @@ func checkSongs(gameDir string, gameId int) {
|
||||
}
|
||||
for _, entry := range files {
|
||||
path := gameDir + entry.Name()
|
||||
songName := entry.Name()
|
||||
if !entry.IsDir() && !strings.HasSuffix(songName, ".id") {
|
||||
songs = append(songs, models.SongData{GameId: gameId, SongName: songName, Path: path})
|
||||
fileName := entry.Name()
|
||||
if isSong(entry) {
|
||||
songs = append(songs, 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) {
|
||||
@@ -127,6 +131,34 @@ func checkSongs(gameDir string, gameId int) {
|
||||
db.AddSong(song)
|
||||
}
|
||||
}
|
||||
//TODO: Add number of songs here
|
||||
}
|
||||
|
||||
func checkBrokenSongs() {
|
||||
allSongs := db.FetchAllSongs()
|
||||
var brokenSongs []models.SongData
|
||||
for _, song := range allSongs {
|
||||
//Check if file exists and open
|
||||
openFile, err := os.Open(song.Path)
|
||||
if err != nil {
|
||||
//File not found
|
||||
brokenSongs = append(brokenSongs, song)
|
||||
}
|
||||
err = openFile.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
db.RemoveBrokenSongs(brokenSongs)
|
||||
}
|
||||
|
||||
func isSong(entry fs.FileInfo) bool {
|
||||
return !entry.IsDir() && strings.HasSuffix(entry.Name(), ".mp3") || strings.HasSuffix(entry.Name(), ".wav")
|
||||
}
|
||||
|
||||
func isCoverImage(entry fs.FileInfo) bool {
|
||||
return !entry.IsDir() && strings.Contains(entry.Name(), "cover") &&
|
||||
(strings.HasSuffix(entry.Name(), ".jpg") || strings.HasSuffix(entry.Name(), ".png"))
|
||||
}
|
||||
|
||||
func contains(s []string, searchTerm string) bool {
|
||||
|
||||
Reference in New Issue
Block a user