Can listen to gong on the page
This commit is contained in:
parent
8e432c9b6b
commit
7db7489b4c
3 changed files with 52 additions and 0 deletions
18
api/gongs.go
18
api/gongs.go
|
|
@ -85,6 +85,24 @@ func declareGongsRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
|||
gongsRoutes.GET("", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, c.MustGet("gong"))
|
||||
})
|
||||
gongsRoutes.GET("/stream", func(c *gin.Context) {
|
||||
gong := c.MustGet("gong").(*reveil.Gong)
|
||||
|
||||
size, err := gong.Size()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to open the gong: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
fd, err := gong.Open()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to open the gong: %s", err.Error())})
|
||||
return
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
c.DataFromReader(http.StatusOK, size, gong.ContentType(), fd, map[string]string{})
|
||||
})
|
||||
gongsRoutes.PUT("", func(c *gin.Context) {
|
||||
oldgong := c.MustGet("gong").(*reveil.Gong)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue