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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -253,13 +254,16 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
momentsJSON, _ := json.Marshal(moments)
|
||||||
err = momentsTemplate.Execute(w, struct {
|
err = momentsTemplate.Execute(w, struct {
|
||||||
Streams map[string]*Stream
|
Streams map[string]*Stream
|
||||||
Moments [][]string
|
MomentsJSON string
|
||||||
Stream *Stream
|
Moments [][]string
|
||||||
WatchArea *WatchArea
|
Stream *Stream
|
||||||
|
WatchArea *WatchArea
|
||||||
}{
|
}{
|
||||||
server.Streams,
|
server.Streams,
|
||||||
|
string(momentsJSON[:]),
|
||||||
moments,
|
moments,
|
||||||
stream,
|
stream,
|
||||||
watchArea,
|
watchArea,
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,6 @@
|
||||||
let streamName = "{{.Stream.Name}}";
|
let streamName = "{{.Stream.Name}}";
|
||||||
let watchAreaName = "{{.WatchArea.Name}}";
|
let watchAreaName = "{{.WatchArea.Name}}";
|
||||||
let interval = {{.Stream.MotionInterval}};
|
let interval = {{.Stream.MotionInterval}};
|
||||||
let moments = [
|
let moments = {{.MomentsJSON}}
|
||||||
{{range $moment := .Moments}}
|
|
||||||
[
|
|
||||||
{{range $image := $moment}}
|
|
||||||
'{{$image}}',
|
|
||||||
{{end}}
|
|
||||||
],
|
|
||||||
{{end}}
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
Loading…
Add table
Reference in a new issue