Can listen to tracks in the browser

This commit is contained in:
nemunaire 2022-10-15 13:29:25 +02:00
parent 69ddfd48e9
commit 2bcac6edd1
3 changed files with 52 additions and 0 deletions

View file

@ -85,6 +85,24 @@ func declareTracksRoutes(cfg *config.Config, router *gin.RouterGroup) {
tracksRoutes.GET("", func(c *gin.Context) {
c.JSON(http.StatusOK, c.MustGet("track"))
})
tracksRoutes.GET("/stream", func(c *gin.Context) {
track := c.MustGet("track").(*reveil.Track)
size, err := track.Size()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to open the track: %s", err.Error())})
return
}
fd, err := track.Open()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to open the track: %s", err.Error())})
return
}
defer fd.Close()
c.DataFromReader(http.StatusOK, size, track.ContentType(), fd, map[string]string{})
})
tracksRoutes.PUT("", func(c *gin.Context) {
oldtrack := c.MustGet("track").(*reveil.Track)