96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
package route
|
|
|
|
import (
|
|
"net/http"
|
|
"rkkvm/external/ffmpeg"
|
|
"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 := ffmpeg.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
|
|
}
|
|
/*
|
|
log.Debug("Stopping ffmpeg SetScreen")
|
|
ffmpeg.Stop()
|
|
time.Sleep(100 * time.Millisecond)
|
|
ffmpeg.ApplyOptions()
|
|
log.Debug("Starting ffmpeg SetScreen")
|
|
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",
|
|
},
|
|
})
|
|
}
|