Skip to content

Commit

Permalink
seperate path
Browse files Browse the repository at this point in the history
  • Loading branch information
TimIsOverpowered committed Oct 15, 2024
1 parent 36c8be4 commit 73e804c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func saveStreams() {
}

//set it for stream_key as well for mediamtx warmer
err = client.Rdb.Set(client.Ctx, stream.User.StreamKey, base64String, 10*time.Second).Err()
err = client.Rdb.Set(client.Ctx, stream.User.StreamKey, base64String+"_"+stream.User.Username, 10*time.Second).Err()
if err != nil {
log.Println(err)
}
Expand Down
42 changes: 41 additions & 1 deletion server/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Initalize() {
router := gin.Default()
router.SetTrustedProxies([]string{"127.0.0.1"})

router.POST("/hls/:channel/:endUrl", func(c *gin.Context) {
router.POST("/transcode/:channel/:endUrl", func(c *gin.Context) {
jwtToken, err := extractBearerToken(c.GetHeader("Authorization"))
if err != nil {
c.AbortWithStatus(500)
Expand Down Expand Up @@ -62,6 +62,46 @@ func Initalize() {
}
})

router.POST("/hls/:channel/:endUrl", func(c *gin.Context) {
jwtToken, err := extractBearerToken(c.GetHeader("Authorization"))
if err != nil {
c.AbortWithStatus(500)
return
}

if jwtToken != utils.Config.IngestAPI.AuthKey {
c.AbortWithStatus(500)
return
}

channel := c.Param("channel")
regex := regexp.MustCompile(`_src|_medium|_low`)
base64Channel := regex.ReplaceAllString(channel, "")
endUrl := c.Param("endUrl")

base64Path, err := client.Rdb.Get(client.Ctx, base64Channel).Result()
if err != nil {
c.AbortWithStatus(500)
return
}

key := base64Path + "/" + endUrl
data, _ := c.GetRawData()
if strings.HasSuffix(endUrl, ".ts") {
client.Rdb.Set(client.Ctx, key, data, 30*time.Second)
} else if strings.HasSuffix(endUrl, ".m3u8") {
client.Rdb.Set(client.Ctx, key, data, 30*time.Second)
} else if strings.HasSuffix(endUrl, "init.mp4") {
client.Rdb.Set(client.Ctx, key, data, 30*time.Second)
} else if strings.HasSuffix(endUrl, ".mp4") {
client.Rdb.Set(client.Ctx, key, data, 30*time.Second)
} else if strings.HasSuffix(endUrl, ".m4s") {
client.Rdb.Set(client.Ctx, key, data, 30*time.Second)
} else {
c.AbortWithStatus(400)
}
})

router.GET("/hls/:channel/:endUrl", func(c *gin.Context) {
channel := c.Param("channel")
endUrl := c.Param("endUrl")
Expand Down

0 comments on commit 73e804c

Please sign in to comment.