正在显示
8 个修改的文件
包含
180 行增加
和
40 行删除
| @@ -44,4 +44,7 @@ h5_host = "http://mmm-web-open-test.fjmaimaimai.com" | @@ -44,4 +44,7 @@ h5_host = "http://mmm-web-open-test.fjmaimaimai.com" | ||
| 44 | suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com" | 44 | suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com" |
| 45 | 45 | ||
| 46 | #阿里云 | 46 | #阿里云 |
| 47 | -cname ="https://media.goexample.live/" | ||
| 47 | +cname ="https://media.goexample.live/" | ||
| 48 | + | ||
| 49 | +#企业平台地址 | ||
| 50 | +BUSINESS_ADMIN_SERVICE_HOST = "${BUSINESS_ADMIN_SERVICE_HOST||http://suplus-business-admin-dev.fjmaimaimai.com/}" |
| @@ -94,6 +94,12 @@ spec: | @@ -94,6 +94,12 @@ spec: | ||
| 94 | value: "stdout" | 94 | value: "stdout" |
| 95 | - name: aliyun_logs_access | 95 | - name: aliyun_logs_access |
| 96 | value: " /opt/logs/app.log" | 96 | value: " /opt/logs/app.log" |
| 97 | + | ||
| 98 | + - name: BUSINESS_ADMIN_SERVICE_HOST | ||
| 99 | + valueFrom: | ||
| 100 | + configMapKeyRef: | ||
| 101 | + name: suplus-config | ||
| 102 | + key: service.businessadmin | ||
| 97 | volumes: | 103 | volumes: |
| 98 | - name: accesslogs | 104 | - name: accesslogs |
| 99 | emptyDir: {} | 105 | emptyDir: {} |
| @@ -98,6 +98,12 @@ spec: | @@ -98,6 +98,12 @@ spec: | ||
| 98 | value: "stdout" | 98 | value: "stdout" |
| 99 | - name: aliyun_logs_access | 99 | - name: aliyun_logs_access |
| 100 | value: " /opt/logs/app.log" | 100 | value: " /opt/logs/app.log" |
| 101 | + | ||
| 102 | + - name: BUSINESS_ADMIN_SERVICE_HOST | ||
| 103 | + valueFrom: | ||
| 104 | + configMapKeyRef: | ||
| 105 | + name: suplus-config | ||
| 106 | + key: service.businessadmin | ||
| 101 | volumes: | 107 | volumes: |
| 102 | - name: accesslogs | 108 | - name: accesslogs |
| 103 | emptyDir: {} | 109 | emptyDir: {} |
| @@ -20,6 +20,7 @@ var ( | @@ -20,6 +20,7 @@ var ( | ||
| 20 | 20 | ||
| 21 | type OSSClient struct { | 21 | type OSSClient struct { |
| 22 | client *oss.Client | 22 | client *oss.Client |
| 23 | + Bucket *oss.Bucket | ||
| 23 | UpAddr UploadAddress | 24 | UpAddr UploadAddress |
| 24 | Auth UploadAuth | 25 | Auth UploadAuth |
| 25 | } | 26 | } |
| @@ -54,22 +55,35 @@ func NewOSSClient(ep, key, secret, token string) (o *OSSClient, err error) { | @@ -54,22 +55,35 @@ func NewOSSClient(ep, key, secret, token string) (o *OSSClient, err error) { | ||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | //简单上传 (通过文件地址) | 57 | //简单上传 (通过文件地址) |
| 57 | -func (o *OSSClient) PutObjectByUrl(bucketName string, fileName string, url string) error { | 58 | +func (o *OSSClient) PutObjectByUrl(bucketName string, fileName string, url string, options ...oss.Option) error { |
| 58 | r, err := GetFileFromUrl(url) | 59 | r, err := GetFileFromUrl(url) |
| 59 | if err != nil { | 60 | if err != nil { |
| 60 | return err | 61 | return err |
| 61 | } | 62 | } |
| 62 | - return o.PutObject(bucketName, fileName, r) | 63 | + return o.PutObjectByBucket(bucketName, fileName, r, options...) |
| 63 | } | 64 | } |
| 64 | -func (o *OSSClient) PutObjectByUrlDefault(url string) error { | ||
| 65 | - return o.PutObjectByUrl(o.UpAddr.Bucket, o.UpAddr.FileName, url) | 65 | +func (o *OSSClient) PutObjectByUrlDefault(url string, options ...oss.Option) error { |
| 66 | + return o.PutObjectByUrl(o.UpAddr.Bucket, o.UpAddr.FileName, url, options...) | ||
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | //简单上传 | 69 | //简单上传 |
| 69 | -func (o *OSSClient) PutObject(bucketName, objKey string, r io.Reader, options ...oss.Option) error { | 70 | +func (o *OSSClient) PutObjectByBucket(bucketName, objKey string, r io.Reader, options ...oss.Option) error { |
| 70 | bucket, err := o.client.Bucket(bucketName) | 71 | bucket, err := o.client.Bucket(bucketName) |
| 71 | if err != nil { | 72 | if err != nil { |
| 72 | return err | 73 | return err |
| 73 | } | 74 | } |
| 74 | return bucket.PutObject(objKey, r, options...) | 75 | return bucket.PutObject(objKey, r, options...) |
| 75 | } | 76 | } |
| 77 | + | ||
| 78 | +func (o *OSSClient) SetBucket(bucketName string) error { | ||
| 79 | + bucket, err := o.client.Bucket(bucketName) | ||
| 80 | + if err != nil { | ||
| 81 | + return err | ||
| 82 | + } | ||
| 83 | + o.Bucket = bucket | ||
| 84 | + return nil | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +func (o *OSSClient) PutObject(objKey string, r io.Reader, options ...oss.Option) error { | ||
| 88 | + return o.Bucket.PutObject(objKey, r, options...) | ||
| 89 | +} |
| @@ -45,7 +45,7 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie | @@ -45,7 +45,7 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie | ||
| 45 | func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) { | 45 | func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) { |
| 46 | request := vod.CreateCreateUploadVideoRequest() | 46 | request := vod.CreateCreateUploadVideoRequest() |
| 47 | filePath := getFileName(FileVideo, r.FileName) | 47 | filePath := getFileName(FileVideo, r.FileName) |
| 48 | - if filepath.Ext(r.FileName) == "mp3" { | 48 | + if filepath.Ext(r.FileName) == ".mp3" { |
| 49 | filePath = getFileName(FileVoice, r.FileName) | 49 | filePath = getFileName(FileVoice, r.FileName) |
| 50 | } | 50 | } |
| 51 | request.Title = filePath | 51 | request.Title = filePath |
| @@ -135,7 +135,7 @@ func getFileName(fileType string, filename string) string { | @@ -135,7 +135,7 @@ func getFileName(fileType string, filename string) string { | ||
| 135 | subfix := path.Ext(filename) | 135 | subfix := path.Ext(filename) |
| 136 | prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32)) | 136 | prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32)) |
| 137 | filename = fmt.Sprintf("%v%v", prefix, subfix) | 137 | filename = fmt.Sprintf("%v%v", prefix, subfix) |
| 138 | - sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", beego.BConfig.AppName, beego.BConfig.RunMode, fileType, date, filename) | 138 | + sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", beego.BConfig.AppName, beego.BConfig.RunMode, date, fileType, filename) |
| 139 | return sourcePath | 139 | return sourcePath |
| 140 | } | 140 | } |
| 141 | 141 |
| @@ -534,17 +534,17 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) { | @@ -534,17 +534,17 @@ func ClearEmptyForm(inputFormList []*Form) (FormList []*Form) { | ||
| 534 | type Speech struct { | 534 | type Speech struct { |
| 535 | Path string `json:"path"` | 535 | Path string `json:"path"` |
| 536 | Duration int `json:"duration"` | 536 | Duration int `json:"duration"` |
| 537 | - VideoId string `json:"videoId"` //videoId | ||
| 538 | - PathBak string `json:"path_bak"` //备份路径 | 537 | + VideoId string `json:"videoId"` //videoId |
| 538 | + PathBak string `json:"-"` //备份路径 | ||
| 539 | } | 539 | } |
| 540 | 540 | ||
| 541 | //图片 | 541 | //图片 |
| 542 | type Picture struct { | 542 | type Picture struct { |
| 543 | Path string `json:"path"` | 543 | Path string `json:"path"` |
| 544 | - W int `json:"w"` | ||
| 545 | - H int `json:"h"` | 544 | + W int `json:"-"` //w |
| 545 | + H int `json:"-"` //h | ||
| 546 | ImageId string `json:"imageId"` //imageId | 546 | ImageId string `json:"imageId"` //imageId |
| 547 | - PathBak string `json:"path_bak"` | 547 | + PathBak string `json:"-"` |
| 548 | //JobId string `json:"job_id"` | 548 | //JobId string `json:"job_id"` |
| 549 | } | 549 | } |
| 550 | 550 | ||
| @@ -554,7 +554,7 @@ type Video struct { | @@ -554,7 +554,7 @@ type Video struct { | ||
| 554 | Cover Cover `json:"cover"` //封面 | 554 | Cover Cover `json:"cover"` //封面 |
| 555 | Duration int `json:"duration"` | 555 | Duration int `json:"duration"` |
| 556 | VideoId string `json:"videoId"` //videoId | 556 | VideoId string `json:"videoId"` //videoId |
| 557 | - PathBak string `json:"path_bak"` | 557 | + PathBak string `json:"-"` // |
| 558 | } | 558 | } |
| 559 | 559 | ||
| 560 | //审批配置 | 560 | //审批配置 |
| @@ -161,9 +161,10 @@ type QuestionContent struct { | @@ -161,9 +161,10 @@ type QuestionContent struct { | ||
| 161 | Content string `json:"content" valid:"Required"` | 161 | Content string `json:"content" valid:"Required"` |
| 162 | } | 162 | } |
| 163 | type Cover struct { | 163 | type Cover struct { |
| 164 | - Path string `json:"path" valid:"Required"` | ||
| 165 | - H int `json:"h"` | ||
| 166 | - W int `json:"w"` | 164 | + Path string `json:"path" valid:"Required"` |
| 165 | + H int `json:"-"` | ||
| 166 | + W int `json:"-"` | ||
| 167 | + ImageId string `json:"imageId"` | ||
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | /*公告列表 BulletinList */ | 170 | /*公告列表 BulletinList */ |
| @@ -3,13 +3,13 @@ package contrab | @@ -3,13 +3,13 @@ package contrab | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "github.com/aliyun/alibaba-cloud-sdk-go/services/vod" | 5 | "github.com/aliyun/alibaba-cloud-sdk-go/services/vod" |
| 6 | + "github.com/aliyun/aliyun-oss-go-sdk/oss" | ||
| 6 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 8 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
| 8 | "opp/internal/aliyun" | 9 | "opp/internal/aliyun" |
| 9 | "opp/internal/utils" | 10 | "opp/internal/utils" |
| 10 | "opp/models" | 11 | "opp/models" |
| 11 | "opp/protocol" | 12 | "opp/protocol" |
| 12 | - "path/filepath" | ||
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | const LoopSize = 1 | 15 | const LoopSize = 1 |
| @@ -51,8 +51,9 @@ func MigrateChanceDataToAliYun() { | @@ -51,8 +51,9 @@ func MigrateChanceDataToAliYun() { | ||
| 51 | //上传图片 | 51 | //上传图片 |
| 52 | data.Images = utils.JsonMarsh(uploadImages(data, data.Images)) | 52 | data.Images = utils.JsonMarsh(uploadImages(data, data.Images)) |
| 53 | //上传视频 | 53 | //上传视频 |
| 54 | + data.Videos = utils.JsonMarsh(uploadVideos(data, data.Videos)) | ||
| 54 | //上传音频 | 55 | //上传音频 |
| 55 | - | 56 | + data.Speechs = utils.JsonMarsh(uploadVoice(data, data.Speechs)) |
| 56 | //更新数据 | 57 | //更新数据 |
| 57 | o.Update(data) | 58 | o.Update(data) |
| 58 | } | 59 | } |
| @@ -61,6 +62,69 @@ func MigrateChanceDataToAliYun() { | @@ -61,6 +62,69 @@ func MigrateChanceDataToAliYun() { | ||
| 61 | } | 62 | } |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 65 | +func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) { | ||
| 66 | + utils.JsonUnmarshal(video, &rsp) | ||
| 67 | + if len(rsp) == 0 { | ||
| 68 | + rsp = make([]protocol.Video, 0) | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + for i := range rsp { | ||
| 72 | + p := rsp[i] | ||
| 73 | + if len(p.VideoId) > 0 { | ||
| 74 | + printInfo(d, p.Path, Uploaded) | ||
| 75 | + continue | ||
| 76 | + } | ||
| 77 | + var ( | ||
| 78 | + err error | ||
| 79 | + auth *aliyun.CreateUploadVideoResponse | ||
| 80 | + authImage *aliyun.CreateUploadImageResponse | ||
| 81 | + vodc *vod.Client | ||
| 82 | + ) | ||
| 83 | + vodc, err = aliyun.DefaultVodClient() | ||
| 84 | + if err != nil { | ||
| 85 | + goto ERR | ||
| 86 | + } | ||
| 87 | + //上传视频 | ||
| 88 | + auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path}) | ||
| 89 | + if err != nil { | ||
| 90 | + goto ERR | ||
| 91 | + } | ||
| 92 | + err = upload(p.Path, auth.UploadAddress, auth.UploadAuth) | ||
| 93 | + if err != nil { | ||
| 94 | + goto ERR | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + //备份路径 | ||
| 98 | + rsp[i].PathBak = p.Path | ||
| 99 | + rsp[i].VideoId = auth.VideoId | ||
| 100 | + rsp[i].Path = auth.FileURL | ||
| 101 | + printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.FileURL), UploadSuccess) | ||
| 102 | + | ||
| 103 | + //上传封面 | ||
| 104 | + if len(p.Cover.Path) > 0 { | ||
| 105 | + authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Cover.Path}) | ||
| 106 | + if err != nil { | ||
| 107 | + goto ERR | ||
| 108 | + } | ||
| 109 | + err = upload(p.Cover.Path, authImage.UploadAddress, authImage.UploadAuth) | ||
| 110 | + if err != nil { | ||
| 111 | + goto ERR | ||
| 112 | + } | ||
| 113 | + printInfo(d, fmt.Sprintf("cover %v -> %v", p.Cover.Path, authImage.ImageURL), UploadSuccess) | ||
| 114 | + rsp[i].Cover.Path = authImage.ImageURL | ||
| 115 | + rsp[i].Cover.ImageId = authImage.ImageId | ||
| 116 | + } | ||
| 117 | + continue | ||
| 118 | + ERR: | ||
| 119 | + { | ||
| 120 | + log.Error("ali vod error:", err) | ||
| 121 | + printInfo(d, p.Path, UploadFail) | ||
| 122 | + continue | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + return | ||
| 126 | +} | ||
| 127 | + | ||
| 64 | //上传图片 | 128 | //上传图片 |
| 65 | func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { | 129 | func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { |
| 66 | utils.JsonUnmarshal(img, &rsp) | 130 | utils.JsonUnmarshal(img, &rsp) |
| @@ -74,40 +138,92 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { | @@ -74,40 +138,92 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { | ||
| 74 | printInfo(d, p.Path, Uploaded) | 138 | printInfo(d, p.Path, Uploaded) |
| 75 | continue | 139 | continue |
| 76 | } | 140 | } |
| 77 | - | ||
| 78 | var ( | 141 | var ( |
| 79 | - err error | ||
| 80 | - vodc *vod.Client | ||
| 81 | - imageRsp *aliyun.CreateUploadImageResponse | ||
| 82 | - client *aliyun.OSSClient | 142 | + err error |
| 143 | + auth *aliyun.CreateUploadImageResponse | ||
| 144 | + vodc *vod.Client | ||
| 83 | ) | 145 | ) |
| 84 | - vodc, _ = aliyun.DefaultVodClient() | ||
| 85 | - list := filepath.SplitList(p.Path) | ||
| 86 | - if len(list) == 0 { | ||
| 87 | - err = fmt.Errorf("路径无效:%v", p.Path) | 146 | + vodc, err = aliyun.DefaultVodClient() |
| 147 | + if err != nil { | ||
| 88 | goto ERR | 148 | goto ERR |
| 89 | } | 149 | } |
| 150 | + auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Path}) | ||
| 90 | if err != nil { | 151 | if err != nil { |
| 91 | goto ERR | 152 | goto ERR |
| 92 | } | 153 | } |
| 93 | - imageRsp, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: list[len(list)-1]}) | 154 | + err = upload(p.Path, auth.UploadAddress, auth.UploadAuth) |
| 94 | if err != nil { | 155 | if err != nil { |
| 95 | goto ERR | 156 | goto ERR |
| 96 | } | 157 | } |
| 97 | - client, err = aliyun.NewStsOSSClient(imageRsp.UploadAddress, imageRsp.UploadAuth) | 158 | + |
| 159 | + //备份路径 | ||
| 160 | + rsp[i].PathBak = p.Path | ||
| 161 | + rsp[i].ImageId = auth.ImageId | ||
| 162 | + rsp[i].Path = auth.ImageURL | ||
| 163 | + printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.ImageURL), UploadSuccess) | ||
| 164 | + continue | ||
| 165 | + ERR: | ||
| 166 | + { | ||
| 167 | + log.Error("ali vod error:", err) | ||
| 168 | + printInfo(d, p.Path, UploadFail) | ||
| 169 | + continue | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + return | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +//上传文件 | ||
| 176 | +func upload(path string, upAddress, upAuth string, options ...oss.Option) (err error) { | ||
| 177 | + var ( | ||
| 178 | + client *aliyun.OSSClient | ||
| 179 | + ) | ||
| 180 | + client, err = aliyun.NewStsOSSClient(upAddress, upAuth) | ||
| 181 | + if err != nil { | ||
| 182 | + return | ||
| 183 | + } | ||
| 184 | + err = client.PutObjectByUrlDefault(path, options...) | ||
| 185 | + if err != nil { | ||
| 186 | + return | ||
| 187 | + } | ||
| 188 | + return | ||
| 189 | +} | ||
| 190 | + | ||
| 191 | +//上班媒体数据 | ||
| 192 | +func uploadVoice(d *models.ChanceData, data string) (rsp []protocol.Speech) { | ||
| 193 | + utils.JsonUnmarshal(data, &rsp) | ||
| 194 | + if len(rsp) == 0 { | ||
| 195 | + rsp = make([]protocol.Speech, 0) | ||
| 196 | + return | ||
| 197 | + } | ||
| 198 | + for i := range rsp { | ||
| 199 | + p := rsp[i] | ||
| 200 | + if len(p.VideoId) > 0 { | ||
| 201 | + printInfo(d, p.Path, Uploaded) | ||
| 202 | + continue | ||
| 203 | + } | ||
| 204 | + var ( | ||
| 205 | + err error | ||
| 206 | + auth *aliyun.CreateUploadVideoResponse | ||
| 207 | + vodc *vod.Client | ||
| 208 | + ) | ||
| 209 | + vodc, err = aliyun.DefaultVodClient() | ||
| 210 | + if err != nil { | ||
| 211 | + goto ERR | ||
| 212 | + } | ||
| 213 | + auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path}) | ||
| 98 | if err != nil { | 214 | if err != nil { |
| 99 | goto ERR | 215 | goto ERR |
| 100 | } | 216 | } |
| 101 | - err = client.PutObjectByUrlDefault(p.Path) | 217 | + err = upload(p.Path, auth.UploadAddress, auth.UploadAuth, oss.ContentType("audio/mpeg")) |
| 102 | if err != nil { | 218 | if err != nil { |
| 103 | goto ERR | 219 | goto ERR |
| 104 | } | 220 | } |
| 105 | 221 | ||
| 106 | //备份路径 | 222 | //备份路径 |
| 107 | rsp[i].PathBak = p.Path | 223 | rsp[i].PathBak = p.Path |
| 108 | - rsp[i].ImageId = imageRsp.ImageId | ||
| 109 | - rsp[i].Path = imageRsp.ImageURL | ||
| 110 | - printInfo(d, p.Path, UploadSuccess) | 224 | + rsp[i].VideoId = auth.VideoId |
| 225 | + rsp[i].Path = auth.FileURL | ||
| 226 | + printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.FileURL), UploadSuccess) | ||
| 111 | continue | 227 | continue |
| 112 | ERR: | 228 | ERR: |
| 113 | { | 229 | { |
| @@ -119,12 +235,6 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { | @@ -119,12 +235,6 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { | ||
| 119 | return | 235 | return |
| 120 | } | 236 | } |
| 121 | 237 | ||
| 122 | -//上班媒体数据 | ||
| 123 | -func uploadVoice(d *models.ChanceData, url string) (rp []protocol.Speech) { | ||
| 124 | - // | ||
| 125 | - return nil | ||
| 126 | -} | ||
| 127 | - | ||
| 128 | type ChanceDataExtend struct { | 238 | type ChanceDataExtend struct { |
| 129 | Id int64 `json:"id"` | 239 | Id int64 `json:"id"` |
| 130 | ChanceId int64 `json:"chance_id"` | 240 | ChanceId int64 `json:"chance_id"` |
-
请 注册 或 登录 后发表评论