|
- 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"
- "github.com/syyongx/php2go"
- "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.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: "--",
- Platform: v.Platform,
- 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"
- resp.LastPlatform = make([]string, 0)
- if lastAndroid != nil {
- resp.LastAndroid = lastAndroid.Version
- resp.LastBit = lastAndroid.Bit
- resp.LastIsCombine = lastAndroid.IsCombine
- platform := strings.Split(lastAndroid.NewPlatform, ",")
- resp.LastPlatform = platform
- }
- lastIos, _ := NewCloudBundleDb.GetCloudBundleLast("2")
- if lastIos != nil {
- resp.ListIos = lastIos.Version
- }
- resp.List = noticeList
- resp.SelectData = []md.CloudBundleVersionMap{
- {Type: "station", Name: "本站"},
- {Type: "yingyongbao", Name: "应用宝"},
- {Type: "huawei", Name: "华为"},
- {Type: "xiaomi", Name: "小米"},
- {Type: "meizu", Name: "魅族"},
- {Type: "vivo", Name: "VIVO"},
- {Type: "oppo", Name: "OPPO"},
- }
- 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
- }
- if req.Os == "2" {
- req.Platform = []string{"ios"}
- }
- tmp := model.CloudBundle{
- Os: utils.StrToInt(req.Os),
- Version: req.Version,
- ApplyAt: int(time.Now().Unix()),
- Memo: req.Memo,
- AppletId: 0,
- NewPlatform: strings.Join(req.Platform, ","),
- 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 = "http://ddstar.izhim.cn"
- }
- url := "http://120.76.175.204:8080/job/" + keys + "/buildWithParameters?platform=" + tmp.NewPlatform + "&os=" + req.Os + "×tamp=" + utils.Int64ToStr(time.Now().Unix()) + "&token=" + token + "&branch=" + masterKey + "&domain=" + php2go.URLEncode(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 {
- newUrl := url
- ids := make([]string, 0)
- for _, v1 := range req.Platform {
- tmp1 := tmp
- tmp1.Bit = v
- tmp1.Platform = v1
- db.Db.Insert(&tmp1)
- ids = append(ids, utils.IntToStr(tmp1.Id))
- }
- newUrl += "&bit=" + v + "&id=" + strings.Join(ids, ",")
- getcurl(newUrl)
- }
-
- } else {
- ids := make([]string, 0)
- for _, v1 := range req.Platform {
- tmp1 := tmp
- tmp1.Platform = v1
- db.Db.Insert(&tmp1)
- url += "&id=" + utils.IntToStr(tmp1.Id)
- getcurl(url)
- }
- url += "&bit=" + strings.Join(req.Bit, ",") + "&id=" + strings.Join(ids, ",")
- getcurl(url)
- }
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
- func getcurl(url string) (string, error) {
- return "", nil
- 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
- }
|