Refactor: Rename NanoKVM to BatchuKVM and update server URL
This commit is contained in:
14
server/proto/application.go
Normal file
14
server/proto/application.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package proto
|
||||
|
||||
type GetVersionRsp struct {
|
||||
Current string `json:"current"`
|
||||
Latest string `json:"latest"`
|
||||
}
|
||||
|
||||
type GetPreviewRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type SetPreviewReq struct {
|
||||
Enable bool `validate:"omitempty"`
|
||||
}
|
||||
28
server/proto/auth.go
Normal file
28
server/proto/auth.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package proto
|
||||
|
||||
type LoginReq struct {
|
||||
Username string `validate:"required"`
|
||||
Password string `validate:"required"`
|
||||
}
|
||||
|
||||
type LoginRsp struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type GetAccountRsp struct {
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type ChangePasswordReq struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
type IsPasswordUpdatedRsp struct {
|
||||
IsUpdated bool `json:"isUpdated"`
|
||||
}
|
||||
|
||||
type ConnectWifiReq struct {
|
||||
Ssid string `validate:"required"`
|
||||
Password string `valid:"required"`
|
||||
}
|
||||
11
server/proto/download.go
Normal file
11
server/proto/download.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package proto
|
||||
|
||||
type ImageEnabledRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type StatusImageRsp struct {
|
||||
Status string `json:"status"`
|
||||
File string `json:"file"`
|
||||
Percentage string `json:"percentage"`
|
||||
}
|
||||
9
server/proto/hid.go
Normal file
9
server/proto/hid.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package proto
|
||||
|
||||
type GetHidModeRsp struct {
|
||||
Mode string `json:"mode"` // normal or hid-only
|
||||
}
|
||||
|
||||
type SetHidModeReq struct {
|
||||
Mode string `validate:"required"` // normal or hid-only
|
||||
}
|
||||
44
server/proto/network.go
Normal file
44
server/proto/network.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package proto
|
||||
|
||||
type WakeOnLANReq struct {
|
||||
Mac string `form:"mac" validate:"required"`
|
||||
}
|
||||
|
||||
type GetMacRsp struct {
|
||||
Macs []string `json:"macs"`
|
||||
}
|
||||
|
||||
type DeleteMacReq struct {
|
||||
Mac string `form:"mac" validate:"required"`
|
||||
}
|
||||
|
||||
type SetMacNameReq struct {
|
||||
Mac string `form:"mac" validate:"required"`
|
||||
Name string `form:"name" validate:"required"`
|
||||
}
|
||||
|
||||
type TailscaleState string
|
||||
|
||||
const (
|
||||
TailscaleNotInstall TailscaleState = "notInstall"
|
||||
TailscaleNotRunning TailscaleState = "notRunning"
|
||||
TailscaleNotLogin TailscaleState = "notLogin"
|
||||
TailscaleStopped TailscaleState = "stopped"
|
||||
TailscaleRunning TailscaleState = "running"
|
||||
)
|
||||
|
||||
type GetTailscaleStatusRsp struct {
|
||||
State TailscaleState `json:"state"`
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
Account string `json:"account"`
|
||||
}
|
||||
|
||||
type LoginTailscaleRsp struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type GetWifiRsp struct {
|
||||
Supported bool `json:"supported"`
|
||||
Connected bool `json:"connected"`
|
||||
}
|
||||
49
server/proto/request.go
Normal file
49
server/proto/request.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var env = os.Getenv(gin.EnvGinMode)
|
||||
|
||||
// ValidateRequest Validates request parameters.
|
||||
func ValidateRequest(req interface{}) error {
|
||||
validate := validator.New()
|
||||
|
||||
if err := validate.Struct(req); err != nil {
|
||||
log.Errorf("validate request failed, err: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if env == "" || env == "debug" {
|
||||
log.Debugf("request: %+v\n", req)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseQueryRequest Validates GET requests.
|
||||
func ParseQueryRequest(c *gin.Context, req interface{}) error {
|
||||
var err error
|
||||
if err = c.ShouldBindQuery(req); err != nil {
|
||||
log.Errorf("parse request failed, err: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return ValidateRequest(req)
|
||||
}
|
||||
|
||||
// ParseFormRequest Validates POST Requests.
|
||||
func ParseFormRequest(c *gin.Context, req interface{}) error {
|
||||
var err error
|
||||
if err = c.ShouldBind(req); err != nil {
|
||||
log.Errorf("parse request failed, err: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return ValidateRequest(req)
|
||||
}
|
||||
50
server/proto/response.go
Normal file
50
server/proto/response.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"` // Status code. 0-success, others-failure
|
||||
Msg string `json:"msg"` // Status details
|
||||
Data interface{} `json:"data"` // Returned data
|
||||
}
|
||||
|
||||
func (r *Response) Ok() {
|
||||
r.Code = 0
|
||||
r.Msg = "success"
|
||||
}
|
||||
|
||||
func (r *Response) OkWithData(data interface{}) {
|
||||
r.Ok()
|
||||
r.Data = data
|
||||
}
|
||||
|
||||
func (r *Response) Err(code int, msg string) {
|
||||
r.Code = code
|
||||
r.Msg = msg
|
||||
}
|
||||
|
||||
// OkRsp Successful response without data.
|
||||
func (r *Response) OkRsp(c *gin.Context) {
|
||||
r.Ok()
|
||||
|
||||
c.JSON(http.StatusOK, r)
|
||||
}
|
||||
|
||||
// OkRspWithData Successful response with data.
|
||||
func (r *Response) OkRspWithData(c *gin.Context, data interface{}) {
|
||||
r.Ok()
|
||||
r.Data = data
|
||||
|
||||
c.JSON(http.StatusOK, r)
|
||||
}
|
||||
|
||||
// ErrRsp Failed response.
|
||||
func (r *Response) ErrRsp(c *gin.Context, code int, msg string) {
|
||||
r.Err(code, msg)
|
||||
|
||||
c.JSON(http.StatusOK, r)
|
||||
}
|
||||
22
server/proto/storage.go
Normal file
22
server/proto/storage.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package proto
|
||||
|
||||
type GetImagesRsp struct {
|
||||
Files []string `json:"files"`
|
||||
}
|
||||
|
||||
type MountImageReq struct {
|
||||
File string `json:"file" validate:"omitempty"`
|
||||
Cdrom bool `json:"cdrom" validate:"omitempty"`
|
||||
}
|
||||
|
||||
type GetMountedImageRsp struct {
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
type GetCdRomRsp struct {
|
||||
Cdrom int64 `json:"cdrom"`
|
||||
}
|
||||
|
||||
type DeleteImageReq struct {
|
||||
File string `json:"file" validate:"required"`
|
||||
}
|
||||
9
server/proto/stream.go
Normal file
9
server/proto/stream.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package proto
|
||||
|
||||
type UpdateFrameDetectReq struct {
|
||||
Enabled bool `validate:"omitempty"`
|
||||
}
|
||||
|
||||
type StopFrameDetectReq struct {
|
||||
Duration int `validate:"omitempty"`
|
||||
}
|
||||
138
server/proto/vm.go
Normal file
138
server/proto/vm.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package proto
|
||||
|
||||
type IP struct {
|
||||
Name string `json:"name"`
|
||||
Addr string `json:"addr"`
|
||||
Version string `json:"version"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GetInfoRsp struct {
|
||||
IPs []IP `json:"ips"`
|
||||
Mdns string `json:"mdns"`
|
||||
Image string `json:"image"`
|
||||
Application string `json:"application"`
|
||||
DeviceKey string `json:"deviceKey"`
|
||||
}
|
||||
|
||||
type GetHardwareRsp struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type SetGpioReq struct {
|
||||
Type string `validate:"required"` // reset / power
|
||||
Duration uint `validate:"omitempty"` // press time (unit: milliseconds)
|
||||
}
|
||||
|
||||
type GetGpioRsp struct {
|
||||
PWR bool `json:"pwr"` // power led
|
||||
HDD bool `json:"hdd"` // hdd led
|
||||
}
|
||||
|
||||
type SetScreenReq struct {
|
||||
Type string `validate:"required"` // resolution / fps / quality
|
||||
Value int `validate:"number"` // value
|
||||
}
|
||||
|
||||
type GetScriptsRsp struct {
|
||||
Files []string `json:"files"`
|
||||
}
|
||||
|
||||
type UploadScriptRsp struct {
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
type RunScriptReq struct {
|
||||
Name string `validate:"required"`
|
||||
Type string `validate:"required"` // foreground | background
|
||||
}
|
||||
|
||||
type RunScriptRsp struct {
|
||||
Log string `json:"log"`
|
||||
}
|
||||
|
||||
type DeleteScriptReq struct {
|
||||
Name string `validate:"required"`
|
||||
}
|
||||
|
||||
type GetVirtualDeviceRsp struct {
|
||||
Network bool `json:"network"`
|
||||
Disk bool `json:"disk"`
|
||||
}
|
||||
|
||||
type UpdateVirtualDeviceReq struct {
|
||||
Device string `validate:"required"`
|
||||
}
|
||||
|
||||
type UpdateVirtualDeviceRsp struct {
|
||||
On bool `json:"on"`
|
||||
}
|
||||
|
||||
type SetMemoryLimitReq struct {
|
||||
Enabled bool `validate:"omitempty"`
|
||||
Limit int64 `validate:"omitempty"`
|
||||
}
|
||||
|
||||
type GetMemoryLimitRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Limit int64 `json:"limit"`
|
||||
}
|
||||
|
||||
type SetOledReq struct {
|
||||
Sleep int `validate:"omitempty"`
|
||||
}
|
||||
|
||||
type GetOLEDRsp struct {
|
||||
Exist bool `json:"exist"`
|
||||
Sleep int `json:"sleep"`
|
||||
}
|
||||
|
||||
type GetGetHdmiStateRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type GetSSHStateRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type GetSwapRsp struct {
|
||||
Size int64 `json:"size"` // unit: MB
|
||||
}
|
||||
|
||||
type SetSwapReq struct {
|
||||
Size int64 `validate:"omitempty"` // unit: MB
|
||||
}
|
||||
|
||||
type GetMouseJigglerRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
type SetMouseJigglerReq struct {
|
||||
Enabled bool `validate:"omitempty"`
|
||||
Mode string `validate:"omitempty"`
|
||||
}
|
||||
|
||||
type GetMdnsStateRsp struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type SetHostnameReq struct {
|
||||
Hostname string `validate:"required"`
|
||||
}
|
||||
|
||||
type GetHostnameRsp struct {
|
||||
Hostname string `json:"hostname"`
|
||||
}
|
||||
|
||||
type SetWebTitleReq struct {
|
||||
Title string `validate:"omitempty"`
|
||||
}
|
||||
|
||||
type GetWebTitleRsp struct {
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type SetTlsReq struct {
|
||||
Enabled bool `validate:"omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user