add audio support, trying to manage MSD device
This commit is contained in:
90
http/route/nanokvm_ui.go
Normal file
90
http/route/nanokvm_ui.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"rkkvm/http/hw/stream"
|
||||
"rkkvm/http/middleware"
|
||||
"rkkvm/http/reqrsp"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type LoginReq struct {
|
||||
Username string `validate:"required"`
|
||||
Password string `validate:"required"`
|
||||
}
|
||||
|
||||
type LoginRsp struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type ChangePasswordReq struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
func Auth(r *gin.Engine) {
|
||||
r.POST("/api/auth/login", login)
|
||||
|
||||
api := r.Group("/api").Use(middleware.CheckToken())
|
||||
|
||||
api.POST("/auth/password", func(ctx *gin.Context) {})
|
||||
}
|
||||
|
||||
func VM(r *gin.Engine) {
|
||||
api := r.Group("/api").Use(middleware.CheckToken())
|
||||
|
||||
api.POST("/vm/screen", SetScreen)
|
||||
api.GET("/vm/gpio", func(ctx *gin.Context) {}) // just to not space in front log
|
||||
}
|
||||
|
||||
type SetScreenReq struct {
|
||||
Type string `validate:"required"` // resolution / fps / quality
|
||||
Value int `validate:"number"` // value
|
||||
}
|
||||
|
||||
func SetScreen(c *gin.Context) {
|
||||
var req SetScreenReq
|
||||
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, reqrsp.NanoKVMRsp{
|
||||
Code: -1,
|
||||
Msg: "invalid arguments",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ffmpeg := stream.GetFFmpeg()
|
||||
switch req.Type {
|
||||
case "fps":
|
||||
ffmpeg.SetFPS(req.Value)
|
||||
case "quality":
|
||||
ffmpeg.SetBitrate(req.Value * 100)
|
||||
case "resolution":
|
||||
ffmpeg.SetResolution(req.Value)
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, reqrsp.NanoKVMRsp{
|
||||
Code: -2,
|
||||
Msg: "invalid type",
|
||||
})
|
||||
return
|
||||
}
|
||||
ffmpeg.Stop()
|
||||
ffmpeg.Start()
|
||||
|
||||
log.Debugf("update screen: %+v", req)
|
||||
c.JSON(http.StatusOK, reqrsp.NanoKVMRsp{
|
||||
Msg: reqrsp.MsgSuccess,
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME: auth disabled while backend doesn't have key features
|
||||
func login(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, reqrsp.NanoKVMRsp{
|
||||
Msg: reqrsp.MsgSuccess,
|
||||
Data: gin.H{
|
||||
"token": "disabled",
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user