change: group hrp ui server urls

This commit is contained in:
lilong.129
2024-11-05 15:27:43 +08:00
parent 0ccac86957
commit 112d7b6656
2 changed files with 28 additions and 20 deletions
+1 -1
View File
@@ -1 +1 @@
v5.0.0+2411051500 v5.0.0+2411051527
+27 -19
View File
@@ -17,22 +17,31 @@ import (
func NewServer(port int) error { func NewServer(port int) error {
router := gin.Default() router := gin.Default()
router.GET("/ping", pingHandler) router.GET("/ping", pingHandler)
router.GET("/api/v1/:platform/devices", listDeviceHandler)
router.POST("/api/v1/:platform/:serial/ui/tap", parseDeviceInfo(), tapHandler) apiV1Platform := router.Group("/api/v1").Group("/:platform")
router.POST("/api/v1/:platform/:serial/ui/drag", parseDeviceInfo(), dragHandler) apiV1Platform.GET("/devices", listDeviceHandler)
router.POST("/api/v1/:platform/:serial/ui/input", parseDeviceInfo(), inputHandler)
router.POST("/api/v1/:platform/:serial/key/unlock", parseDeviceInfo(), unlockHandler) apiV1PlatformSerial := apiV1Platform.Group("/:serial")
router.POST("/api/v1/:platform/:serial/key/home", parseDeviceInfo(), homeHandler) // UI operations
router.POST("/api/v1/:platform/:serial/key", parseDeviceInfo(), keycodeHandler) apiV1PlatformSerial.POST("/ui/tap", parseDeviceInfo(), tapHandler)
router.GET("/api/v1/:platform/:serial/app/foreground", parseDeviceInfo(), foregroundAppHandler) apiV1PlatformSerial.POST("/ui/drag", parseDeviceInfo(), dragHandler)
router.POST("/api/v1/:platform/:serial/app/clear", parseDeviceInfo(), clearAppHandler) apiV1PlatformSerial.POST("/ui/input", parseDeviceInfo(), inputHandler)
router.POST("/api/v1/:platform/:serial/app/launch", parseDeviceInfo(), launchAppHandler) // Key operations
router.POST("/api/v1/:platform/:serial/app/terminal", parseDeviceInfo(), terminalAppHandler) apiV1PlatformSerial.POST("/key/unlock", parseDeviceInfo(), unlockHandler)
router.GET("/api/v1/:platform/:serial/screenshot", parseDeviceInfo(), screenshotHandler) apiV1PlatformSerial.POST("/key/home", parseDeviceInfo(), homeHandler)
router.GET("/api/v1/:platform/:serial/stub/source", parseDeviceInfo(), sourceHandler) apiV1PlatformSerial.POST("/key", parseDeviceInfo(), keycodeHandler)
router.GET("/api/v1/:platform/:serial/adb/source", parseDeviceInfo(), adbSourceHandler) // App operations
router.POST("/api/v1/:platform/:serial/stub/login", parseDeviceInfo(), loginHandler) apiV1PlatformSerial.GET("/app/foreground", parseDeviceInfo(), foregroundAppHandler)
router.POST("/api/v1/:platform/:serial/stub/logout", parseDeviceInfo(), logoutHandler) apiV1PlatformSerial.POST("/app/clear", parseDeviceInfo(), clearAppHandler)
apiV1PlatformSerial.POST("/app/launch", parseDeviceInfo(), launchAppHandler)
apiV1PlatformSerial.POST("/app/terminal", parseDeviceInfo(), terminalAppHandler)
// get screen info
apiV1PlatformSerial.GET("/screenshot", parseDeviceInfo(), screenshotHandler)
apiV1PlatformSerial.GET("/stub/source", parseDeviceInfo(), sourceHandler)
apiV1PlatformSerial.GET("/adb/source", parseDeviceInfo(), adbSourceHandler)
// Stub operations
apiV1PlatformSerial.POST("/stub/login", parseDeviceInfo(), loginHandler)
apiV1PlatformSerial.POST("/stub/logout", parseDeviceInfo(), logoutHandler)
err := router.Run(fmt.Sprintf("127.0.0.1:%d", port)) err := router.Run(fmt.Sprintf("127.0.0.1:%d", port))
if err != nil { if err != nil {
@@ -658,13 +667,12 @@ func parseDeviceInfo() gin.HandlerFunc {
if err != nil { if err != nil {
log.Error().Err(err).Str("platform", platform).Str("serial", serial).Msg(fmt.Sprintf("[%s]: Device Not Found", c.HandlerName())) log.Error().Err(err).Str("platform", platform).Str("serial", serial).Msg(fmt.Sprintf("[%s]: Device Not Found", c.HandlerName()))
c.JSON(http.StatusBadRequest, HttpResponse{ c.JSON(http.StatusBadRequest, HttpResponse{
Code: DeviceNotFoundCode, Code: code.GetErrorCode(err),
Message: fmt.Sprintf(DeviceNotFoundMsg, serial), Message: err.Error(),
}) })
c.Abort() c.Abort()
return return
} }
// c.Set("device", device)
driver, err := device.NewDriver(uixt.WithDriverImageService(true), uixt.WithDriverResultFolder(true)) driver, err := device.NewDriver(uixt.WithDriverImageService(true), uixt.WithDriverResultFolder(true))
if err != nil { if err != nil {
log.Error().Err(err).Str("platform", platform).Str("serial", serial).Msg(fmt.Sprintf("[%s]: Failed New Driver", c.HandlerName())) log.Error().Err(err).Str("platform", platform).Str("serial", serial).Msg(fmt.Sprintf("[%s]: Failed New Driver", c.HandlerName()))