From 63aae590d59564b549cea4ee12562f36eb547c01 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 25 Jul 2020 13:19:17 +0000 Subject: [PATCH] added inputs for interval/motion interval on the addStream page --- main.go | 38 ++++++++++++++++++++++++++++++++++---- stream.go | 6 +++--- templates/add_stream.html | 11 +++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 804f0e1..c634b81 100755 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "path/filepath" + "strconv" "text/template" ) @@ -47,21 +48,46 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) { func (server Server) addStream(w http.ResponseWriter, r *http.Request) { nameMessage := "" URLMessage := "" + intervalMessage := "" + motionIntervalMessage := "" if r.Method == "POST" { name := r.FormValue("name") URL := r.FormValue("URL") + interval := r.FormValue("interval") + motionInterval := r.FormValue("motion_interval") if name == "" { nameMessage = "Name is required" } if URL == "" { URLMessage = "URL is required" } + if interval == "" { + intervalMessage = "Interval is required" + } + if motionInterval == "" { + motionIntervalMessage = "MotionInterval is required" + } _, exists := server.Streams[name] if exists { nameMessage = "Name already used" } - if !exists && name != "" && URL != "" { - server.Streams[name] = NewStream(name, URL) + if !exists && name != "" && URL != "" && interval != "" && motionInterval != "" { + intInterval, err := strconv.ParseInt(interval, 10, 64) + if err != nil { + log.Println("Illigal value for Interval: ", interval) + intInterval = 5000 + } + intMotionInterval, err := strconv.ParseInt(motionInterval, 10, 64) + if err != nil { + log.Println("Illigal value for MotionInterval: ", motionInterval) + intMotionInterval = 1000 + } + server.Streams[name] = NewStream( + name, + URL, + (int)(intInterval), + (int)(intMotionInterval), + ) go server.Streams[name].UpdateInterval() http.Redirect(w, r, "/", http.StatusTemporaryRedirect) } @@ -73,11 +99,15 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) { return } addStreamTemplate.Execute(w, struct { - NameMessage string - URLMessage string + NameMessage string + URLMessage string + IntervalMessage string + MotionIntervalMessage string }{ nameMessage, URLMessage, + intervalMessage, + motionIntervalMessage, }) } diff --git a/stream.go b/stream.go index f62ec7d..af27c88 100755 --- a/stream.go +++ b/stream.go @@ -30,15 +30,15 @@ type Stream struct { } // NewStream creates a new Stream Object -func NewStream(Name string, URL string) *Stream { +func NewStream(Name string, URL string, Interval int, MotionInterval int) *Stream { base64 := URLToBase64(URL) stream := Stream{ Name: Name, URL: URL, Base64: base64, - Interval: 5000, - MotionInterval: 500, + Interval: Interval, + MotionInterval: MotionInterval, WatchAreas: make([]WatchArea, 0), Timeouts: 0, MotionDetected: false, diff --git a/templates/add_stream.html b/templates/add_stream.html index 007606c..01d4f21 100755 --- a/templates/add_stream.html +++ b/templates/add_stream.html @@ -1,5 +1,6 @@ {{template "base" .}} {{define "head"}} + {{end}} {{define "content"}}

Add Stream

@@ -7,9 +8,19 @@ {{.NameMessage}} + {{.URLMessage}} + + + + {{.IntervalMessage}} + + + + {{.MotionIntervalMessage}} + {{end}} \ No newline at end of file