package cloud_bundle import ( "applet/app/cfg" "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/svc" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "fmt" "github.com/gin-gonic/gin" "io" "net/http" "strings" "time" ) func List(c *gin.Context) { var req *md.CloudBundleReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } var resp md.CloudBundleResp noticeList := make([]md.CloudBundleList, 0) NewCloudBundleDb := implement.NewCloudBundleDb(db.Db) notice, total, _ := NewCloudBundleDb.FindCloudBundleAndTotal(req.Page, req.Limit) resp.Total = total if notice != nil { for _, v := range *notice { tmp := md.CloudBundleList{ Id: utils.IntToStr(v.Id), BuildId: v.BuildId, Version: "v" + v.Version, Os: utils.IntToStr(v.Os), State: utils.IntToStr(v.State), Memo: v.Memo, Src: svc.GetOssUrl(v.Src), Bit: v.Bit, IsCombine: v.IsCombine, FinishAt: "--", IsAuditing: utils.IntToStr(v.IsAuditing), } if v.ApplyAt > 0 { tmp.ApplyAt = time.Unix(int64(v.ApplyAt), 0).Format("2006-01-02 15:04:05") } if v.FinishAt > 0 && v.State == 999 { tmp.FinishAt = time.Unix(int64(v.FinishAt), 0).Format("2006-01-02 15:04:05") } noticeList = append(noticeList, tmp) } } lastAndroid, _ := NewCloudBundleDb.GetCloudBundleLast("1") resp.LastBit = "64" resp.LastIsCombine = "0" if lastAndroid != nil { resp.LastAndroid = "v" + lastAndroid.Version resp.LastBit = lastAndroid.Bit resp.LastIsCombine = lastAndroid.IsCombine } lastIos, _ := NewCloudBundleDb.GetCloudBundleLast("2") if lastIos != nil { resp.ListIos = "v" + lastIos.Version } resp.List = noticeList e.OutSuc(c, resp, nil) return } func Build(c *gin.Context) { var req *md.CloudBundleBuildReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } count, _ := db.Db.Where("os=? and version=?", req.Os, req.Version).Count(&model.CloudBundle{}) if count > 0 { e.OutErr(c, 400, e.NewErr(400, "版本已存在")) return } tmp := model.CloudBundle{ Os: utils.StrToInt(req.Os), Version: req.Version, ApplyAt: int(time.Now().Unix()), Memo: req.Memo, AppletId: 0, IsCombine: req.IsCombine, NewBit: strings.Join(req.Bit, ","), } //TODO 调用打包机 keys := "CloudBuild" if req.Os == "2" { keys = "CloudBuild-iOS" } token := "aaaaaa" masterKey := "master" domain := "" if cfg.Prd == false { masterKey = "dev" domain = "" } url := "http://120.76.175.204:8080/job/" + keys + "/buildWithParameters?timestamp=" + utils.Int64ToStr(time.Now().Unix()) + "&token=" + token + "&branch=" + masterKey + "&domain=" + domain tmp.Bit = strings.Join(req.Bit, ",") if req.Os == "2" { db.Db.Insert(&tmp) url += "&id=" + utils.IntToStr(tmp.Id) getcurl(url) } else { if req.IsCombine != "1" { for _, v := range req.Bit { for _, v1 := range req.Platform { tmp.Bit = v tmp.Platform = v1 db.Db.Insert(&tmp) url += "&id=" + utils.IntToStr(tmp.Id) getcurl(url) } } } else { for _, v1 := range req.Platform { tmp.Platform = v1 db.Db.Insert(&tmp) url += "&id=" + utils.IntToStr(tmp.Id) getcurl(url) } } } e.OutSuc(c, "success", nil) return } func getcurl(url string) (string, error) { client := &http.Client{} // 创建请求 request, err := http.NewRequest("GET", url, nil) if err != nil { return "", err } // 设置用户名和密码,这里的"user:password"是用户名和密码的组合,中间不能有空格 request.SetBasicAuth("fnuoos", "11ad0050eef8521bc85f1c06ebf018654b") // 发送请求 response, err := client.Do(request) if err != nil { return "", err } // 读取响应内容 defer response.Body.Close() body, err := io.ReadAll(response.Body) if err != nil { return "", err } fmt.Println(string(body)) return string(body), nil } func Del(c *gin.Context) { var req *md.ArticleDelReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } db.Db.In("id", req.Id).Delete(&model.CloudBundle{}) e.OutSuc(c, "success", nil) return } func AuditSet(c *gin.Context) { var req *md.CommReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } db.Db.Where("id=?", req.Id).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 1}) e.OutSuc(c, "success", nil) return } func AuditClear(c *gin.Context) { var req *md.AuditClearReq if err := c.ShouldBindJSON(&req); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } db.Db.Where("os=?", req.Os).Cols("is_auditing").Update(&model.CloudBundle{IsAuditing: 0}) e.OutSuc(c, "success", nil) return }