From 63873fc1fea408c201cef5cfedb3a9bdaeab5b4d Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期一, 16 十二月 2019 17:05:21 +0800 Subject: [PATCH] add patchUpdate --- controllers/syssetcont.go | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 203 insertions(+), 16 deletions(-) diff --git a/controllers/syssetcont.go b/controllers/syssetcont.go index 3be8a7a..56199d5 100644 --- a/controllers/syssetcont.go +++ b/controllers/syssetcont.go @@ -1,10 +1,14 @@ package controllers import ( + "net/http" + "regexp" + "strconv" "webserver/extend/code" "webserver/extend/config" "webserver/extend/sys" "webserver/extend/util" + "webserver/middlewares/auth" "basic.com/dbapi.git" "github.com/gin-gonic/gin" @@ -51,6 +55,7 @@ NewTime string `json:"newTime" example:"鎵嬪姩鎸囧畾鏃堕棿"` } +// @Security ApiKeyAuth // @Summary 瀛樺偍淇℃伅鏌ヨ // @Description 瀛樺偍淇℃伅鏌ヨ // @Accept json @@ -69,6 +74,7 @@ } } +// @Security ApiKeyAuth // @Summary 瀛樺偍淇℃伅淇敼 // @Description 瀛樺偍淇℃伅淇敼 // @Accept json @@ -95,9 +101,9 @@ } } +// @Security ApiKeyAuth // @Summary 瀛樺偍淇℃伅淇敼 // @Description 瀛樺偍淇℃伅淇敼 -// @Accept json // @Produce json // @Tags sysset // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" @@ -117,6 +123,7 @@ } } +// @Security ApiKeyAuth // @Summary 瑙嗛鎴彇鏃堕暱淇敼 // @Description 瑙嗛鎴彇鏃堕暱淇℃伅 // @Accept x-www-form-urlencoded @@ -142,6 +149,7 @@ } } +// @Security ApiKeyAuth // @Summary 鑾峰彇鍒嗘瀽璁惧淇℃伅 // @Description 鍒嗘瀽璁惧淇℃伅 // @Accept json @@ -179,6 +187,7 @@ } } +// @Security ApiKeyAuth // saveDevInfo dev_id dev_name // @Summary 淇濆瓨瑙嗛鍒嗘瀽璁惧淇℃伅 // @Description 鍒嗘瀽璁惧淇℃伅 @@ -190,7 +199,6 @@ // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" // @Router /data/api-v/sysset/saveDevInfo [POST] func (sset SysSetController) SaveDevInfo(c *gin.Context) { - dev_name := c.PostForm("server_name") var api dbapi.SysSetApi paramBody := make(map[string]interface{}, 0) @@ -211,6 +219,7 @@ } } +// @Security ApiKeyAuth // @Summary GB28181璁剧疆鏌ヨ // @Description GB28181璁剧疆淇℃伅鏌ヨ // @Accept json @@ -229,6 +238,7 @@ } } +// @Security ApiKeyAuth // @Summary GB28181璁剧疆淇℃伅淇敼 // @Description GB28181璁剧疆淇敼 // @Accept json @@ -255,6 +265,7 @@ } } +// @Security ApiKeyAuth // @Summary 鑾峰彇鏃堕棿閰嶇疆 // @Description 绯荤粺鏃堕棿閰嶇疆淇℃伅 // @Accept json @@ -271,9 +282,9 @@ util.ResponseFormat(c, code.Success, resData) } +// @Security ApiKeyAuth // @Summary 娴嬭瘯鍚屾鏃堕棿 // @Description 娴嬭瘯鍚屾鏃堕棿鏈嶅姟鍣ㄦ槸鍚﹀彲鐢� -// @Accept json // @Produce json // @Tags sysset // @Param server query string true "鏃堕棿鏈嶅姟鍣╥p" @@ -288,19 +299,17 @@ return } - isIP, err := sys.RunNTPDate(ntpServer) - if !isIP { - util.ResponseFormat(c, code.RequestParamError, "鎸囧畾鐨勬湇鍔″櫒鍦板潃閿欒") + isConn := sys.RunNTPDate(ntpServer) + if !isConn { + util.ResponseFormat(c, code.RequestParamError, "NTP鏈嶅姟鍣ㄤ笉鍙敤") return } - if err == nil { - util.ResponseFormat(c, code.Success, "") - } else { - util.ResponseFormat(c, code.TaskStoped, "") - } + util.ResponseFormat(c, code.Success, "") + } +// @Security ApiKeyAuth // @Summary 璁剧疆绯荤粺鏃堕棿 // @Description 鏍℃绯荤粺鏃堕棿 // @Accept json @@ -315,11 +324,6 @@ err := c.BindJSON(&args) if err != nil { util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") - return - } - - if root := sys.CheckRootPermissions(); !root { - util.ResponseFormat(c, code.ServiceInsideError, "鏈嶅姟鍣ㄦ病鏈変慨鏀规椂闂寸殑鏉冮檺") return } @@ -345,6 +349,7 @@ util.ResponseFormat(c, code.UpdateSuccess, "閰嶇疆鎴愬姛") } +// @Security ApiKeyAuth // @Summary 鏌ヨ绯荤粺杩愯淇℃伅 // @Description 鑾峰彇褰撳墠绯荤粺鐨勮繍琛岀姸鎬侊紝CPU, GPU, 鍐呭瓨绛� // @Produce json @@ -356,3 +361,185 @@ info := sys.GetSysInfo() util.ResponseFormat(c, code.UpdateSuccess, info) } + +// @Security ApiKeyAuth +// @Summary 鏌ヨ绯荤粺鐘舵�侀槇鍊艰缃� +// @Description 鑾峰彇褰撳墠绯荤粺鐨勮繍琛岀姸鎬侊紝CPU, GPU, 鍐呭瓨鐨勯槇鍊奸厤缃� +// @Produce json +// @Tags sysset +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" +// @Router /data/api-v/sysset/sysThresholds [GET] +func (sset SysSetController) GetSysThresholds(c *gin.Context) { + util.ResponseFormat(c, code.UpdateSuccess, config.Server.SysThresholds) +} + +// @Security ApiKeyAuth +// @Summary 閲嶅惎绯荤粺 +// @Description 閲嶅惎鎿嶄綔绯荤粺 +// @Produce json +// @Tags sysset +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" +// @Router /data/api-v/sysset/reboot [GET] +func (sset SysSetController) RebootOS(c *gin.Context) { + if isOk, msg := sys.Reboot(); !isOk { + util.ResponseFormat(c, code.UpdateFail, msg) + return + } + + util.ResponseFormat(c, code.Success, "姝e湪閲嶅惎") +} + +// @Summary 鑾峰彇瀹氭椂閲嶅惎 +// @Description 鑾峰彇瀹氭椂閲嶅惎浠诲姟鐨勯厤缃鍒� +// @Produce json +// @Tags sysset +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" +// @Router /data/api-v/sysset/rebootTask [GET] +func (sset SysSetController) GetRebootTask(c *gin.Context) { + _, msg := sys.ReadRebootTaskInCrontab() + util.ResponseFormat(c, code.Success, msg) +} + +// @Summary 璁剧疆瀹氭椂閲嶅惎 +// @Description 璁剧疆瀹氭椂閲嶅惎浠诲姟鐨勯厤缃鍒� +// @Accept x-www-form-urlencoded +// @Produce json +// @Tags sysset +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" +// @Router /data/api-v/sysset/rebootTask [POST] +func (sset SysSetController) SetRebootTask(c *gin.Context) { + task := c.PostForm("task") + if len(task) < 1 { + sys.CleanRebootTask() + util.ResponseFormat(c, code.Success, "閰嶇疆鎴愬姛") + return + } + + regEx := `^([0-9*]+\s){4}[0-9*]+$` + if r, _ := regexp.MatchString(regEx, task); !r { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟閿欒") + return + } + + if r := sys.UpdateRebootTask(task); !r { + util.ResponseFormat(c, code.UpdateFail, "閰嶇疆澶辫触") + return + } + + util.ResponseFormat(c, code.Success, "閰嶇疆鎴愬姛") +} + +// @Security ApiKeyAuth +// @Summary 绯荤粺鏇存柊鍖呬笂浼�(鍒嗗潡妫�鏌�) +// @Description 绯荤粺鏇存柊鍖呬笂浼�(鍒嗗潡妫�鏌�) +// @Accept multipart/form-data +// @Produce json +// @Tags sysset +// @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡" +// @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬" +// @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬" +// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5" +// @Param filename formData string true "鏂囦欢鍚嶇О" +// @Param relativePath formData string true "鏂囦欢鍦ㄥ鎴风鐢佃剳鐨勮矾寰�" +// @Param totalChunks formData int true "鏂囦欢鎬诲潡鏁�" +// @Success 200 {string} json "{"code":200, msg:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Router /data/api-v/sysset/patchUpdate [get] +func (sset SysSetController) PatchUpdateCheck(c *gin.Context) { + authDriver := auth.GenerateAuthDriver() + userM := (*authDriver).User(c) + if userM ==nil { + util.ResponseFormat(c,code.TokenNotFound,"鐧诲綍杩囨湡锛岃鐧诲綍") + return + } + chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber")) + chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize")) + currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize")) + identifier := c.Request.FormValue("identifier") + filename := c.Request.FormValue("filename") + relativePath := c.Request.FormValue("relativePath") + totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks")) + if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e5 !=nil { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + var arg = service.FileChunkCheckVo { + UserId: userM["id"].(string), + FileName: filename, + Identifier: identifier, + RelativePath: relativePath, + TotalChunks: totalChunks, + ChunkNumber: chunkNumber, + ChunkSize: chunkSize, + CurrentChunkSize:currentChunkSize, + } + var sv service.SysService + if b := sv.CheckUpdateFile(&arg);b { + c.String(http.StatusOK,"found") + } else { + c.String(http.StatusNoContent,"") + } +} + +// @Security ApiKeyAuth +// @Summary 绯荤粺鏇存柊鍖呬笂浼� +// @Description 绯荤粺鏇存柊鍖呬笂浼� +// @Accept multipart/form-data +// @Produce json +// @Tags sysset +// @Param chunkNumber formData int true "褰撳墠鏄鍑犱釜鍒嗗潡" +// @Param chunkSize formData int true "姣忎竴鍧楃殑澶у皬" +// @Param currentChunkSize formData int true "褰撳墠鍧楃殑澶у皬" +// @Param totalSize formData string true "鏂囦欢鎬诲ぇ灏�" +// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5" +// @Param filename formData string true "鏂囦欢鍚嶇О" +// @Param relativePath formData string true "鏂囦欢鍦ㄥ鎴风鐢佃剳鐨勮矾寰�" +// @Param totalChunks formData int true "鏂囦欢鎬诲潡鏁�" +// @Param file formData file true "鏂囦欢鍒嗙墖鍐呭" +// @Success 200 {string} json "{"code":200, msg:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Router /data/api-v/sysset/patchUpdate [post] +func (sset SysSetController) PatchUpdate(c *gin.Context) { + authDriver := auth.GenerateAuthDriver() + userM := (*authDriver).User(c) + if userM == nil { + util.ResponseFormat(c, code.TokenNotFound, "鐧诲綍杩囨湡锛岃鐧诲綍") + return + } + chunkNumber, e1 := strconv.Atoi(c.Request.FormValue("chunkNumber")) + chunkSize, e2 := strconv.Atoi(c.Request.FormValue("chunkSize")) + currentChunkSize, e3 := strconv.Atoi(c.Request.FormValue("currentChunkSize")) + totalSize, e4 := strconv.ParseInt(c.Request.FormValue("totalSize"), 10, 64) + identifier := c.Request.FormValue("identifier") + filename := c.Request.FormValue("filename") + relativePath := c.Request.FormValue("relativePath") + totalChunks, e5 := strconv.Atoi(c.Request.FormValue("totalChunks")) + file, header, e6 := c.Request.FormFile("file") + if identifier == "" || e1 != nil || e2 != nil || e3 != nil || e4 != nil || e5 != nil || e6 != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + var arg = service.FileUploadVo{ + UserId: userM["id"].(string), + FileName: filename, + Identifier: identifier, + RelativePath: relativePath, + TotalSize: totalSize, + TotalChunks: totalChunks, + ChunkNumber: chunkNumber, + ChunkSize: chunkSize, + CurrentChunkSize: currentChunkSize, + File: &file, + Header: header, + } + var sv service.SysService + if b := sv.PatchUpload(&arg); b { + util.ResponseFormat(c, code.Success, "") + } else { + util.ResponseFormat(c, code.ComError, "") + } +} \ No newline at end of file -- Gitblit v1.8.0