You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package monkey
import (
"goqs/controllers"
"goqs/dbsql"
"goqs/models"
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
// @Tags Monkey相关 /api/monkey/v1/
// @Summary 获取设备列表
// @Description 获取安卓设备列表
// @accept x-www-form-urlencoded
// @Param platform query int false "平台ios/adr"
// @Success 200 {object} models.Response "返回设备信息"
// @Router /api/monkey/v1/devices [get]
func GetDevices(c *gin.Context) {
rsp := controllers.NewResponse()
// var list []models.MonkeyDevice
// db, err := dbsql.GetConn(dbsql.DSN)
// if err != nil {
// rsp.Error(err.Error())
// c.JSON(http.StatusOK, rsp)
// return
// }
// defer dbsql.Close(db)
rsp.Success()
rsp.Data = GetAndroidDevices()
c.JSON(http.StatusOK, rsp)
}
// @Tags Monkey相关 /api/monkey/v1/
// @Summary 获取设备列表
// @Description 获取安卓设备列表
// @accept x-www-form-urlencoded
// @Param task_id query string true "任务id"
// @Success 200 {object} models.Response "返回设备信息"
// @Router /api/monkey/v1/task/devices [get]
func GetDevicesByTaskId(c *gin.Context) {
rsp := controllers.NewResponse()
task_id := c.DefaultQuery("task_id", "")
if task_id == "" {
rsp.Error("task_id为空")
c.JSON(http.StatusOK, rsp)
return
}
db, err := dbsql.GetConn(dbsql.DSN)
if err != nil {
rsp.Error(err.Error())
c.JSON(http.StatusOK, rsp)
return
}
defer dbsql.Close(db)
var task models.MonkeyTask
db.Model(models.MonkeyTask{}).Where("id = ?", task_id).Last(&task)
if task.Id < 1 {
rsp.Error("没有找到该Monkey任务task_id=" + task_id)
c.JSON(http.StatusOK, rsp)
return
}
var devices []models.Device
if strings.Contains(task.Devices, ",") {
list := strings.Split(task.Devices, ",")
for _, v := range list {
var d models.Device
db.Model(models.Device{}).Where("udid = ?", v).Last(&d)
if d.ID > 0 {
devices = append(devices, d)
}
}
} else {
var d models.Device
db.Model(models.Device{}).Where("udid = ?", task.Devices).Last(&d)
if d.ID > 0 {
devices = append(devices, d)
}
}
rsp.Success()
rsp.Data = devices
c.JSON(http.StatusOK, rsp)
}