作者 yangfu

登录修改

... ... @@ -45,3 +45,6 @@ suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com"
#阿里云
cname ="https://media.goexample.live/"
#企业平台地址
BUSINESS_ADMIN_SERVICE_HOST = "${BUSINESS_ADMIN_SERVICE_HOST||http://suplus-business-admin-dev.fjmaimaimai.com/}"
\ No newline at end of file
... ...
... ... @@ -94,6 +94,12 @@ spec:
value: "stdout"
- name: aliyun_logs_access
value: " /opt/logs/app.log"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
volumes:
- name: accesslogs
emptyDir: {}
... ...
... ... @@ -98,6 +98,12 @@ spec:
value: "stdout"
- name: aliyun_logs_access
value: " /opt/logs/app.log"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
volumes:
- name: accesslogs
emptyDir: {}
... ...
... ... @@ -20,6 +20,7 @@ var (
type OSSClient struct {
client *oss.Client
Bucket *oss.Bucket
UpAddr UploadAddress
Auth UploadAuth
}
... ... @@ -54,22 +55,35 @@ func NewOSSClient(ep, key, secret, token string) (o *OSSClient, err error) {
}
//简单上传 (通过文件地址)
func (o *OSSClient) PutObjectByUrl(bucketName string, fileName string, url string) error {
func (o *OSSClient) PutObjectByUrl(bucketName string, fileName string, url string, options ...oss.Option) error {
r, err := GetFileFromUrl(url)
if err != nil {
return err
}
return o.PutObject(bucketName, fileName, r)
return o.PutObjectByBucket(bucketName, fileName, r, options...)
}
func (o *OSSClient) PutObjectByUrlDefault(url string) error {
return o.PutObjectByUrl(o.UpAddr.Bucket, o.UpAddr.FileName, url)
func (o *OSSClient) PutObjectByUrlDefault(url string, options ...oss.Option) error {
return o.PutObjectByUrl(o.UpAddr.Bucket, o.UpAddr.FileName, url, options...)
}
//简单上传
func (o *OSSClient) PutObject(bucketName, objKey string, r io.Reader, options ...oss.Option) error {
func (o *OSSClient) PutObjectByBucket(bucketName, objKey string, r io.Reader, options ...oss.Option) error {
bucket, err := o.client.Bucket(bucketName)
if err != nil {
return err
}
return bucket.PutObject(objKey, r, options...)
}
func (o *OSSClient) SetBucket(bucketName string) error {
bucket, err := o.client.Bucket(bucketName)
if err != nil {
return err
}
o.Bucket = bucket
return nil
}
func (o *OSSClient) PutObject(objKey string, r io.Reader, options ...oss.Option) error {
return o.Bucket.PutObject(objKey, r, options...)
}
... ...
... ... @@ -45,7 +45,7 @@ func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Clie
func CreateUploadVideo(client *vod.Client, r *CreateUploadVideoRequest) (response *CreateUploadVideoResponse, err error) {
request := vod.CreateCreateUploadVideoRequest()
filePath := getFileName(FileVideo, r.FileName)
if filepath.Ext(r.FileName) == "mp3" {
if filepath.Ext(r.FileName) == ".mp3" {
filePath = getFileName(FileVoice, r.FileName)
}
request.Title = filePath
... ... @@ -135,7 +135,7 @@ func getFileName(fileType string, filename string) string {
subfix := path.Ext(filename)
prefix := fmt.Sprintf("%v_%v", time.Now().Unix(), common.RandomString(32))
filename = fmt.Sprintf("%v%v", prefix, subfix)
sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", beego.BConfig.AppName, beego.BConfig.RunMode, fileType, date, filename)
sourcePath := fmt.Sprintf("%v/%v/%v/%v/%v", beego.BConfig.AppName, beego.BConfig.RunMode, date, fileType, filename)
return sourcePath
}
... ...
... ... @@ -535,16 +535,16 @@ type Speech struct {
Path string `json:"path"`
Duration int `json:"duration"`
VideoId string `json:"videoId"` //videoId
PathBak string `json:"path_bak"` //备份路径
PathBak string `json:"-"` //备份路径
}
//图片
type Picture struct {
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
W int `json:"-"` //w
H int `json:"-"` //h
ImageId string `json:"imageId"` //imageId
PathBak string `json:"path_bak"`
PathBak string `json:"-"`
//JobId string `json:"job_id"`
}
... ... @@ -554,7 +554,7 @@ type Video struct {
Cover Cover `json:"cover"` //封面
Duration int `json:"duration"`
VideoId string `json:"videoId"` //videoId
PathBak string `json:"path_bak"`
PathBak string `json:"-"` //
}
//审批配置
... ...
... ... @@ -162,8 +162,9 @@ type QuestionContent struct {
}
type Cover struct {
Path string `json:"path" valid:"Required"`
H int `json:"h"`
W int `json:"w"`
H int `json:"-"`
W int `json:"-"`
ImageId string `json:"imageId"`
}
/*公告列表 BulletinList */
... ...
... ... @@ -3,13 +3,13 @@ package contrab
import (
"fmt"
"github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/aliyun"
"opp/internal/utils"
"opp/models"
"opp/protocol"
"path/filepath"
)
const LoopSize = 1
... ... @@ -51,8 +51,9 @@ func MigrateChanceDataToAliYun() {
//上传图片
data.Images = utils.JsonMarsh(uploadImages(data, data.Images))
//上传视频
data.Videos = utils.JsonMarsh(uploadVideos(data, data.Videos))
//上传音频
data.Speechs = utils.JsonMarsh(uploadVoice(data, data.Speechs))
//更新数据
o.Update(data)
}
... ... @@ -61,6 +62,69 @@ func MigrateChanceDataToAliYun() {
}
}
func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) {
utils.JsonUnmarshal(video, &rsp)
if len(rsp) == 0 {
rsp = make([]protocol.Video, 0)
return
}
for i := range rsp {
p := rsp[i]
if len(p.VideoId) > 0 {
printInfo(d, p.Path, Uploaded)
continue
}
var (
err error
auth *aliyun.CreateUploadVideoResponse
authImage *aliyun.CreateUploadImageResponse
vodc *vod.Client
)
vodc, err = aliyun.DefaultVodClient()
if err != nil {
goto ERR
}
//上传视频
auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path})
if err != nil {
goto ERR
}
err = upload(p.Path, auth.UploadAddress, auth.UploadAuth)
if err != nil {
goto ERR
}
//备份路径
rsp[i].PathBak = p.Path
rsp[i].VideoId = auth.VideoId
rsp[i].Path = auth.FileURL
printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.FileURL), UploadSuccess)
//上传封面
if len(p.Cover.Path) > 0 {
authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Cover.Path})
if err != nil {
goto ERR
}
err = upload(p.Cover.Path, authImage.UploadAddress, authImage.UploadAuth)
if err != nil {
goto ERR
}
printInfo(d, fmt.Sprintf("cover %v -> %v", p.Cover.Path, authImage.ImageURL), UploadSuccess)
rsp[i].Cover.Path = authImage.ImageURL
rsp[i].Cover.ImageId = authImage.ImageId
}
continue
ERR:
{
log.Error("ali vod error:", err)
printInfo(d, p.Path, UploadFail)
continue
}
}
return
}
//上传图片
func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
utils.JsonUnmarshal(img, &rsp)
... ... @@ -74,40 +138,92 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
printInfo(d, p.Path, Uploaded)
continue
}
var (
err error
auth *aliyun.CreateUploadImageResponse
vodc *vod.Client
imageRsp *aliyun.CreateUploadImageResponse
client *aliyun.OSSClient
)
vodc, _ = aliyun.DefaultVodClient()
list := filepath.SplitList(p.Path)
if len(list) == 0 {
err = fmt.Errorf("路径无效:%v", p.Path)
vodc, err = aliyun.DefaultVodClient()
if err != nil {
goto ERR
}
auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Path})
if err != nil {
goto ERR
}
err = upload(p.Path, auth.UploadAddress, auth.UploadAuth)
if err != nil {
goto ERR
}
imageRsp, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: list[len(list)-1]})
//备份路径
rsp[i].PathBak = p.Path
rsp[i].ImageId = auth.ImageId
rsp[i].Path = auth.ImageURL
printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.ImageURL), UploadSuccess)
continue
ERR:
{
log.Error("ali vod error:", err)
printInfo(d, p.Path, UploadFail)
continue
}
}
return
}
//上传文件
func upload(path string, upAddress, upAuth string, options ...oss.Option) (err error) {
var (
client *aliyun.OSSClient
)
client, err = aliyun.NewStsOSSClient(upAddress, upAuth)
if err != nil {
return
}
err = client.PutObjectByUrlDefault(path, options...)
if err != nil {
return
}
return
}
//上班媒体数据
func uploadVoice(d *models.ChanceData, data string) (rsp []protocol.Speech) {
utils.JsonUnmarshal(data, &rsp)
if len(rsp) == 0 {
rsp = make([]protocol.Speech, 0)
return
}
for i := range rsp {
p := rsp[i]
if len(p.VideoId) > 0 {
printInfo(d, p.Path, Uploaded)
continue
}
var (
err error
auth *aliyun.CreateUploadVideoResponse
vodc *vod.Client
)
vodc, err = aliyun.DefaultVodClient()
if err != nil {
goto ERR
}
client, err = aliyun.NewStsOSSClient(imageRsp.UploadAddress, imageRsp.UploadAuth)
auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path})
if err != nil {
goto ERR
}
err = client.PutObjectByUrlDefault(p.Path)
err = upload(p.Path, auth.UploadAddress, auth.UploadAuth, oss.ContentType("audio/mpeg"))
if err != nil {
goto ERR
}
//备份路径
rsp[i].PathBak = p.Path
rsp[i].ImageId = imageRsp.ImageId
rsp[i].Path = imageRsp.ImageURL
printInfo(d, p.Path, UploadSuccess)
rsp[i].VideoId = auth.VideoId
rsp[i].Path = auth.FileURL
printInfo(d, fmt.Sprintf("%v -> %v", p.Path, auth.FileURL), UploadSuccess)
continue
ERR:
{
... ... @@ -119,12 +235,6 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
return
}
//上班媒体数据
func uploadVoice(d *models.ChanceData, url string) (rp []protocol.Speech) {
//
return nil
}
type ChanceDataExtend struct {
Id int64 `json:"id"`
ChanceId int64 `json:"chance_id"`
... ...