vod.go
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package service
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/pkg/constant"
protocol "openapi/pkg/domain"
"openapi/pkg/infrastructure/aliyun"
"openapi/pkg/infrastructure/utils"
)
//创建视频上传凭证
func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUploadVideoRequest) (rsp *aliyun.CreateUploadVideoResponse, err error) {
var (
up aliyun.UploadAddress
filePath string
fileName = request.FileName
)
defer func() {
err = ErrorHandler(err)
}()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
if aliyun.ValidFileExt(aliyun.VideoFileExt, request.FileName) {
filePath = utils.GetFileName(header.AppProject, aliyun.FileVideo, request.FileName)
} else if aliyun.ValidFileExt(aliyun.VoiceFileExt, request.FileName) {
filePath = utils.GetFileName(header.AppProject, aliyun.FileVoice, request.FileName)
} else {
err = aliyun.OssErrFileFormat
return
}
request.FileName = filePath
request.Title = filePath
rsp, err = aliyun.CreateUploadVideo(client, request)
if err != nil {
log.Error(err)
return
}
if up, err = aliyun.ParseUploadAddress(rsp.UploadAddress); err != nil {
log.Error(err)
return
}
rsp.FileName = fileName
rsp.FileURL = up.GetFileUrl(constant.CName)
return
}
//创建视频上传凭证
func RefreshUploadVideo(header *protocol.RequestHeader, request *aliyun.RefreshUploadVideoRequest) (rsp *aliyun.RefreshUploadVideoResponse, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
rsp, err = aliyun.RefreshUploadVideo(client, request)
if err != nil {
log.Error(err)
}
return
}
//创建图片上传凭证
func CreateUploadImage(header *protocol.RequestHeader, request *aliyun.CreateUploadImageRequest) (rsp *aliyun.CreateUploadImageResponse, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultImageFileName
}
if !aliyun.ValidFileExt(aliyun.ImageFileExt, request.FileName) {
return nil, protocol.NewCustomMessage(1, aliyun.OssErrFileFormat.Error())
}
request.Title = utils.GetFileName(header.AppProject, aliyun.FileImage, request.FileName)
rsp, err = aliyun.CreateUploadImage(client, request)
if err != nil {
log.Error(err)
return
}
rsp.FileURL = rsp.ImageURL
rsp.FileName = request.FileName
return
}
//获取视频播放地址
func GetPlayInfo(header *protocol.RequestHeader, request *aliyun.GetPlayInfoRequest) (rsp interface{}, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
rsp, err = aliyun.GetPlayInfo(client, request)
if err != nil {
log.Error(err)
}
return
}
//获取视频播放凭证
func GetVideoPlayAuth(header *protocol.RequestHeader, request *aliyun.GetVideoPlayAuthRequest) (rsp interface{}, err error) {
var ()
client, e := aliyun.DefaultVodClient()
if e != nil {
log.Error(e)
err = e
return
}
rsp, err = aliyun.GetGetVideoPlayAuth(client, request)
if err != nil {
log.Error(err)
}
return
}