creating moments json in backend with json.Marshal instead of looping in template
This commit is contained in:
parent
5b26865959
commit
5978e560f0
2 changed files with 9 additions and 13 deletions
12
main.go
12
main.go
|
|
@ -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
|
||||
Moments [][]string
|
||||
Stream *Stream
|
||||
WatchArea *WatchArea
|
||||
Streams map[string]*Stream
|
||||
MomentsJSON string
|
||||
Moments [][]string
|
||||
Stream *Stream
|
||||
WatchArea *WatchArea
|
||||
}{
|
||||
server.Streams,
|
||||
string(momentsJSON[:]),
|
||||
moments,
|
||||
stream,
|
||||
watchArea,
|
||||
|
|
|
|||
|
|
@ -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}}
|
||||
Loading…
Add table
Reference in a new issue