Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 93ffaec

Browse files
authored
Merge pull request #44 from Roverr/fix/blacklist
2 parents cf22852 + ea807fe commit 93ffaec

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

core/controller.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ type SummariseDTO struct {
5252

5353
// IController describes main functions for the controller
5454
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
6666
}
6767

6868
// Controller holds all handler functions for the API
@@ -93,7 +93,7 @@ func NewController(spec *config.Specification, fileServer http.Handler) *Control
9393
map[string]string{},
9494
map[string]string{},
9595
map[string]string{},
96-
nil,
96+
(*blacklist.List)(nil),
9797
fileServer,
9898
time.Second * 15,
9999
provider,
@@ -225,9 +225,9 @@ func (c *Controller) sendStart(w http.ResponseWriter, success bool, stream *stre
225225
if len(alias) > 0 {
226226
name = alias
227227
}
228-
Uri := fmt.Sprintf("/stream/%s/index.m3u8", name)
228+
URI := fmt.Sprintf("/stream/%s/index.m3u8", name)
229229

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})
231231
w.Header().Add("Content-Type", "application/json")
232232
w.Write(b)
233233
}
@@ -254,17 +254,17 @@ func (c *Controller) ListStreamHandler(w http.ResponseWriter, r *http.Request, _
254254
URI: fmt.Sprintf("/stream/%s/index.m3u8", newKey),
255255
Running: stream.Streak.IsActive(),
256256
ID: stream.ID,
257-
Alias: aliasName,
257+
Alias: aliasName,
258258
})
259259
}
260260

261261
// preload streams
262-
for name, _ := range c.preload {
262+
for name := range c.preload {
263263
dto = append(dto, &SummariseDTO{
264264
URI: fmt.Sprintf("/stream/%s/index.m3u8", name),
265265
Running: false,
266266
ID: "",
267-
Alias: name,
267+
Alias: name,
268268
})
269269
}
270270

@@ -327,16 +327,16 @@ func (c *Controller) StopStreamHandler(w http.ResponseWriter, r *http.Request, p
327327
w.WriteHeader(http.StatusOK)
328328
}
329329

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)
332332

333-
_, knownStream := c.index[Uri]
333+
_, knownStream := c.index[URI]
334334
if knownStream {
335335
return
336336
}
337337

338338
stream, id := streamer.NewStream(
339-
Uri,
339+
URI,
340340
c.spec.StoreDir,
341341
c.spec.KeepFiles,
342342
c.spec.Audio,
@@ -354,19 +354,19 @@ func (c *Controller) startPreloadStream(Alias string, Uri string) {
354354
streamName := id
355355
stream.Start().Wait()
356356
if !stream.Running {
357-
if c.blacklist.AddOrIncrease(Uri).IsBanned(Uri) {
357+
if c.blacklist.AddOrIncrease(URI).IsBanned(URI) {
358358
delete(c.preload, Alias)
359359
}
360360
return
361361
}
362362

363363
c.streams[id] = stream
364-
c.index[Uri] = id
364+
c.index[URI] = id
365365
if len(Alias) > 0 {
366366
c.alias[Alias] = id
367367
streamName = Alias
368368
}
369-
c.blacklist.Remove(Uri)
369+
c.blacklist.Remove(URI)
370370
delete(c.preload, Alias)
371371

372372
logrus.Infoln("started stream /stream/" + streamName + "/index.m3u8")

0 commit comments

Comments
 (0)