作者 yangfu

修改迁移

@@ -43,4 +43,4 @@ h5_host = "http://mmm-web-open-test.fjmaimaimai.com" @@ -43,4 +43,4 @@ h5_host = "http://mmm-web-open-test.fjmaimaimai.com"
43 suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com" 43 suplus_approve_host ="http://suplus-approve-dev.fjmaimaimai.com"
44 44
45 #阿里云 45 #阿里云
46 -cname ="https://media.goexample.live/"  
  46 +cname ="https://media.fjmaimaimai.com/"
@@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn" @@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn"
40 h5_host = "https://web-open.fjmaimaimai.com" 40 h5_host = "https://web-open.fjmaimaimai.com"
41 41
42 #审核中心 42 #审核中心
43 -suplus_approve_host ="https://public-interface.fjmaimaimai.com/approve"  
  43 +suplus_approve_host ="https://public-interface.fjmaimaimai.com/approve"
  44 +
  45 +#阿里云
  46 +cname ="https://media.fjmaimaimai.com/"
1 [test] 1 [test]
2 #数据库相关 2 #数据库相关
3 mysql_user = "${MYSQL_USER||root}" 3 mysql_user = "${MYSQL_USER||root}"
4 -mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"  
5 -mysql_host = "${MYSQL_HOST||115.29.205.99}" 4 +mysql_password = "${MYSQL_PASSWORD||sutianxia2018}"
  5 +mysql_host = "${MYSQL_HOST||101.37.68.23}"
6 mysql_port = "${MYSQL_PORT||3306}" 6 mysql_port = "${MYSQL_PORT||3306}"
7 -mysql_db_name = "${MYSQL_DB_NAME||opportunity}" 7 +mysql_db_name = "${MYSQL_DB_NAME||opportunity_test}"
8 8
9 #日志 9 #日志
10 log_level = "${LOG_LEVEL||debug}" 10 log_level = "${LOG_LEVEL||debug}"
@@ -14,7 +14,7 @@ aliyun_logs_access ="${aliyun_logs_access||app.log}" @@ -14,7 +14,7 @@ aliyun_logs_access ="${aliyun_logs_access||app.log}"
14 #redis相关配置 14 #redis相关配置
15 redis_add = "${REDIS_HOST||127.0.0.1}" 15 redis_add = "${REDIS_HOST||127.0.0.1}"
16 redis_add_port = "${REDIS_PORT||6379}" 16 redis_add_port = "${REDIS_PORT||6379}"
17 -redis_auth = "" 17 +redis_auth = "123456"
18 18
19 #sms相关配置 19 #sms相关配置
20 yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json" 20 yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
@@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn" @@ -40,4 +40,7 @@ user_center_app_secret ="cykbjnfqgctn"
40 h5_host = "http://mmm-web-open-test.fjmaimaimai.com" 40 h5_host = "http://mmm-web-open-test.fjmaimaimai.com"
41 41
42 #审核中心 42 #审核中心
43 -suplus_approve_host ="http://suplus-approve-test.fjmaimaimai.com"  
  43 +suplus_approve_host ="http://suplus-approve-test.fjmaimaimai.com"
  44 +
  45 +#阿里云
  46 +cname ="https://media.fjmaimaimai.com/"
@@ -101,6 +101,10 @@ func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (respons @@ -101,6 +101,10 @@ func CreateUploadImage(client *vod.Client, r *CreateUploadImageRequest) (respons
101 return 101 return
102 } 102 }
103 request.ImageExt = filepath.Ext(r.FileName)[1:] 103 request.ImageExt = filepath.Ext(r.FileName)[1:]
  104 + if request.ImageExt == "" {
  105 + err = fmt.Errorf("filename:%v invalid", r.FileName)
  106 + return
  107 + }
