mostly working addWatchArea system, somehow wont actually add the watcharea to the WatchAreas list in a Strea, goroutine problem?
This commit is contained in:
parent
a88837f90f
commit
f9a6c37350
4 changed files with 80 additions and 1 deletions
64
main.go
64
main.go
|
|
@ -2,6 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/color"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -39,6 +41,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
log.Fatal(err)
|
||||
}
|
||||
streamTemplate.Execute(w, stream)
|
||||
log.Println(server.Streams)
|
||||
}
|
||||
|
||||
func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -77,7 +80,66 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (server Server) addWatchArea(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.Method != "POST" {
|
||||
//return
|
||||
}
|
||||
streamName := r.FormValue("streamName")
|
||||
if streamName == "" {
|
||||
return
|
||||
}
|
||||
stream, exists := server.Streams[streamName]
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
name := r.FormValue("name")
|
||||
if name == "" {
|
||||
return
|
||||
}
|
||||
x0 := r.FormValue("x0")
|
||||
if x0 == "" {
|
||||
return
|
||||
}
|
||||
y0 := r.FormValue("y0")
|
||||
if y0 == "" {
|
||||
return
|
||||
}
|
||||
x1 := r.FormValue("x1")
|
||||
if x1 == "" {
|
||||
return
|
||||
}
|
||||
y1 := r.FormValue("y1")
|
||||
if y1 == "" {
|
||||
return
|
||||
}
|
||||
R := r.FormValue("R")
|
||||
if R == "" {
|
||||
return
|
||||
}
|
||||
G := r.FormValue("G")
|
||||
if G == "" {
|
||||
return
|
||||
}
|
||||
B := r.FormValue("B")
|
||||
if B == "" {
|
||||
return
|
||||
}
|
||||
stream.WatchAreas = append(stream.WatchAreas, WatchArea{
|
||||
Name: name,
|
||||
Color: color.RGBA{
|
||||
uint8(StrToInt(R)),
|
||||
uint8(StrToInt(G)),
|
||||
uint8(StrToInt(B)),
|
||||
255,
|
||||
},
|
||||
Area: image.Rect(
|
||||
StrToInt(x0),
|
||||
StrToInt(y0),
|
||||
StrToInt(x1),
|
||||
StrToInt(y1),
|
||||
),
|
||||
})
|
||||
stream.WriteStreamJSON()
|
||||
http.Redirect(w, r, "/?name="+streamName, http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -174,6 +174,11 @@ func (s Stream) SwapInstants(previous string, current string, next string) {
|
|||
}
|
||||
}
|
||||
|
||||
// AddWatchArea adds the given WatchArea to the list of WatchAreas
|
||||
func (s Stream) AddWatchArea(watchArea WatchArea) {
|
||||
s.WatchAreas = append(s.WatchAreas, watchArea)
|
||||
}
|
||||
|
||||
// GetStreamJSONPath returns filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||
func (s Stream) GetStreamJSONPath() string {
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
<img src="{{ .GetCurrentURL }}" width="425" height="240">
|
||||
</div>
|
||||
<form action="/addWatchArea" method="GET" id="newWatchAreaForm">
|
||||
<input type="hidden" name="streamName" value="{{ .Name }}">
|
||||
<table class="pure-table pure-table-horizontal">
|
||||
<caption>Watches</caption>
|
||||
<thead>
|
||||
|
|
|
|||
11
util.go
11
util.go
|
|
@ -3,8 +3,10 @@ package main
|
|||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// URLToBase64 returns the base64 encoding of the URL parameter
|
||||
|
|
@ -35,3 +37,12 @@ func GetStreamDirPath() string {
|
|||
func StreamStorePathExists() bool {
|
||||
return FileExists(GetStreamDirPath())
|
||||
}
|
||||
|
||||
// StrToInt uses strconv.ParseInt
|
||||
func StrToInt(str string) int {
|
||||
i, err := strconv.ParseInt(str, 10, 64)
|
||||
if err != nil {
|
||||
log.Println("Could not convert string to int ", str)
|
||||
}
|
||||
return int(i)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue