uplink/plugins/icecast/input/instance.go

49 lines
1.2 KiB
Go
Raw Normal View History

package icecast_input
2018-04-10 14:34:41 +00:00
2018-04-10 15:08:40 +00:00
import (
"io"
"git.icedream.tech/icedream/uplink/app/authentication"
"git.icedream.tech/icedream/uplink/app/channels"
2018-04-10 15:08:40 +00:00
"git.icedream.tech/icedream/uplink/app/servers/http"
"github.com/gin-gonic/gin"
)
2018-04-10 14:34:41 +00:00
type pluginInstance struct {
server *httpserver.Server
authenticator authentication.Authenticator
channelManager *channels.ChannelManager
}
func (instance *pluginInstance) SetAuthenticator(authenticator authentication.Authenticator) {
instance.authenticator = authenticator
}
func (instance *pluginInstance) SetChannelManager(channelManager *channels.ChannelManager) {
instance.channelManager = channelManager
2018-04-10 14:34:41 +00:00
}
2018-04-10 15:08:40 +00:00
func (instance *pluginInstance) SetServer(server *httpserver.Server) {
2018-04-10 14:34:41 +00:00
instance.server = server
2018-04-10 15:08:40 +00:00
router := instance.server.Router
router.PUT("/:channel", func(ctx *gin.Context) {
channel := instance.channelManager.Channel(ctx.Param("channel"))
2018-04-10 15:08:40 +00:00
if channel == nil {
ctx.Status(404)
return
}
if user, password, ok := ctx.Request.BasicAuth(); ok {
if !instance.authenticator.VerifyUsernameAndPassword(channel, user, password) {
2018-04-10 15:08:40 +00:00
ctx.Status(401)
return
}
} else {
ctx.Status(401)
return
}
io.Copy(channel.InputStream, ctx.Request.Body)
2018-04-10 15:08:40 +00:00
})
2018-04-10 14:34:41 +00:00
}