...
|
...
|
@@ -2,12 +2,14 @@ package contrab |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
|
|
|
"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
|
...
|
...
|
@@ -71,18 +73,47 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { |
|
|
printInfo(d, p.Path, Uploaded)
|
|
|
continue
|
|
|
}
|
|
|
//上传图片
|
|
|
callBack := aliyun.NewCallBackHttp(getCallBackUrl())
|
|
|
extend := NewChanceDataExtend(d, aliyun.FileImage, p.Path)
|
|
|
response, err := aliyun.UploadMediaByURL([]string{p.Path}, callBack, extend)
|
|
|
if err != nil || response == nil || len(response.UploadJobs) == 0 {
|
|
|
printInfo(d, p.Path, UploadFail)
|
|
|
continue
|
|
|
|
|
|
var (
|
|
|
err error
|
|
|
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)
|
|
|
goto ERR
|
|
|
}
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
imageRsp, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: list[len(list)-1]})
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
client, err = aliyun.NewStsOSSClient(imageRsp.UploadAddress, imageRsp.UploadAuth)
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
err = client.PutObjectByUrlDefault(p.Path)
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
|
|
|
//备份路径
|
|
|
rsp[i].PathBak = p.Path
|
|
|
rsp[i].JobId = response.UploadJobs[0].JobId
|
|
|
rsp[i].ImageId = imageRsp.ImageId
|
|
|
rsp[i].Path = imageRsp.ImageURL
|
|
|
printInfo(d, p.Path, UploadSuccess)
|
|
|
continue
|
|
|
ERR:
|
|
|
{
|
|
|
log.Error("ali vod error:", err)
|
|
|
printInfo(d, p.Path, UploadFail)
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
...
|
...
|
|