@@ -20,6 +20,7 @@ import (
20
20
"github.com/ossrs/go-oryx-lib/errors"
21
21
ohttp "github.com/ossrs/go-oryx-lib/http"
22
22
"github.com/ossrs/go-oryx-lib/logger"
23
+
23
24
// Use v8 because we use Go 1.16+, while v9 requires Go 1.18+
24
25
"github.com/go-redis/redis/v8"
25
26
"github.com/google/uuid"
@@ -49,25 +50,19 @@ func (v *CameraWorker) GetTask(platform string) *CameraTask {
49
50
func (v * CameraWorker ) Handle (ctx context.Context , handler * http.ServeMux ) error {
50
51
ep := "/terraform/v1/ffmpeg/camera/secret"
51
52
logger .Tf (ctx , "Handle %v" , ep )
52
- handler .HandleFunc (ep , func (w http.ResponseWriter , r * http.Request ) {
53
+ handler .Handle (ep , middlewareAuthTokenInBody ( ctx , http . HandlerFunc ( func (w http.ResponseWriter , r * http.Request ) {
53
54
if err := func () error {
54
- var token , action string
55
+ var action string
55
56
var userConf CameraConfigure
56
57
if err := ParseBody (ctx , r .Body , & struct {
57
- Token * string `json:"token"`
58
58
Action * string `json:"action"`
59
59
* CameraConfigure
60
60
}{
61
- Token : & token , Action : & action , CameraConfigure : & userConf ,
61
+ Action : & action , CameraConfigure : & userConf ,
62
62
}); err != nil {
63
63
return errors .Wrapf (err , "parse body" )
64
64
}
65
65
66
- apiSecret := envApiSecret ()
67
- if err := Authenticate (ctx , apiSecret , token , r .Header ); err != nil {
68
- return errors .Wrapf (err , "authenticate" )
69
- }
70
-
71
66
allowedActions := []string {"update" }
72
67
allowedPlatforms := []string {"wx" , "bilibili" , "kuaishou" }
73
68
if action != "" {
@@ -122,7 +117,7 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
122
117
}
123
118
124
119
ohttp .WriteData (ctx , w , r , nil )
125
- logger .Tf (ctx , "Camera: update secret ok, token=%vB" , len ( token ) )
120
+ logger .Tf (ctx , "Camera: update secret ok" )
126
121
return nil
127
122
} else {
128
123
confObjs := make (map [string ]* CameraConfigure )
@@ -139,32 +134,18 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
139
134
}
140
135
141
136
ohttp .WriteData (ctx , w , r , confObjs )
142
- logger .Tf (ctx , "Camera: query configures ok, token=%vB" , len ( token ) )
137
+ logger .Tf (ctx , "Camera: query configures ok" )
143
138
return nil
144
139
}
145
140
}(); err != nil {
146
141
ohttp .WriteError (ctx , w , r , err )
147
142
}
148
- })
143
+ })))
149
144
150
145
ep = "/terraform/v1/ffmpeg/camera/streams"
151
146
logger .Tf (ctx , "Handle %v" , ep )
152
- handler .HandleFunc (ep , func (w http.ResponseWriter , r * http.Request ) {
147
+ handler .Handle (ep , middlewareAuthTokenInBody ( ctx , http . HandlerFunc ( func (w http.ResponseWriter , r * http.Request ) {
153
148
if err := func () error {
154
- var token string
155
- if err := ParseBody (ctx , r .Body , & struct {
156
- Token * string `json:"token"`
157
- }{
158
- Token : & token ,
159
- }); err != nil {
160
- return errors .Wrapf (err , "parse body" )
161
- }
162
-
163
- apiSecret := envApiSecret ()
164
- if err := Authenticate (ctx , apiSecret , token , r .Header ); err != nil {
165
- return errors .Wrapf (err , "authenticate" )
166
- }
167
-
168
149
res := make ([]map [string ]interface {}, 0 )
169
150
if configs , err := rdb .HGetAll (ctx , SRS_CAMERA_CONFIG ).Result (); err != nil && err != redis .Nil {
170
151
return errors .Wrapf (err , "hgetall %v" , SRS_CAMERA_CONFIG )
@@ -209,33 +190,26 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
209
190
})
210
191
211
192
ohttp .WriteData (ctx , w , r , res )
212
- logger .Tf (ctx , "Camera: Query streams ok, token=%vB" , len ( token ) )
193
+ logger .Tf (ctx , "Camera: Query streams ok" )
213
194
return nil
214
195
}(); err != nil {
215
196
ohttp .WriteError (ctx , w , r , err )
216
197
}
217
- })
198
+ })))
218
199
219
200
ep = "/terraform/v1/ffmpeg/camera/stream-url"
220
201
logger .Tf (ctx , "Handle %v" , ep )
221
- handler .HandleFunc (ep , func (w http.ResponseWriter , r * http.Request ) {
202
+ handler .Handle (ep , middlewareAuthTokenInBody ( ctx , http . HandlerFunc ( func (w http.ResponseWriter , r * http.Request ) {
222
203
if err := func () error {
223
- var token string
224
204
var qUrl string
225
205
if err := ParseBody (ctx , r .Body , & struct {
226
- Token * string `json:"token"`
227
206
StreamURL * string `json:"url"`
228
207
}{
229
- Token : & token , StreamURL : & qUrl ,
208
+ StreamURL : & qUrl ,
230
209
}); err != nil {
231
210
return errors .Wrapf (err , "parse body" )
232
211
}
233
212
234
- apiSecret := envApiSecret ()
235
- if err := Authenticate (ctx , apiSecret , token , r .Header ); err != nil {
236
- return errors .Wrapf (err , "authenticate" )
237
- }
238
-
239
213
// Parse URL to object.
240
214
u , err := RebuildStreamURL (qUrl )
241
215
if err != nil {
@@ -274,11 +248,11 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
274
248
}(); err != nil {
275
249
ohttp .WriteError (ctx , w , r , err )
276
250
}
277
- })
251
+ })))
278
252
279
253
ep = "/terraform/v1/ffmpeg/camera/source"
280
254
logger .Tf (ctx , "Handle %v" , ep )
281
- handler .HandleFunc (ep , func (w http.ResponseWriter , r * http.Request ) {
255
+ handler .Handle (ep , middlewareAuthTokenInBody ( ctx , http . HandlerFunc ( func (w http.ResponseWriter , r * http.Request ) {
282
256
if err := func () error {
283
257
type CameraTempFile struct {
284
258
// The file name.
@@ -293,23 +267,17 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
293
267
Type FFprobeSourceType `json:"type"`
294
268
}
295
269
296
- var token , platform string
270
+ var platform string
297
271
var streams []* CameraTempFile
298
272
if err := ParseBody (ctx , r .Body , & struct {
299
- Token * string `json:"token"`
300
273
Platform * string `json:"platform"`
301
274
Streams * []* CameraTempFile `json:"files"`
302
275
}{
303
- Token : & token , Platform : & platform , Streams : & streams ,
276
+ Platform : & platform , Streams : & streams ,
304
277
}); err != nil {
305
278
return errors .Wrapf (err , "parse body" )
306
279
}
307
280
308
- apiSecret := envApiSecret ()
309
- if err := Authenticate (ctx , apiSecret , token , r .Header ); err != nil {
310
- return errors .Wrapf (err , "authenticate" )
311
- }
312
-
313
281
if len (streams ) == 0 {
314
282
return errors .New ("no files" )
315
283
}
@@ -469,12 +437,12 @@ func (v *CameraWorker) Handle(ctx context.Context, handler *http.ServeMux) error
469
437
}{
470
438
Platform : platform , Files : parsedStreams ,
471
439
})
472
- logger .Tf (ctx , "Camera:: Update ok, token=%vB" , len ( token ) )
440
+ logger .Tf (ctx , "Camera:: Update ok" )
473
441
return nil
474
442
}(); err != nil {
475
443
ohttp .WriteError (ctx , w , r , err )
476
444
}
477
- })
445
+ })))
478
446
479
447
return nil
480
448
}
0 commit comments