作者 yangfu

修改迁移

... ... @@ -43,4 +43,4 @@ h5_host = "http://mmm-web-open-test.fjmaimaimai.com"
suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com"
#阿里云
cname ="https://media.goexample.live/"
\ No newline at end of file
cname ="https://media.fjmaimaimai.com/"
\ No newline at end of file
... ...
... ... @@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn"
h5_host = "https://web-open.fjmaimaimai.com"
#审核中心
suplus_approve_host ="https://public-interface.fjmaimaimai.com/approve"
\ No newline at end of file
suplus_approve_host ="https://public-interface.fjmaimaimai.com/approve"
#阿里云
cname ="https://media.fjmaimaimai.com/"
\ No newline at end of file
... ...
[test]
#数据库相关
mysql_user = "${MYSQL_USER||root}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
mysql_host = "${MYSQL_HOST||115.29.205.99}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2018}"
mysql_host = "${MYSQL_HOST||101.37.68.23}"
mysql_port = "${MYSQL_PORT||3306}"
mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
mysql_db_name = "${MYSQL_DB_NAME||opportunity_test}"
#日志
log_level = "${LOG_LEVEL||debug}"
... ... @@ -14,7 +14,7 @@ aliyun_logs_access ="${aliyun_logs_access||app.log}"
#redis相关配置
redis_add = "${REDIS_HOST||127.0.0.1}"
redis_add_port = "${REDIS_PORT||6379}"
redis_auth = ""
redis_auth = "123456"
#sms相关配置
yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
... ... @@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn"
h5_host = "http://mmm-web-open-test.fjmaimaimai.com"
#审核中心
suplus_approve_host ="http://suplus-approve-test.fjmaimaimai.com"
\ No newline at end of file
suplus_approve_host ="http://suplus-approve-test.fjmaimaimai.com"
#阿里云
cname ="https://media.fjmaimaimai.com/"
\ No newline at end of file
... ...
... ... @@ -101,6 +101,10 @@ func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (respons
return
}
request.ImageExt = filepath.Ext(r.FileName)[1:]
if request.ImageExt == "" {
err = fmt.Errorf("filename:%v invalid", r.FileName)
return
}
request.AcceptFormat = "JSON"
//request.StorageLocation = filepath.Base(request.Title)
rsp, err := client.CreateUploadImage(request)
... ...
... ... @@ -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 (
... ...
... ... @@ -50,3 +50,22 @@ func Test_MyGetURLUploadInfos(t *testing.T) {
fmt.Printf("%s: %s %s\n", uploadInfo.UploadURL, uploadInfo.Status, uploadInfo.MediaId)
}
}
func Test_FixPath(t *testing.T) {
input := []struct {
Input string
Except string
}{
{Input: "https://123.jpg", Except: "https://123.jpg"},
{Input: "https:///123.jpg", Except: "https://123.jpg"},
{Input: "https:/123.jpg", Except: "https://123.jpg"},
{Input: "http://123.jpg", Except: "http://123.jpg"},
{Input: "http:///123.jpg", Except: "http://123.jpg"},
{Input: "http:/123.jpg", Except: "http://123.jpg"},
}
for i := 0; i < len(input); i++ {
if !strings.EqualFold(fixPath(input[i].Input), input[i].Except) {
t.Fatal("not equal input:", input[i].Input, "except:", input[i].Except, "out:", fixPath(input[i].Input))
}
}
}
... ...