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:
1 parent
16f2e07bd1
commit
a863702b22
8 files changed
+57
-59
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user