From 0d858e8610a79b15cb337daf134c4a00962dd477 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期四, 04 六月 2020 16:44:29 +0800 Subject: [PATCH] add sdk upload --- controllers/sdk.go | 123 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 123 insertions(+), 0 deletions(-) diff --git a/controllers/sdk.go b/controllers/sdk.go index 847ec2b..ae10470 100644 --- a/controllers/sdk.go +++ b/controllers/sdk.go @@ -1,9 +1,12 @@ package controllers import ( + "net/http" + "strconv" "webserver/extend/code" "webserver/extend/config" "webserver/extend/util" + "webserver/middlewares/auth" "webserver/service" "basic.com/dbapi.git" @@ -150,6 +153,126 @@ } } +// @Summary 绠楁硶瀹夎鍖呬笂浼�(鍒嗗潡妫�鏌�) +// @Description 绠楁硶瀹夎鍖呬笂浼�(鍒嗗潡妫�鏌�) +// @Accept multipart/form-data +// @Produce json +// @Tags sdk +// @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/sdk/upload [get] +func (sc SdkController) Upload(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/sdk/upload [post] +func (sc SdkController) UploadPack(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,isComplete := sv.PatchUpload(&arg); b { + if isComplete { //涓婁紶瀹屾瘯闇�瑕佽嚜鍔ㄨЕ鍙戝畨瑁� + var sv service.SdkInstallService + if b,err := sv.SdkInstall(identifier, filename);b { + util.ResponseFormat(c,&code.Code{http.StatusOK, true, "绠楁硶瀹夎鎴愬姛"},"绠楁硶瀹夎鎴愬姛") + return + } else { + util.ResponseFormat(c,&code.Code{http.StatusBadRequest, false, "绠楁硶瀹夎澶辫触"},err.Error()) + return + } + } + util.ResponseFormat(c, code.Success, "") + } else { + util.ResponseFormat(c, code.ComError, "") + } +} + func (sc SdkController) SdkDownLoad(c *gin.Context) { var soApi dbapi.SdkApi var sdkConfig map[string]interface{} -- Gitblit v1.8.0