feat: exec multiple uixt actions

This commit is contained in:
lilong.129
2024-11-07 21:00:21 +08:00
parent db5768e3a1
commit 2587bbee82
3 changed files with 34 additions and 1 deletions

View File

@@ -40,6 +40,7 @@ func NewServer(port int) error {
// run uixt actions
apiV1PlatformSerial.POST("/uixt/action", handleDeviceContext(), uixtActionHandler)
apiV1PlatformSerial.POST("/uixt/actions", handleDeviceContext(), uixtActionsHandler)
err := router.Run(fmt.Sprintf("127.0.0.1:%d", port))
if err != nil {

View File

@@ -9,6 +9,7 @@ import (
"github.com/rs/zerolog/log"
)
// exec a single uixt action
func uixtActionHandler(c *gin.Context) {
dExt, err := getContextDriver(c)
if err != nil {
@@ -36,3 +37,34 @@ func uixtActionHandler(c *gin.Context) {
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
}
// exec multiple uixt actions
func uixtActionsHandler(c *gin.Context) {
dExt, err := getContextDriver(c)
if err != nil {
return
}
var actions []uixt.MobileAction
if err := c.ShouldBindJSON(&actions); err != nil {
handlerValidateRequestFailedContext(c, err)
return
}
for _, action := range actions {
if err = dExt.DoAction(action); err != nil {
log.Err(err).Interface("action", action).
Msg("exec uixt action failed")
c.JSON(http.StatusInternalServerError,
HttpResponse{
Code: code.GetErrorCode(err),
Message: err.Error(),
},
)
c.Abort()
return
}
}
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
}