| | |
| | | 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" |
| | |
| | | |
| | | 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, "") |
| | | } |
| | | } |