...
|
...
|
@@ -10,6 +10,7 @@ import ( |
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
const LoopSize = 20
|
...
|
...
|
@@ -37,7 +38,6 @@ func MigrateChanceDataToAliYun() { |
|
|
o := orm.NewOrm()
|
|
|
for {
|
|
|
var datas []*models.ChanceData
|
|
|
log.Info("当前页:", pageInfo.PageIndex, "起始:", pageInfo.Offset())
|
|
|
if _, e := o.Raw(query, pageInfo.Offset(), pageInfo.PageSize).QueryRows(&datas); e != nil {
|
|
|
if e == orm.ErrNoRows {
|
|
|
break
|
...
|
...
|
@@ -45,13 +45,13 @@ func MigrateChanceDataToAliYun() { |
|
|
log.Error(e)
|
|
|
break
|
|
|
}
|
|
|
log.Info("当前页:", pageInfo.PageIndex, "起始:", pageInfo.Offset(), pageInfo.PageSize, " 行数:", len(datas))
|
|
|
if len(datas) == 0 {
|
|
|
break
|
|
|
}
|
|
|
|
|
|
for i := range datas {
|
|
|
data := datas[i]
|
|
|
|
|
|
//上传图片
|
|
|
data.Images = utils.JsonMarsh(uploadImages(data, data.Images))
|
|
|
//上传视频
|
...
|
...
|
@@ -89,11 +89,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) { |
|
|
goto ERR
|
|
|
}
|
|
|
//上传视频
|
|
|
auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path})
|
|
|
auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: fixPath(p.Path)})
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
err = upload(p.Path, auth.UploadAddress, auth.UploadAuth)
|
|
|
err = upload(fixPath(p.Path), auth.UploadAddress, auth.UploadAuth)
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
...
|
...
|
@@ -106,11 +106,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) { |
|
|
|
|
|
//上传封面
|
|
|
if len(p.Cover.Path) > 0 {
|
|
|
authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Cover.Path})
|
|
|
authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: fixPath(p.Cover.Path)})
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
err = upload(p.Cover.Path, authImage.UploadAddress, authImage.UploadAuth)
|
|
|
err = upload(fixPath(p.Cover.Path), authImage.UploadAddress, authImage.UploadAuth)
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
...
|
...
|
@@ -151,11 +151,11 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { |
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Path})
|
|
|
auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: fixPath(p.Path)})
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
|
|
err = upload(p.Path, auth.UploadAddress, auth.UploadAuth)
|
|
|
err = upload(fixPath(p.Path), auth.UploadAddress, auth.UploadAuth)
|
|
|
if err != nil {
|
|
|
goto ERR
|
|
|
}
|
...
|
...
|
@@ -176,6 +176,29 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
func fixPath(path string) string {
|
|
|
if strings.Index(path, "https:///") >= 0 {
|
|
|
return strings.Replace(path, "https:///", "https://", 1)
|
|
|
}
|
|
|
if strings.Index(path, "https://") >= 0 {
|
|
|
return strings.Replace(path, "https:///", "https://", 1)
|
|
|
}
|
|
|
if strings.Index(path, "https:/") >= 0 {
|
|
|
return strings.Replace(path, "https:/", "https://", 1)
|
|
|
}
|
|
|
|
|
|
if strings.Index(path, "http:///") >= 0 {
|
|
|
return strings.Replace(path, "http:///", "http://", 1)
|
|
|
}
|
|
|
if strings.Index(path, "http://") >= 0 {
|
|
|
return strings.Replace(path, "http:///", "http://", 1)
|
|
|
}
|
|
|
if strings.Index(path, "http:/") >= 0 {
|
|
|
return strings.Replace(path, "http:/", "http://", 1)
|
|
|
}
|
|
|
return path
|
|
|
}
|
|
|
|
|
|
//上传文件
|
|
|
func upload(path string, upAddress, upAuth string, options ...oss.Option) (err error) {
|
|
|
var (
|
...
|
...
|
|