作者 yangfu

修改 媒体数据迁移

@@ -2,6 +2,7 @@ package aliyun @@ -2,6 +2,7 @@ package aliyun
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
  5 + "net/url"
5 "testing" 6 "testing"
6 ) 7 )
7 8
@@ -15,3 +16,28 @@ func Test_GetFile(t *testing.T) { @@ -15,3 +16,28 @@ func Test_GetFile(t *testing.T) {
15 n, _ := buf.ReadFrom(io) 16 n, _ := buf.ReadFrom(io)
16 t.Log("read from reader:", n) 17 t.Log("read from reader:", n)
17 } 18 }
  19 +
  20 +func Test_FileUrl(t *testing.T) {
  21 + input := []struct {
  22 + Module string
  23 + Input string
  24 + Except string
  25 + }{
  26 + {
  27 + Module: "UrlParse",
  28 + Input: "http://mmm-opp-dev.fjmaimaimai.com/file/opp/image/20200106/1578297295_RxJscRHCzQmxeseTAEQXTH7A7ZK6z4Fz.jpg",
  29 + Except: "/file/opp/image/20200106/1578297295_RxJscRHCzQmxeseTAEQXTH7A7ZK6z4Fz.jpg",
  30 + },
  31 + }
  32 +
  33 + urlIn := input[0]
  34 + urlRaw, err := url.Parse(urlIn.Input)
  35 + if err != nil {
  36 + t.Fatal(err)
  37 + }
  38 + if urlRaw.Path != urlIn.Except {
  39 + t.Fatal(urlIn.Module, "Input:", urlIn.Input, "Out:", urlRaw.Path, "Except:", urlIn.Except)
  40 + }
  41 + urlRaw.Scheme = "https"
  42 + //t.Log(urlRaw.String())
  43 +}
@@ -188,6 +188,32 @@ func UploadMediaByURL(urls []string, callBack *CallBack, extend interface{}) (re @@ -188,6 +188,32 @@ func UploadMediaByURL(urls []string, callBack *CallBack, extend interface{}) (re
188 return client.UploadMediaByURL(request) 188 return client.UploadMediaByURL(request)
189 } 189 }
190 190
  191 +//通过oss上传图片
  192 +func OssUploadImageByUrl(rawurl string) (response *CreateUploadImageResponse, err error) {
  193 + var (
  194 + vodc *vod.Client
  195 + imageRsp *CreateUploadImageResponse
  196 + client *OSSClient
  197 + )
  198 + u, err := url.Parse(rawurl)
  199 + if err != nil {
  200 + return
  201 + }
  202 + imageRsp, err = CreateUploadImage(vodc, &CreateUploadImageRequest{FileName: u.Path})
  203 + if err != nil {
  204 + return
  205 + }
  206 + client, err = NewStsOSSClient(imageRsp.UploadAddress, imageRsp.UploadAuth)
  207 + if err != nil {
  208 + return
  209 + }
  210 + err = client.PutObjectByUrlDefault(rawurl)
  211 + if err != nil {
  212 + return
  213 + }
  214 + return
  215 +}
  216 +
191 func assertMarsh(v interface{}) string { 217 func assertMarsh(v interface{}) string {
192 data, e := json.Marshal(v) 218 data, e := json.Marshal(v)
193 if e != nil { 219 if e != nil {
@@ -61,6 +61,7 @@ func MigrateChanceDataToAliYun() { @@ -61,6 +61,7 @@ func MigrateChanceDataToAliYun() {
61 } 61 }
62 } 62 }
63 63
  64 +//上传图片
64 func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { 65 func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
65 utils.JsonUnmarshal(img, &rsp) 66 utils.JsonUnmarshal(img, &rsp)
66 if len(rsp) == 0 { 67 if len(rsp) == 0 {
@@ -118,6 +119,12 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) { @@ -118,6 +119,12 @@ func uploadImages(d *models.ChanceData, img string) (rsp []protocol.Picture) {
118 return 119 return
119 } 120 }
120 121
  122 +//上班媒体数据
  123 +func uploadVoice(d *models.ChanceData, url string) (rp []protocol.Speech) {
  124 + //
  125 + return nil
  126 +}
  127 +
121 type ChanceDataExtend struct { 128 type ChanceDataExtend struct {
122 Id int64 `json:"id"` 129 Id int64 `json:"id"`
123 ChanceId int64 `json:"chance_id"` 130 ChanceId int64 `json:"chance_id"`