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

@@ -7,6 +7,8 @@ import (
"github.com/gin-gonic/gin"
"io"
"io/fs"
"music-server/pkg/db"
"music-server/pkg/models"
"net/http"
"os"
"strconv"
@@ -60,6 +62,20 @@ func EmbedFolder(fsEmbed embed.FS, targetPath string, index bool) static.ServeFi
}
}
func CheckIfSongExists(song models.SongData) bool {
//Check if file exists and open
openFile, err := os.Open(song.Path)
if err != nil {
//File not found
db.RemoveBrokenSong(song)
return false
}
defer func(openFile *os.File) {
_ = openFile.Close()
}(openFile) //Close after function return
return true
}
func SendSong(ctx *gin.Context, Filename string) {
fmt.Println("Client requests: " + Filename)