vod.go
5.8 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package v1
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
oss "openapi/pkg/application/oss/service"
vod "openapi/pkg/application/vod/service"
"openapi/pkg/domain"
"openapi/pkg/infrastructure/aliyun"
"openapi/pkg/port/beego/controllers"
)
type VodController struct {
controllers.BaseController
}
//创建视频上传凭证 CreateUploadVideo
// @router /createUploadVideo [post]
func (this *VodController) CreateUploadVideo() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.CreateUploadVideoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
if len(request.FileName) == 0 {
request.FileName = aliyun.DefaultVideoFileName
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(vod.CreateUploadVideo(header, request))
}
//创建视频上传凭证(多个) CreateUploadVideos
// @router /createUploadVideos [post]
func (this *VodController) CreateUploadVideos() {
var msg *domain.ResponseMessage
var response *aliyun.CreateUploadVideosResponse = &aliyun.CreateUploadVideosResponse{
List: make([]*aliyun.CreateUploadVideoResponse, 0),
}
defer func() {
this.Resp(msg)
}()
var request *aliyun.CreateUploadVideosRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
var err error
if len(request.Items) == 0 {
msg = domain.BadRequestParam(2)
}
for i := range request.Items {
r := request.Items[i]
if rsp, e := vod.CreateUploadVideo(header, r); e != nil {
err = e
break
} else {
response.List = append(response.List, rsp)
}
}
msg = domain.NewReturnResponse(response, err)
}
//刷新视频上传凭证 RefreshUploadVideo
// @router /refreshUploadVideo [post]
func (this *VodController) RefreshUploadVideo() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.RefreshUploadVideoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(vod.RefreshUploadVideo(header, request))
}
//创建图片上传凭证 CreateUploadImage
// @router /createUploadImage [post]
func (this *VodController) CreateUploadImage() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.CreateUploadImageRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(vod.CreateUploadImage(header, request))
}
//创建图片上传凭证 CreateUploadImages
// @router /createUploadImages [post]
func (this *VodController) CreateUploadImages() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var (
request *aliyun.CreateUploadImagesRequest
response *aliyun.CreateUploadImagesResponse = &aliyun.CreateUploadImagesResponse{
List: make([]*aliyun.CreateUploadImageResponse, 0),
}
)
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
var err error
if len(request.Items) == 0 {
msg = domain.BadRequestParam(2)
}
header := controllers.GetRequestHeader(this.Ctx)
for i := range request.Items {
r := request.Items[i]
if rsp, e := vod.CreateUploadImage(header, r); e != nil {
err = e
break
} else {
response.List = append(response.List, rsp)
}
}
msg = domain.NewReturnResponse(response, err)
}
//获取视频播放地址 GetPlayInfo
// @router /getPlayInfo [post]
func (this *VodController) GetPlayInfo() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.GetPlayInfoRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(vod.GetPlayInfo(header, request))
}
//获取视频播放凭证 GetVideoPlayAuth
// @router /getVideoPlayAuth [post]
func (this *VodController) GetVideoPlayAuth() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *aliyun.GetVideoPlayAuthRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(vod.GetVideoPlayAuth(header, request))
}
//归档对象 PutObject
// @router /putObject [post]
func (this *VodController) PutObject() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm))
}
// STS授权 CreateStsAuth
// @router /createStsAuth [post]
func (this *VodController) CreateStsAuth() {
var msg *domain.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request []string
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = domain.BadRequestParam(1)
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = domain.NewReturnResponse(oss.CreateStsAuth(header, request))
}