From 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 20 八月 2020 20:35:30 +0800
Subject: [PATCH] add get buckets contrl

---
 controllers/sdk.go |  266 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 222 insertions(+), 44 deletions(-)

diff --git a/controllers/sdk.go b/controllers/sdk.go
index 58cb37c..76e1570 100644
--- a/controllers/sdk.go
+++ b/controllers/sdk.go
@@ -1,9 +1,11 @@
 package controllers
 
 import (
+	"net/http"
+	"strconv"
 	"webserver/extend/code"
-	"webserver/extend/config"
 	"webserver/extend/util"
+	"webserver/middlewares/auth"
 	"webserver/service"
 
 	"basic.com/dbapi.git"
@@ -45,7 +47,7 @@
 // @Description 绠楁硶淇濆瓨
 // @Accept json
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param reqMap body controllers.SdkVo true "浜鸿劯妫�娴�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -59,7 +61,7 @@
 		return
 	}
 	paramBody := util.Struct2Map(sdk)
-	flag, data := api.Save(paramBody)
+	flag, data := api.Register(paramBody)
 	if flag {
 		util.ResponseFormat(c, code.Success, data)
 	} else {
@@ -71,15 +73,19 @@
 // @Summary 鏌ユ壘鎵�鏈夌畻娉�
 // @Description 鏌ユ壘鎵�鏈夌畻娉�
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param sdkName query string false "鍙�夊弬鏁�"
+// @Param installed query bool true "鏌ュ凡瀹夎鎴栬�呮煡鎵�鏈�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶鍒楄〃",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"[]",success:false}"
 // @Router /data/api-v/sdk/findAllSdk [GET]
 func (sc SdkController) FindAllSdk(c *gin.Context) {
 	sdkName := c.Query("sdkName")
+	installed, _ := strconv.ParseBool(c.Query("installed"))
+	logger.Debug("FindAllSdk sdkName:", sdkName)
 
-	sdks := service.GetSdkList(sdkName)
+	sdks := service.GetSdkList("", installed) //鏈満宸插畨瑁呯殑绠楁硶
+
 	util.ResponseFormat(c, code.Success, sdks)
 }
 
@@ -87,7 +93,7 @@
 // @Summary 鏍规嵁id鑾峰彇绠楁硶淇℃伅
 // @Description 鏍规嵁id鑾峰彇绠楁硶淇℃伅
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param id query string true "绠楁硶id锛屽繀濉�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶淇℃伅",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -130,7 +136,7 @@
 // @Summary 鏍规嵁taskId鑾峰彇绠楁硶淇℃伅
 // @Description 鏍规嵁taskId鑾峰彇绠楁硶淇℃伅
 // @Produce json
-// @Tags sdk
+// @Tags 绠楁硶
 // @Param taskId query string true "taskId锛屽繀濉�"
 // @Success 200 {string} json "{"code":200, msg:"璇锋眰澶勭悊鎴愬姛",data:"绠楁硶淇℃伅",success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"璇锋眰澶辫触",data:"",success:false}"
@@ -150,45 +156,217 @@
 	}
 }
 
