@@ -52,17 +52,17 @@ type SummariseDTO struct {
52
52
53
53
// IController describes main functions for the controller
54
54
type IController interface {
55
- marshalValidatedURI (dto * StreamDTO , body io.Reader ) error // marshals and validates request body for /start
56
- getIDByPath (path string ) string // determines ID from the file access URL
57
- isAuthenticated (r * http.Request , endpoint string ) bool // enforces JWT authentication if config is enabled
58
- stopInactiveStreams () // used periodically to stop streams
59
- sendError (w http.ResponseWriter , err error , status int ) // used by Handlers to send out errors
60
- sendStart (w http.ResponseWriter , success bool , stream * streamer.Stream , alias string ) // used by start to send out response
61
- ListStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - GET /list
62
- StartStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - POST /start
63
- StaticFileHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - GET /stream/{id}/{file}
64
- StopStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - POST /stop
65
- ExitPreHook () chan bool // runs before the application exits to clean up
55
+ marshalValidatedURI (dto * StreamDTO , body io.Reader ) error // marshals and validates request body for /start
56
+ getIDByPath (path string ) string // determines ID from the file access URL
57
+ isAuthenticated (r * http.Request , endpoint string ) bool // enforces JWT authentication if config is enabled
58
+ stopInactiveStreams () // used periodically to stop streams
59
+ sendError (w http.ResponseWriter , err error , status int ) // used by Handlers to send out errors
60
+ sendStart (w http.ResponseWriter , success bool , stream * streamer.Stream , alias string ) // used by start to send out response
61
+ ListStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - GET /list
62
+ StartStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - POST /start
63
+ StaticFileHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - GET /stream/{id}/{file}
64
+ StopStreamHandler (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) // handler - POST /stop
65
+ ExitPreHook () chan bool // runs before the application exits to clean up
66
66
}
67
67
68
68
// Controller holds all handler functions for the API
@@ -93,7 +93,7 @@ func NewController(spec *config.Specification, fileServer http.Handler) *Control
93
93
map [string ]string {},
94
94
map [string ]string {},
95
95
map [string ]string {},
96
- nil ,
96
+ ( * blacklist . List )( nil ) ,
97
97
fileServer ,
98
98
time .Second * 15 ,
99
99
provider ,
@@ -225,9 +225,9 @@ func (c *Controller) sendStart(w http.ResponseWriter, success bool, stream *stre
225
225
if len (alias ) > 0 {
226
226
name = alias
227
227
}
228
- Uri := fmt .Sprintf ("/stream/%s/index.m3u8" , name )
228
+ URI := fmt .Sprintf ("/stream/%s/index.m3u8" , name )
229
229
230
- b , _ := json .Marshal (SummariseDTO {URI : Uri , Running : true , ID : stream .ID , Alias : alias })
230
+ b , _ := json .Marshal (SummariseDTO {URI : URI , Running : true , ID : stream .ID , Alias : alias })
231
231
w .Header ().Add ("Content-Type" , "application/json" )
232
232
w .Write (b )
233
233
}
@@ -254,17 +254,17 @@ func (c *Controller) ListStreamHandler(w http.ResponseWriter, r *http.Request, _
254
254
URI : fmt .Sprintf ("/stream/%s/index.m3u8" , newKey ),
255
255
Running : stream .Streak .IsActive (),
256
256
ID : stream .ID ,
257
- Alias : aliasName ,
257
+ Alias : aliasName ,
258
258
})
259
259
}
260
260
261
261
// preload streams
262
- for name , _ := range c .preload {
262
+ for name := range c .preload {
263
263
dto = append (dto , & SummariseDTO {
264
264
URI : fmt .Sprintf ("/stream/%s/index.m3u8" , name ),
265
265
Running : false ,
266
266
ID : "" ,
267
- Alias : name ,
267
+ Alias : name ,
268
268
})
269
269
}
270
270
@@ -327,16 +327,16 @@ func (c *Controller) StopStreamHandler(w http.ResponseWriter, r *http.Request, p
327
327
w .WriteHeader (http .StatusOK )
328
328
}
329
329
330
- func (c * Controller ) startPreloadStream (Alias string , Uri string ) {
331
- logrus .Debugf ("%s is being initialized" , Uri )
330
+ func (c * Controller ) startPreloadStream (Alias string , URI string ) {
331
+ logrus .Debugf ("%s is being initialized" , URI )
332
332
333
- _ , knownStream := c .index [Uri ]
333
+ _ , knownStream := c .index [URI ]
334
334
if knownStream {
335
335
return
336
336
}
337
337
338
338
stream , id := streamer .NewStream (
339
- Uri ,
339
+ URI ,
340
340
c .spec .StoreDir ,
341
341
c .spec .KeepFiles ,
342
342
c .spec .Audio ,
@@ -354,19 +354,19 @@ func (c *Controller) startPreloadStream(Alias string, Uri string) {
354
354
streamName := id
355
355
stream .Start ().Wait ()
356
356
if ! stream .Running {
357
- if c .blacklist .AddOrIncrease (Uri ).IsBanned (Uri ) {
357
+ if c .blacklist .AddOrIncrease (URI ).IsBanned (URI ) {
358
358
delete (c .preload , Alias )
359
359
}
360
360
return
361
361
}
362
362
363
363
c .streams [id ] = stream
364
- c .index [Uri ] = id
364
+ c .index [URI ] = id
365
365
if len (Alias ) > 0 {
366
366
c .alias [Alias ] = id
367
367
streamName = Alias
368
368
}
369
- c .blacklist .Remove (Uri )
369
+ c .blacklist .Remove (URI )
370
370
delete (c .preload , Alias )
371
371
372
372
logrus .Infoln ("started stream /stream/" + streamName + "/index.m3u8" )
0 commit comments