|
@@ -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 (
|