-func (sc SdkController) SdkDownLoad(c *gin.Context) {
-	var soApi dbapi.SoApi
-	var sdkConfig map[string]interface{}
-
-	path, exist := c.GetQuery("path")
-	if !exist {
-		util.ResponseFormat(c, code.ComError, "涓嬭浇鐨勭畻娉曞弬鏁版湁璇�")
+// @Summary 绠楁硶瀹夎鍖呬笂浼�(鍒嗗潡妫�鏌�)
+// @Description 绠楁硶瀹夎鍖呬笂浼�(鍒嗗潡妫�鏌�)
+// @Accept multipart/form-data
+// @Produce json
+// @Tags 绠楁硶
+// @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
 	}
-
-	logger.Info(path)
-
-	// 鍏堟煡鎵炬湰鍦扮洰褰曞唴鏄惁宸插瓨鍦ㄧ畻娉晄o, 娌℃湁璧颁簯绔笅杞�
-	if sdkConfig = service.FindLocalSdkSoById(path); sdkConfig == nil {
-		sdkConfig = service.DownSdk(path)
+	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
 	}
-
-	if sdkConfig != nil {
-		regSdkSuccess, _ := soApi.Add(sdkConfig)
-		regArgsSuccess, _ := soApi.Add(sdkConfig)
-
-		if regSdkSuccess && regArgsSuccess {
-			util.ResponseFormat(c, code.Success, "涓嬭浇绠楁硶鎴愬姛锛�")
-			return
-		}
+	var arg = service.FileChunkCheckVo {
+		UserId: userM["id"].(string),
+		FileName: filename,
+		Identifier: identifier,
+		RelativePath: relativePath,
+		TotalChunks: totalChunks,
+		ChunkNumber: chunkNumber,
+		ChunkSize: chunkSize,
+		CurrentChunkSize:currentChunkSize,
 	}
-
-	flag := c.Query("needUpdateMiddle")
-	// 涓嬭浇绠楁硶锛堟湁鏃跺�欎篃闇�瑕佹妸涓棿浠朵竴璧蜂笅杞戒笅鏉ワ級
-	if flag == "true" {
-		// 涓嬭浇骞舵洿鏂颁腑闂翠欢,甯︿笂MD5鏍¢獙
-		flag1, err := service.DownSo("http://" + config.SoPath.Ip + ":" + config.SoPath.Port + "/" + "middleware.so")
-		logger.Debug("涓棿浠惰矾寰勶細", "http://"+config.SoPath.Ip+":"+config.SoPath.Port+"/"+"middleware.so")
-		if err != nil {
-			logger.Info(err)
-		}
-		if !flag1 {
-			util.ResponseFormat(c, code.ComError, "璇烽噸鏂颁笅杞界畻娉�")
-		}
+	var sv service.SysService
+	if b := sv.CheckUpdateFile(&arg);b {
+		c.String(http.StatusOK,"found")
+	} else {
+		c.String(http.StatusNoContent,"")
 	}
-
-	util.ResponseFormat(c, code.ComError, "绠楁硶涓嬭浇澶辫触,璇烽噸璇�")
 }
+
+// @Security ApiKeyAuth
+// @Summary 绠楁硶瀹夎鍖呬笂浼�
+// @Description 绠楁硶瀹夎鍖呬笂浼�
+// @Accept multipart/form-data
+// @Produce json
+// @Tags 绠楁硶
+// @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,_ := 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, "")
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 涓婁紶瀹屾垚鑾峰彇瀹夎淇℃伅
+// @Description 涓婁紶瀹屾垚鑾峰彇瀹夎淇℃伅
+// @Produce json
+// @Tags 绠楁硶
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Param filename formData string true "鏂囦欢鍚嶇О"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/showInstallInfo [post]
+func (sc SdkController) ShowInstallInfo(c *gin.Context) {
+	identifier := c.Request.FormValue("identifier")
+	filename := c.Request.FormValue("filename")
+	var sv service.SdkInstallService
+	b,d, err := sv.ShowInstallInfo(identifier, filename)
+	if b {
+		util.ResponseFormat(c,code.Success, d)
+	} else {
+		util.ResponseFormat(c,&code.Code{http.StatusInternalServerError, false, err.Error()}, err.Error())
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 涓婁紶瀹屾垚寮�濮嬪畨瑁�
+// @Description 涓婁紶瀹屾垚寮�濮嬪畨瑁�
+// @Produce json
+// @Tags 绠楁硶
+// @Param identifier formData string true "鏁翠釜鏂囦欢鐨勫敮涓�鏍囪瘑锛岀洰鍓嶆槸md5"
+// @Param filename formData string true "鏂囦欢鍚嶇О"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/install [post]
+func (sc SdkController) Install(c *gin.Context) {
+	identifier := c.Request.FormValue("identifier")
+	filename := c.Request.FormValue("filename")
+
+	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()},err.Error())
+		return
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 浠庡晢鍩庝笅杞芥垨鍗囩骇绠楁硶
+// @Description 浠庡晢鍩庝笅杞芥垨鍗囩骇绠楁硶
+// @Produce json
+// @Tags 绠楁硶
+// @Param path query string true "绠楁硶id"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/sdkDownload [get]
+func (sc SdkController) SdkDownLoad(c *gin.Context) {
+	sdkId, exist := c.GetQuery("path")
+	if !exist {
+		util.ResponseFormat(c, code.RequestParamError, "涓嬭浇鐨勭畻娉曞弬鏁版湁璇�")
+		return
+	}
+
+	if b,err := service.DownloadOrUpgrade(sdkId);b {
+		util.ResponseFormat(c, code.Success, "绠楁硶瀹夎鎴愬姛")
+	} else {
+		util.ResponseFormat(c, &code.Code{http.StatusBadRequest, false, err.Error()}, err.Error())
+	}
+}
+
+// @Security ApiKeyAuth
+// @Summary 浣跨敤婵�娲荤爜婵�娲诲畨瑁呯畻娉�
+// @Description 浣跨敤婵�娲荤爜婵�娲诲畨瑁呯畻娉�
+// @Produce json
+// @Tags 绠楁硶
+// @Param code query string true "婵�娲荤爜"
+// @Param sdkId query string true "绠楁硶id"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/sdk/active [get]
+func (sc SdkController) Active(c *gin.Context) {
+	cod := c.GetString("code")
+	sdkId := c.GetString("sdkId")
+	if cod == "" || sdkId == "" {
+		util.ResponseFormat(c, code.RequestParamError, "婵�娲荤爜鍜岀畻娉昳d涓嶈兘涓虹┖")
+		return
+	}
+	var sv service.SdkInstallService
+	d, err := sv.Active(cod, sdkId)
+	if err == nil {
+		util.ResponseFormat(c,code.Success,  d)
+	} else {
+		util.ResponseFormat(c,code.ComError, err.Error())
+	}
+}
\ No newline at end of file

--
Gitblit v1.8.0