正在显示
2 个修改的文件
包含
233 行增加
和
0 行删除
pkg/port/beego/controllers/v2/vod.go
0 → 100644
1 | +package v2 | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
6 | + oss "openapi/pkg/application/oss/service" | ||
7 | + vod "openapi/pkg/application/vod/service" | ||
8 | + "openapi/pkg/domain" | ||
9 | + "openapi/pkg/infrastructure/aliyun" | ||
10 | + "openapi/pkg/port/beego/controllers" | ||
11 | +) | ||
12 | + | ||
13 | +type VodController struct { | ||
14 | + controllers.BaseController | ||
15 | +} | ||
16 | + | ||
17 | +//创建视频上传凭证 CreateUploadVideo | ||
18 | +// @router /createUploadVideo [post] | ||
19 | +func (this *VodController) CreateUploadVideo() { | ||
20 | + var msg *domain.ResponseMessage | ||
21 | + defer func() { | ||
22 | + this.Resp(msg) | ||
23 | + }() | ||
24 | + var request *aliyun.CreateUploadVideoRequest | ||
25 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
26 | + log.Error(err) | ||
27 | + msg = domain.BadRequestParam(1) | ||
28 | + return | ||
29 | + } | ||
30 | + if b, m := this.Valid(request); !b { | ||
31 | + msg = m | ||
32 | + return | ||
33 | + } | ||
34 | + if len(request.FileName) == 0 { | ||
35 | + request.FileName = aliyun.DefaultVideoFileName | ||
36 | + } | ||
37 | + header := controllers.GetRequestHeader(this.Ctx) | ||
38 | + msg = domain.NewReturnResponse(vod.CreateUploadVideo(header, request)) | ||
39 | +} | ||
40 | + | ||
41 | +//创建视频上传凭证(多个) CreateUploadVideos | ||
42 | +// @router /createUploadVideos [post] | ||
43 | +func (this *VodController) CreateUploadVideos() { | ||
44 | + var msg *domain.ResponseMessage | ||
45 | + var response *aliyun.CreateUploadVideosResponse = &aliyun.CreateUploadVideosResponse{ | ||
46 | + List: make([]*aliyun.CreateUploadVideoResponse, 0), | ||
47 | + } | ||
48 | + defer func() { | ||
49 | + this.Resp(msg) | ||
50 | + }() | ||
51 | + var request *aliyun.CreateUploadVideosRequest | ||
52 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
53 | + log.Error(err) | ||
54 | + msg = domain.BadRequestParam(1) | ||
55 | + return | ||
56 | + } | ||
57 | + if b, m := this.Valid(request); !b { | ||
58 | + msg = m | ||
59 | + return | ||
60 | + } | ||
61 | + header := controllers.GetRequestHeader(this.Ctx) | ||
62 | + var err error | ||
63 | + if len(request.Items) == 0 { | ||
64 | + msg = domain.BadRequestParam(2) | ||
65 | + } | ||
66 | + for i := range request.Items { | ||
67 | + r := request.Items[i] | ||
68 | + if rsp, e := vod.CreateUploadVideo(header, r); e != nil { | ||
69 | + err = e | ||
70 | + break | ||
71 | + } else { | ||
72 | + response.List = append(response.List, rsp) | ||
73 | + } | ||
74 | + } | ||
75 | + msg = domain.NewReturnResponse(response, err) | ||
76 | +} | ||
77 | + | ||
78 | +//刷新视频上传凭证 RefreshUploadVideo | ||
79 | +// @router /refreshUploadVideo [post] | ||
80 | +func (this *VodController) RefreshUploadVideo() { | ||
81 | + var msg *domain.ResponseMessage | ||
82 | + defer func() { | ||
83 | + this.Resp(msg) | ||
84 | + }() | ||
85 | + var request *aliyun.RefreshUploadVideoRequest | ||
86 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
87 | + log.Error(err) | ||
88 | + msg = domain.BadRequestParam(1) | ||
89 | + return | ||
90 | + } | ||
91 | + if b, m := this.Valid(request); !b { | ||
92 | + msg = m | ||
93 | + return | ||
94 | + } | ||
95 | + header := controllers.GetRequestHeader(this.Ctx) | ||
96 | + msg = domain.NewReturnResponse(vod.RefreshUploadVideo(header, request)) | ||
97 | +} | ||
98 | + | ||
99 | +//创建图片上传凭证 CreateUploadImage | ||
100 | +// @router /createUploadImage [post] | ||
101 | +func (this *VodController) CreateUploadImage() { | ||
102 | + var msg *domain.ResponseMessage | ||
103 | + defer func() { | ||
104 | + this.Resp(msg) | ||
105 | + }() | ||
106 | + var request *aliyun.CreateUploadImageRequest | ||
107 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
108 | + log.Error(err) | ||
109 | + msg = domain.BadRequestParam(1) | ||
110 | + return | ||
111 | + } | ||
112 | + if b, m := this.Valid(request); !b { | ||
113 | + msg = m | ||
114 | + return | ||
115 | + } | ||
116 | + | ||
117 | + header := controllers.GetRequestHeader(this.Ctx) | ||
118 | + msg = domain.NewReturnResponse(vod.CreateUploadImage(header, request)) | ||
119 | +} | ||
120 | + | ||
121 | +//创建图片上传凭证 CreateUploadImages | ||
122 | +// @router /createUploadImages [post] | ||
123 | +func (this *VodController) CreateUploadImages() { | ||
124 | + var msg *domain.ResponseMessage | ||
125 | + defer func() { | ||
126 | + this.Resp(msg) | ||
127 | + }() | ||
128 | + var ( | ||
129 | + request *aliyun.CreateUploadImagesRequest | ||
130 | + response *aliyun.CreateUploadImagesResponse = &aliyun.CreateUploadImagesResponse{ | ||
131 | + List: make([]*aliyun.CreateUploadImageResponse, 0), | ||
132 | + } | ||
133 | + ) | ||
134 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
135 | + log.Error(err) | ||
136 | + msg = domain.BadRequestParam(1) | ||
137 | + return | ||
138 | + } | ||
139 | + if b, m := this.Valid(request); !b { | ||
140 | + msg = m | ||
141 | + return | ||
142 | + } | ||
143 | + var err error | ||
144 | + if len(request.Items) == 0 { | ||
145 | + msg = domain.BadRequestParam(2) | ||
146 | + } | ||
147 | + header := controllers.GetRequestHeader(this.Ctx) | ||
148 | + for i := range request.Items { | ||
149 | + r := request.Items[i] | ||
150 | + if rsp, e := vod.CreateUploadImage(header, r); e != nil { | ||
151 | + err = e | ||
152 | + break | ||
153 | + } else { | ||
154 | + response.List = append(response.List, rsp) | ||
155 | + } | ||
156 | + } | ||
157 | + msg = domain.NewReturnResponse(response, err) | ||
158 | +} | ||
159 | + | ||
160 | +//获取视频播放地址 GetPlayInfo | ||
161 | +// @router /getPlayInfo [post] | ||
162 | +func (this *VodController) GetPlayInfo() { | ||
163 | + var msg *domain.ResponseMessage | ||
164 | + defer func() { | ||
165 | + this.Resp(msg) | ||
166 | + }() | ||
167 | + var request *aliyun.GetPlayInfoRequest | ||
168 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
169 | + log.Error(err) | ||
170 | + msg = domain.BadRequestParam(1) | ||
171 | + return | ||
172 | + } | ||
173 | + if b, m := this.Valid(request); !b { | ||
174 | + msg = m | ||
175 | + return | ||
176 | + } | ||
177 | + header := controllers.GetRequestHeader(this.Ctx) | ||
178 | + msg = domain.NewReturnResponse(vod.GetPlayInfo(header, request)) | ||
179 | +} | ||
180 | + | ||
181 | +//获取视频播放凭证 GetVideoPlayAuth | ||
182 | +// @router /getVideoPlayAuth [post] | ||
183 | +func (this *VodController) GetVideoPlayAuth() { | ||
184 | + var msg *domain.ResponseMessage | ||
185 | + defer func() { | ||
186 | + this.Resp(msg) | ||
187 | + }() | ||
188 | + var request *aliyun.GetVideoPlayAuthRequest | ||
189 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
190 | + log.Error(err) | ||
191 | + msg = domain.BadRequestParam(1) | ||
192 | + return | ||
193 | + } | ||
194 | + if b, m := this.Valid(request); !b { | ||
195 | + msg = m | ||
196 | + return | ||
197 | + } | ||
198 | + header := controllers.GetRequestHeader(this.Ctx) | ||
199 | + msg = domain.NewReturnResponse(vod.GetVideoPlayAuth(header, request)) | ||
200 | +} | ||
201 | + | ||
202 | +//归档对象 PutObject | ||
203 | +// @router /putObject [post] | ||
204 | +func (this *VodController) PutObject() { | ||
205 | + var msg *domain.ResponseMessage | ||
206 | + defer func() { | ||
207 | + this.Resp(msg) | ||
208 | + }() | ||
209 | + | ||
210 | + header := controllers.GetRequestHeader(this.Ctx) | ||
211 | + msg = domain.NewReturnResponse(oss.CreateOssUpload(header, this.Ctx.Request.MultipartForm)) | ||
212 | +} | ||
213 | + | ||
214 | +// STS授权 CreateStsAuth | ||
215 | +// @router /createStsAuth [post] | ||
216 | +func (this *VodController) CreateStsAuth() { | ||
217 | + var msg *domain.ResponseMessage | ||
218 | + defer func() { | ||
219 | + this.Resp(msg) | ||
220 | + }() | ||
221 | + var request = struct { | ||
222 | + FileNames []string `json:"files"` | ||
223 | + }{} | ||
224 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
225 | + log.Error(err) | ||
226 | + msg = domain.BadRequestParam(1) | ||
227 | + return | ||
228 | + } | ||
229 | + header := controllers.GetRequestHeader(this.Ctx) | ||
230 | + msg = domain.NewReturnResponse(oss.CreateStsAuth(header, request.FileNames)) | ||
231 | +} |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "openapi/pkg/constant" | 5 | "openapi/pkg/constant" |
6 | "openapi/pkg/port/beego/controllers" | 6 | "openapi/pkg/port/beego/controllers" |
7 | "openapi/pkg/port/beego/controllers/v1" | 7 | "openapi/pkg/port/beego/controllers/v1" |
8 | + v2 "openapi/pkg/port/beego/controllers/v2" | ||
8 | ) | 9 | ) |
9 | 10 | ||
10 | var nsV1 *beego.Namespace | 11 | var nsV1 *beego.Namespace |
@@ -16,5 +17,6 @@ func init() { | @@ -16,5 +17,6 @@ func init() { | ||
16 | beego.NSNamespace("sms", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.SmsController{})), | 17 | beego.NSNamespace("sms", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.SmsController{})), |
17 | ) | 18 | ) |
18 | beego.SetStaticPath("/log/NIONkenfieldon", constant.LogFilePath) | 19 | beego.SetStaticPath("/log/NIONkenfieldon", constant.LogFilePath) |
20 | + beego.Router("/v2/vod/createStsAuth", &v2.VodController{}, "Post:CreateStsAuth") | ||
19 | beego.AddNamespace(nsV1) | 21 | beego.AddNamespace(nsV1) |
20 | } | 22 | } |
-
请 注册 或 登录 后发表评论