From 7193ef06e6f8bf12cdec260d7b01e6d4e4c0d442 Mon Sep 17 00:00:00 2001 From: luziqi Date: Tue, 25 Jul 2023 15:03:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3-?= =?UTF-8?q?=E8=8E=B7=E5=8F=96bugly=E5=87=AD=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/bugly.go | 37 ++++++++++++++++++++++++++++++++++--- docs/docs.go | 26 +++++++++++++++++++++++--- docs/swagger.json | 26 +++++++++++++++++++++++--- docs/swagger.yaml | 19 ++++++++++++++++--- main.go | 1 + 5 files changed, 97 insertions(+), 12 deletions(-) diff --git a/controllers/bugly.go b/controllers/bugly.go index ab77cc8..ad19c0c 100644 --- a/controllers/bugly.go +++ b/controllers/bugly.go @@ -4,17 +4,48 @@ import ( "autogo/dbsql" "autogo/models" "net/http" + "time" "github.com/gin-gonic/gin" ) // @Tags 设置相关 /api/setting/v2/ -// @Summary 新建设备 -// @Description 新建设备,UDID唯一 +// @Summary 获取bugly凭据 +// @Description 获取bugly凭据 +// @accept x-www-form-urlencoded +// @Success 200 {object} models.Response "返回存储的bugly凭据" +// @Router /api/setting/v2/get_bugly_token [get] +func GetBuglyToken(c *gin.Context) { + rsp := NewResponse() + + db, err := dbsql.GetConn(dbsql.DSN) + if err != nil { + c.JSON(http.StatusOK, rsp.Error(err.Error())) + return + } + defer dbsql.Close(db) + + var m1, m2 models.SysMap + db.Model(models.SysMap{}).Where("name = ? AND `key` = ?", "bugly-login", "xtoken").Last(&m1) + db.Model(models.SysMap{}).Where("name = ? AND `key` = ?", "bugly-login", "session").Last(&m2) + + m := make(map[string]string) + m["xtoken"] = m1.Value + m["session"] = m2.Value + location, _ := time.LoadLocation("Asia/Shanghai") + m["update_time"] = m1.UpdateTime.Local().In(location).Format("2006-01-02 15:04:05") + + rsp.Data = m + c.JSON(http.StatusOK, rsp.Success()) +} + +// @Tags 设置相关 /api/setting/v2/ +// @Summary 更新Bugly凭据 +// @Description 更新Bugly凭据 // @accept x-www-form-urlencoded // @Param xtoken formData string true "bugly请求header:XToken" // @Param session formData string true "bugly请求cookies:bugly-session" -// @Success 200 {object} models.Response "返回创建后的设备信息" +// @Success 200 {object} models.Response "返回接收的凭据" // @Router /api/setting/v2/update_bugly_token [post] func UpdateBuglyToken(c *gin.Context) { rsp := NewResponse() diff --git a/docs/docs.go b/docs/docs.go index 8eb8ce4..242ef1e 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1106,16 +1106,36 @@ const docTemplate = `{ } } }, + "/api/setting/v2/get_bugly_token": { + "get": { + "description": "获取bugly凭据", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "tags": [ + "设置相关 /api/setting/v2/" + ], + "summary": "获取bugly凭据", + "responses": { + "200": { + "description": "返回存储的bugly凭据", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/api/setting/v2/update_bugly_token": { "post": { - "description": "新建设备,UDID唯一", + "description": "更新Bugly凭据", "consumes": [ "application/x-www-form-urlencoded" ], "tags": [ "设置相关 /api/setting/v2/" ], - "summary": "新建设备", + "summary": "更新Bugly凭据", "parameters": [ { "type": "string", @@ -1134,7 +1154,7 @@ const docTemplate = `{ ], "responses": { "200": { - "description": "返回创建后的设备信息", + "description": "返回接收的凭据", "schema": { "$ref": "#/definitions/models.Response" } diff --git a/docs/swagger.json b/docs/swagger.json index 1cabb25..c184ce0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1094,16 +1094,36 @@ } } }, + "/api/setting/v2/get_bugly_token": { + "get": { + "description": "获取bugly凭据", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "tags": [ + "设置相关 /api/setting/v2/" + ], + "summary": "获取bugly凭据", + "responses": { + "200": { + "description": "返回存储的bugly凭据", + "schema": { + "$ref": "#/definitions/models.Response" + } + } + } + } + }, "/api/setting/v2/update_bugly_token": { "post": { - "description": "新建设备,UDID唯一", + "description": "更新Bugly凭据", "consumes": [ "application/x-www-form-urlencoded" ], "tags": [ "设置相关 /api/setting/v2/" ], - "summary": "新建设备", + "summary": "更新Bugly凭据", "parameters": [ { "type": "string", @@ -1122,7 +1142,7 @@ ], "responses": { "200": { - "description": "返回创建后的设备信息", + "description": "返回接收的凭据", "schema": { "$ref": "#/definitions/models.Response" } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5bb398f..68857aa 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -732,11 +732,24 @@ paths: summary: 获取应用信息 tags: - Monkey相关 /api/project/v1/ + /api/setting/v2/get_bugly_token: + get: + consumes: + - application/x-www-form-urlencoded + description: 获取bugly凭据 + responses: + "200": + description: 返回存储的bugly凭据 + schema: + $ref: '#/definitions/models.Response' + summary: 获取bugly凭据 + tags: + - 设置相关 /api/setting/v2/ /api/setting/v2/update_bugly_token: post: consumes: - application/x-www-form-urlencoded - description: 新建设备,UDID唯一 + description: 更新Bugly凭据 parameters: - description: bugly请求header:XToken in: formData @@ -750,10 +763,10 @@ paths: type: string responses: "200": - description: 返回创建后的设备信息 + description: 返回接收的凭据 schema: $ref: '#/definitions/models.Response' - summary: 新建设备 + summary: 更新Bugly凭据 tags: - 设置相关 /api/setting/v2/ /api/tool/v1/voice/list: diff --git a/main.go b/main.go index b25d6c6..8e476df 100644 --- a/main.go +++ b/main.go @@ -102,6 +102,7 @@ func main() { r.POST("/api/monkey/v2/task/store_anomaly", monkey.StoreMonkeyAnomaly) r.GET("/api/monkey/v2/task/get_anomalies", monkey.GetMonkeyAnomaliesByTaskId) + r.GET("/api/setting/v2/get_bugly_token", controllers.GetBuglyToken) r.POST("/api/setting/v2/update_bugly_token", controllers.UpdateBuglyToken) r.Run(port)