From 0f2a02510076bd9078b73754f17c4137a3404c2f Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Thu, 13 Apr 2023 05:37:46 +0100 Subject: [PATCH 001/102] Update --- server/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/go.mod b/server/go.mod index 1631a93..fa094ec 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,6 +1,6 @@ module github.com/ystv/streamer/server -go 1.17 +go 1.19 require ( github.com/gorilla/mux v1.8.0 From d93637f0e0baa1976a73245b564fcf7d8e996f56 Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Thu, 13 Apr 2023 05:38:21 +0100 Subject: [PATCH 002/102] Commenting and changing the order --- server/main.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/main.go b/server/main.go index dba4876..ffdba4e 100644 --- a/server/main.go +++ b/server/main.go @@ -140,19 +140,19 @@ func main() { mux: mux.NewRouter(), cfg: cfg, } - web.mux.HandleFunc("/", web.home) //web.mux.HandleFunc("/authenticate1", web.authenticate1) - web.mux.HandleFunc("/endpoints", web.endpoints) - web.mux.HandleFunc("/streams", web.streams) - web.mux.HandleFunc("/start", web.start) - web.mux.HandleFunc("/resume", web.resume) - web.mux.HandleFunc("/status", web.status) - web.mux.HandleFunc("/stop", web.stop) - web.mux.HandleFunc("/list", web.list) - web.mux.HandleFunc("/save", web.save) - web.mux.HandleFunc("/recall", web.recall) - web.mux.HandleFunc("/youtubehelp", web.youtubeHelp) - web.mux.HandleFunc("/facebookhelp", web.facebookHelp) + web.mux.HandleFunc("/", web.home) // Default view + web.mux.HandleFunc("/endpoints", web.endpoints) // Call made by home to view endpoints + web.mux.HandleFunc("/streams", web.streams) // Call made by home to view all active streams for the endpoints + web.mux.HandleFunc("/start", web.start) // Call made by home to start forwarding + web.mux.HandleFunc("/resume", web.resume) // To return to the page that controls a stream + web.mux.HandleFunc("/status", web.status) // Call made by home to view status + web.mux.HandleFunc("/stop", web.stop) // Call made by home to stop forwarding + web.mux.HandleFunc("/list", web.list) // List view of current forwards + web.mux.HandleFunc("/save", web.save) // Where you can save a stream for later + web.mux.HandleFunc("/recall", web.recall) // Where you can recall a saved stream to modify it if needed and start it + web.mux.HandleFunc("/youtubehelp", web.youtubeHelp) // YouTube help page + web.mux.HandleFunc("/facebookhelp", web.facebookHelp) // Facebook help page web.mux.HandleFunc("/public/{id:[a-zA-Z0-9_.-]+}", web.public) // This handles all the public pages that the webpage can request, e.g. css, images and jquery fmt.Println("Server listening on port", web.cfg.ServerPort, "...") From 5c11fa427d273f3b8e6b91ac1a917111f1169a9b Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Thu, 13 Apr 2023 05:39:00 +0100 Subject: [PATCH 003/102] Functioned out this bit of repeated code --- server/main.go | 55 +++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/server/main.go b/server/main.go index ffdba4e..c5a32dc 100644 --- a/server/main.go +++ b/server/main.go @@ -382,24 +382,10 @@ func (web *Web) endpoints(w http.ResponseWriter, r *http.Request) { fmt.Printf("error loading .env file: %s", err) } - response, err := http.Get(web.cfg.StreamChecker) + streamPageContent, err := getBody(web.cfg.StreamChecker) if err != nil { fmt.Println(err) } - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - fmt.Println(err) - } - }(response.Body) - - buf := new(strings.Builder) - _, err = io.Copy(buf, response.Body) - if err != nil { - fmt.Println(err) - } - - streamPageContent := buf.String() var rtmp RTMP @@ -449,25 +435,11 @@ func (web *Web) streams(w http.ResponseWriter, r *http.Request) { fmt.Printf("error loading .env file: %s", err) } - response, err := http.Get(web.cfg.StreamChecker) - if err != nil { - fmt.Println(err) - } - defer func(Body io.ReadCloser) { - err := Body.Close() - if err != nil { - fmt.Println(err) - } - }(response.Body) - - buf := new(strings.Builder) - _, err = io.Copy(buf, response.Body) + streamPageContent, err := getBody(web.cfg.StreamChecker) if err != nil { fmt.Println(err) } - streamPageContent := buf.String() - var rtmp RTMP err = xml.Unmarshal([]byte(streamPageContent), &rtmp) @@ -1431,6 +1403,29 @@ func (web *Web) websiteCheck(endpoint string) bool { } } +func getBody(url string) (body string, err error) { + response, err := http.Get(url) + if err != nil { + return + } + defer func(Body io.ReadCloser) { + err = Body.Close() + if err != nil { + return + } + }(response.Body) + + buf := new(strings.Builder) + _, err = io.Copy(buf, response.Body) + if err != nil { + return + } + + body = buf.String() + + return +} + // existingStreamCheck checks if there are any existing streams still registered in the database func existingStreamCheck() bool { if verbose { From e406dff47a2ce366a10336a84f0dededbd25d9a6 Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Thu, 13 Apr 2023 05:39:57 +0100 Subject: [PATCH 004/102] Removed some redundant code, and fixed the tabs --- server/templates/main.tmpl | 822 +++++++++++++++-------------------- server/templates/recall.tmpl | 253 +++++------ server/templates/resume.tmpl | 218 +++++----- server/templates/save.tmpl | 254 +++++------ 4 files changed, 715 insertions(+), 832 deletions(-) diff --git a/server/templates/main.tmpl b/server/templates/main.tmpl index 36f5057..3902405 100644 --- a/server/templates/main.tmpl +++ b/server/templates/main.tmpl @@ -1,188 +1,199 @@ {{define "content"}} -
-
-
-

This tool allows you to select the endpoint that your streaming software is streaming to and then forward - it - onto - your platforms of choice.
- Streamer is designed to be simple to use, you select the endpoint that you are streaming to by selecting - the - possible endpoints using the checkboxes below and then pressing "Refresh streams".


-

Stream endpoint selector

-

Endpoints

-


-

Selection

-
-
+
+
+
+

This tool allows you to select the endpoint that your streaming software is streaming to and then + forward + it + onto + your platforms of choice.
+ Streamer is designed to be simple to use, you select the endpoint that you are streaming to by + selecting + the + possible endpoints using the checkboxes below and then pressing "Refresh streams".


+

Stream endpoint selector

+

Endpoints

+


+

Selection

+ +
+
+ +
- - -
+
-
-
-
-
+
+
+ -

After refreshing what streams are active, you can select the endpoint with the dropdown box below

-
-

Select stream

-
- - -
-

+

After refreshing what streams are active, you can select the endpoint with the dropdown box + below

+
+

Select stream

+
+ + +
+

- + +
-
-