creating moments json in backend with json.Marshal instead of looping in template

This commit is contained in:
BroodjeAap 2020-08-09 15:12:03 +00:00
parent 5b26865959
commit 5978e560f0
2 changed files with 9 additions and 13 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"encoding/json"
"image"
"image/color"
"io/ioutil"
@ -253,13 +254,16 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
log.Println(err)
return
}
momentsJSON, _ := json.Marshal(moments)
err = momentsTemplate.Execute(w, struct {
Streams map[string]*Stream
MomentsJSON string
Moments [][]string
Stream *Stream
WatchArea *WatchArea
}{
server.Streams,
string(momentsJSON[:]),
moments,
stream,
watchArea,

View file

@ -34,14 +34,6 @@
let streamName = "{{.Stream.Name}}";
let watchAreaName = "{{.WatchArea.Name}}";
let interval = {{.Stream.MotionInterval}};
let moments = [
{{range $moment := .Moments}}
[
{{range $image := $moment}}
'{{$image}}',
{{end}}
],
{{end}}
];
let moments = {{.MomentsJSON}}
</script>
{{end}}