diff --git a/main.go b/main.go
index 9d691b9..12d3f25 100755
--- a/main.go
+++ b/main.go
@@ -16,6 +16,7 @@ var baseHTML = filepath.Join("templates", "base.html")
var indexHTML = filepath.Join("templates", "index.html")
var addStreamHTML = filepath.Join("templates", "add_stream.html")
var streamHTML = filepath.Join("templates", "stream.html")
+var momentsHTML = filepath.Join("templates", "moments.html")
// Server is the main application struct
type Server struct {
@@ -209,10 +210,14 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
}
log.Println("got images: ", len(images))
moments := make([][]string, 0)
+ currentMoment := make([]string, 0)
momentIndex := 0
foundMoment := false
for i := range images {
+ if i == 0 {
+ continue
+ }
log.Println(i)
previousImage := images[i-1]
previousTime, err := time.Parse(timeLayout, previousImage.Name())
@@ -233,15 +238,33 @@ func (server Server) streamRecordings(w http.ResponseWriter, r *http.Request) {
timeDifference := currentTime.Sub(previousTime)
if timeDifference < (time.Duration(stream.Interval) * time.Millisecond) {
foundMoment = true
- moments[momentIndex] = append(moments[momentIndex], previousImage.Name())
+ currentMoment = append(currentMoment, previousImage.Name())
} else {
if foundMoment {
+ currentMoment = append(currentMoment, currentImage.Name())
+ moments = append(moments, currentMoment)
+ currentMoment = make([]string, 0)
momentIndex++
}
foundMoment = false
}
}
- log.Println(moments)
+ momentsTemplate, err := template.ParseFiles(momentsHTML, baseHTML)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+ momentsTemplate.Execute(w, struct {
+ Streams map[string]*Stream
+ Moments [][]string
+ Stream *Stream
+ WatchArea *WatchArea
+ }{
+ server.Streams,
+ moments,
+ stream,
+ watchArea,
+ })
}
func main() {
diff --git a/templates/moments.html b/templates/moments.html
new file mode 100755
index 0000000..d4dfeec
--- /dev/null
+++ b/templates/moments.html
@@ -0,0 +1,11 @@
+{{template "base" .}}
+{{define "head"}}
+
+{{end}}
+{{define "content"}}
+ {{range $moment := .Moments}}
+ {{range $image := $moment}}
+
+ {{end}}
+ {{end}}
+{{end}}
\ No newline at end of file