| | |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 上传完成获取安装信息 |
| | | // @Description 上传完成获取安装信息 |
| | | // @Produce json |
| | | // @Tags 算法 |
| | | // @Param identifier formData string true "整个文件的唯一标识,目前是md5" |
| | | // @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") |
| | | var sv service.SdkInstallService |
| | | b,d := sv.ShowInstallInfo(identifier) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success, d) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError, "获取失败") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 上传完成开始安装 |
| | | // @Description 上传完成开始安装 |
| | | // @Produce json |
| | |
| | | sdkApi.GET("/sdkDownload", sdkController.SdkDownLoad) |
| | | sdkApi.GET("/upload", sdkController.Upload) |
| | | sdkApi.POST("/upload", sdkController.UploadPack) |
| | | sdkApi.POST("/showInstallInfo", sdkController.ShowInstallInfo) |
| | | sdkApi.POST("/install", sdkController.Install) |
| | | sdkApi.GET("/active", sdkController.Active) |
| | | } |
| | |
| | | logger.Debug("DownloadFile err:", err) |
| | | return false, err |
| | | } |
| | | if unPackB,unPackErr := unPackPatchPackage(resp.Md5, ext); !unPackB { //解压失败 |
| | | return false, unPackErr |
| | | } |
| | | b, err := installSdk(resp.Md5, ext) |
| | | if b { |
| | | return true, nil |
| | |
| | | } |
| | | } |
| | | |
| | | //解压上传的算法安装包 |
| | | func unPackPatchPackage(identifier string, ext string) (bool,error) { |
| | | configPatchPath := "" |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "../patch" |
| | | } |
| | | //1.解压缩更新包 |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | | unPackFilePath := configPatchPath+"/"+identifier+ext |
| | | |
| | | if util.Exists(unPackTargetPath) { |
| | | //此版本已经更新过 |
| | | rmErr := os.RemoveAll(unPackTargetPath) |
| | | if rmErr !=nil { |
| | | return false,rmErr |
| | | } |
| | | } |
| | | if !util.CreateDirectory(unPackTargetPath) { |
| | | return false, errors.New("创建压缩文件夹失败") |
| | | } |
| | | logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath) |
| | | _,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath) |
| | | if err !=nil { |
| | | logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath) |
| | | return false, err |
| | | } |
| | | return true, nil |
| | | } |
| | | |
| | | func (sv SdkInstallService) ShowInstallInfo(identifier string) (bool, map[string]interface{}) { |
| | | configPatchPath := "" |
| | | if config.Server.PatchPath != "" { |
| | | configPatchPath = config.Server.PatchPath |
| | | } else { |
| | | configPatchPath = "../patch" |
| | | } |
| | | unPackTargetPath := configPatchPath+"/"+identifier+"_basic/" |
| | | if util.Exists(unPackTargetPath) { |
| | | targetFileName := "" |
| | | err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | if f == nil { |
| | | return err |
| | | } |
| | | if f.IsDir() { |
| | | targetFileName = f.Name() |
| | | } |
| | | return nil |
| | | }) |
| | | if err != nil { |
| | | return false, nil |
| | | } else { |
| | | unPackPath := unPackTargetPath + targetFileName +"/" |
| | | //解压完成,获取安装包中的文件,开始安装 |
| | | //1.解析安装说明ins.inc |
| | | incPath := unPackPath+"ins.inc" |
| | | if util.Exists(incPath) { |
| | | if incB, err := ioutil.ReadFile(incPath); err == nil { |
| | | var ins InsInc |
| | | if err = json.Unmarshal(incB, &ins); err == nil { |
| | | return true, map[string]interface{} { |
| | | "sdkName": ins.ProductName, |
| | | "installVersion": ins.InstallVersion, |
| | | "installContent": ins.InstallContent, |
| | | } |
| | | } else { |
| | | return false, nil |
| | | } |
| | | } else { |
| | | return false, nil |
| | | } |
| | | } else { |
| | | return false, nil |
| | | } |
| | | } |
| | | } else { |
| | | return false, nil |
| | | } |
| | | } |
| | | |
| | | //安装sdk |
| | | func installSdk(identifier string, ext string) (bool, error) { |
| | | configPatchPath := "" |
| | |
| | | } |
| | | }() |
| | | |
| | | if util.Exists(unPackTargetPath) { |
| | | //此版本已经更新过 |
| | | rmErr := os.RemoveAll(unPackTargetPath) |
| | | if rmErr !=nil { |
| | | return false,rmErr |
| | | } |
| | | } |
| | | if !util.CreateDirectory(unPackTargetPath) { |
| | | return false, errors.New("创建压缩文件夹失败") |
| | | if !util.Exists(unPackTargetPath) {//安装包不存在 |
| | | return false, errors.New("安装文件已不存在") |
| | | } |
| | | |
| | | logger.Debug("unPackFilePath:", unPackFilePath, "unPackPath:", unPackTargetPath) |
| | | _,err := util.UnTarGzByCmd(unPackFilePath, unPackTargetPath) |
| | | if err !=nil { |
| | | logger.Debug("UnPack err:",err,"unPackFile:",unPackFilePath) |
| | | return false, err |
| | | } |
| | | targetFileName := "" |
| | | err = filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | err := filepath.Walk(unPackTargetPath, func(path string, f os.FileInfo, err error) error { |
| | | if f == nil { |
| | | return err |
| | | } |
| | |
| | | return false, err |
| | | } |
| | | unPackPath := unPackTargetPath + targetFileName +"/" |
| | | if !util.Exists(unPackPath) { |
| | | return false, errors.New("安装文件已不存在") |
| | | } |
| | | //解压完成,获取安装包中的文件,开始安装 |
| | | //1.解析安装说明ins.inc |
| | | incPath := unPackPath+"ins.inc" |
| | |
| | | ChCount int `json:"chCount"` |
| | | AuthCount int `json:"authCount"` |
| | | ServeYear int `json:"serveYear"` |
| | | |
| | | ProductName string `json:"productName"` |
| | | InstallVersion string `json:"installVersion"` |
| | | InstallContent string `json:"installContent"` |
| | | } |
| | | |
| | | //算法和参数定义 |
| | |
| | | if isComplete { |
| | | if MergeChunks(fileTmpPath,fileTmpPath + subfix) { |
| | | logger.Debug("merge all chunks success,identifier:",MD5Str,"fileName:",arg.FileName) |
| | | unPackB, unPackErr := unPackPatchPackage(MD5Str, subfix) |
| | | logger.Debug("unPackB:", unPackB, "unPackErr:", unPackErr) |
| | | if unPackB { |
| | | return true, isComplete |
| | | } |
| | | } else { |
| | | return false, isComplete |
| | | } |