From db5768e3a1432c7c6dd895830674a4519ae0ee1e Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 7 Nov 2024 20:41:41 +0800 Subject: [PATCH] feat: add uixt action handler --- hrp/internal/version/VERSION | 2 +- hrp/pkg/server/main.go | 3 +++ hrp/pkg/server/uixt.go | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 hrp/pkg/server/uixt.go diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index dd7a179d..e0ff89ae 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0+2411072017 +v5.0.0+2411072041 diff --git a/hrp/pkg/server/main.go b/hrp/pkg/server/main.go index c2eccf25..82b08d22 100644 --- a/hrp/pkg/server/main.go +++ b/hrp/pkg/server/main.go @@ -38,6 +38,9 @@ func NewServer(port int) error { apiV1PlatformSerial.POST("/stub/login", handleDeviceContext(), loginHandler) apiV1PlatformSerial.POST("/stub/logout", handleDeviceContext(), logoutHandler) + // run uixt actions + apiV1PlatformSerial.POST("/uixt/action", handleDeviceContext(), uixtActionHandler) + err := router.Run(fmt.Sprintf("127.0.0.1:%d", port)) if err != nil { log.Err(err).Msg("failed to start http server") diff --git a/hrp/pkg/server/uixt.go b/hrp/pkg/server/uixt.go new file mode 100644 index 00000000..357efd37 --- /dev/null +++ b/hrp/pkg/server/uixt.go @@ -0,0 +1,38 @@ +package server + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/httprunner/httprunner/v4/hrp/code" + "github.com/httprunner/httprunner/v4/hrp/pkg/uixt" + "github.com/rs/zerolog/log" +) + +func uixtActionHandler(c *gin.Context) { + dExt, err := getContextDriver(c) + if err != nil { + return + } + + var req uixt.MobileAction + if err := c.ShouldBindJSON(&req); err != nil { + handlerValidateRequestFailedContext(c, err) + return + } + + if err = dExt.DoAction(req); err != nil { + log.Err(err).Interface("action", req). + 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"}) +}