104 request.AcceptFormat = "JSON" 108 request.AcceptFormat = "JSON"
105 //request.StorageLocation = filepath.Base(request.Title) 109 //request.StorageLocation = filepath.Base(request.Title)
106 rsp, err := client.CreateUploadImage(request) 110 rsp, err := client.CreateUploadImage(request)
@@ -10,6 +10,7 @@ import ( @@ -10,6 +10,7 @@ import (
10 "opp/internal/utils" 10 "opp/internal/utils"
11 "opp/models" 11 "opp/models"
12 "opp/protocol" 12 "opp/protocol"
  13 + "strings"
13 ) 14 )
14 15
15 const LoopSize = 20 16 const LoopSize = 20
@@ -37,7 +38,6 @@ func MigrateChanceDataToAliYun() { @@ -37,7 +38,6 @@ func MigrateChanceDataToAliYun() {
37 o := orm.NewOrm() 38 o := orm.NewOrm()
38 for { 39 for {
39 var datas []*models.ChanceData 40 var datas []*models.ChanceData
40 - log.Info("当前页:", pageInfo.PageIndex, "起始:", pageInfo.Offset())  
41 if _, e := o.Raw(query, pageInfo.Offset(), pageInfo.PageSize).QueryRows(&datas); e != nil { 41 if _, e := o.Raw(query, pageInfo.Offset(), pageInfo.PageSize).QueryRows(&datas); e != nil {
42 if e == orm.ErrNoRows { 42 if e == orm.ErrNoRows {
43 break 43 break
@@ -45,13 +45,13 @@ func MigrateChanceDataToAliYun() { @@ -45,13 +45,13 @@ func MigrateChanceDataToAliYun() {
45 log.Error(e) 45 log.Error(e)
46 break 46 break
47 } 47 }
  48 + log.Info("当前页:", pageInfo.PageIndex, "起始:", pageInfo.Offset(), pageInfo.PageSize, " 行数:", len(datas))
48 if len(datas) == 0 { 49 if len(datas) == 0 {
49 break 50 break
50 } 51 }
51 52
52 for i := range datas { 53 for i := range datas {
53 data := datas[i] 54 data := datas[i]
54 -  
55 //上传图片 55 //上传图片
56 data.Images = utils.JsonMarsh(uploadImages(data, data.Images)) 56 data.Images = utils.JsonMarsh(uploadImages(data, data.Images))
57 //上传视频 57 //上传视频
@@ -89,11 +89,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) { @@ -89,11 +89,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) {
89 goto ERR 89 goto ERR
90 } 90 }
91 //上传视频 91 //上传视频
92 - auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: p.Path}) 92 + auth, err = aliyun.CreateUploadVideo(vodc, &aliyun.CreateUploadVideoRequest{FileName: fixPath(p.Path)})
93 if err != nil { 93 if err != nil {
94 goto ERR 94 goto ERR
95 } 95 }
96 - err = upload(p.Path, auth.UploadAddress, auth.UploadAuth) 96 + err = upload(fixPath(p.Path), auth.UploadAddress, auth.UploadAuth)
97 if err != nil { 97 if err != nil {
98 goto ERR 98 goto ERR
99 } 99 }
@@ -106,11 +106,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) { @@ -106,11 +106,11 @@ func uploadVideos(d *models.ChanceData, video string) (rsp []protocol.Video) {
106 106
107 //上传封面 107 //上传封面
108 if len(p.Cover.Path) > 0 { 108 if len(p.Cover.Path) > 0 {
109 - authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Cover.Path}) 109 + authImage, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: fixPath(p.Cover.Path)})
110 if err != nil { 110 if err != nil {
111 goto ERR 111 goto ERR
112 } 112 }
113 - err = upload(p.Cover.Path, authImage.UploadAddress, authImage.UploadAuth) 113 + err = upload(fixPath(p.Cover.Path), authImage.UploadAddress, authImage.UploadAuth)
114 if err != nil { 114 if err != nil {
115 goto ERR 115 goto ERR
116 } 116 }
@@ -151,11 +151,11 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { @@ -151,11 +151,11 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
151 if err != nil { 151 if err != nil {
152 goto ERR 152 goto ERR
153 } 153 }
154 - auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: p.Path}) 154 + auth, err = aliyun.CreateUploadImage(vodc, &aliyun.CreateUploadImageRequest{FileName: fixPath(p.Path)})
155 if err != nil { 155 if err != nil {
156 goto ERR 156 goto ERR
157 } 157 }
158 - err = upload(p.Path, auth.UploadAddress, auth.UploadAuth) 158 + err = upload(fixPath(p.Path), auth.UploadAddress, auth.UploadAuth)
159 if err != nil { 159 if err != nil {
160 goto ERR 160 goto ERR
161 } 161 }
@@ -176,6 +176,29 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { @@ -176,6 +176,29 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
176 return 176 return
177 } 177 }
178 178
  179 +func fixPath(path string) string {
  180 + if strings.Index(path, "https:///") >= 0 {
  181 + return strings.Replace(path, "https:///", "https://", 1)
  182 + }
  183 + if strings.Index(path, "https://") >= 0 {
  184 + return strings.Replace(path, "https:///", "https://", 1)
  185 + }
  186 + if strings.Index(path, "https:/") >= 0 {
  187 + return strings.Replace(path, "https:/", "https://", 1)
  188 + }
  189 +
  190 + if strings.Index(path, "http:///") >= 0 {
  191 + return strings.Replace(path, "http:///", "http://", 1)
  192 + }
  193 + if strings.Index(path, "http://") >= 0 {
  194 + return strings.Replace(path, "http:///", "http://", 1)
  195 + }
  196 + if strings.Index(path, "http:/") >= 0 {
  197 + return strings.Replace(path, "http:/", "http://", 1)
  198 + }
  199 + return path
  200 +}
  201 +
179 //上传文件 202 //上传文件
180 func upload(path string, upAddress, upAuth string, options ...oss.Option) (err error) { 203 func upload(path string, upAddress, upAuth string, options ...oss.Option) (err error) {
181 var ( 204 var (
@@ -50,3 +50,22 @@ func Test_MyGetURLUploadInfos(t *testing.T) { @@ -50,3 +50,22 @@ func Test_MyGetURLUploadInfos(t *testing.T) {
50 fmt.Printf("%s: %s %s\n", uploadInfo.UploadURL, uploadInfo.Status, uploadInfo.MediaId) 50 fmt.Printf("%s: %s %s\n", uploadInfo.UploadURL, uploadInfo.Status, uploadInfo.MediaId)
51 } 51 }
52 } 52 }
  53 +
  54 +func Test_FixPath(t *testing.T) {
  55 + input := []struct {
  56 + Input string
  57 + Except string
  58 + }{
  59 + {Input: "https://123.jpg", Except: "https://123.jpg"},
  60 + {Input: "https:///123.jpg", Except: "https://123.jpg"},
  61 + {Input: "https:/123.jpg", Except: "https://123.jpg"},
  62 + {Input: "http://123.jpg", Except: "http://123.jpg"},
  63 + {Input: "http:///123.jpg", Except: "http://123.jpg"},
  64 + {Input: "http:/123.jpg", Except: "http://123.jpg"},
  65 + }
  66 + for i := 0; i < len(input); i++ {
  67 + if !strings.EqualFold(fixPath(input[i].Input), input[i].Except) {
  68 + t.Fatal("not equal input:", input[i].Input, "except:", input[i].Except, "out:", fixPath(input[i].Input))
  69 + }
  70 + }
  71 +}