51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"git.icedream.tech/icedream/uplink/app"
|
|
"git.icedream.tech/icedream/uplink/app/servers/http"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type pluginInstance struct {
|
|
server *app.Server
|
|
}
|
|
|
|
func (instance *pluginInstance) SetServer(server *httpserver.Server) {
|
|
instance.server = server
|
|
|
|
router := instance.server.Router
|
|
router.POST("/:channel", func(ctx *gin.Context) {
|
|
channel := server.ChannelManager.Channel(ctx.Param("channel"))
|
|
if channel == nil {
|
|
ctx.Status(404)
|
|
return
|
|
}
|
|
if user, password, ok := ctx.Request.BasicAuth(); ok {
|
|
if !server.Authenticator.VerifyUsernameAndPassword(channel, user, password) {
|
|
ctx.Status(401)
|
|
return
|
|
}
|
|
} else {
|
|
ctx.Status(401)
|
|
return
|
|
}
|
|
|
|
})
|
|
|
|
router.GET("/:channel", func(ctx *gin.Context) {
|
|
channel := server.ChannelManager.Channel(ctx.Param("channel"))
|
|
if channel == nil {
|
|
ctx.Status(404)
|
|
return
|
|
}
|
|
})
|
|
|
|
router.GET("/:channel/:stream", func(ctx *gin.Context) {
|
|
channel := server.ChannelManager.Channel(ctx.Param("channel"))
|
|
if channel == nil {
|
|
ctx.Status(404)
|
|
return
|
|
}
|
|
})
|
|
}
|