🐛 Fixes server requests
All checks were successful
Gitea Build Action / build-go (push) Successful in 27s
Gitea Build Action / build-nuxt (push) Successful in 10m40s

This commit is contained in:
Daniel Svitan 2025-06-07 15:49:34 +02:00
parent cf35326bf2
commit 53722bdf18
4 changed files with 25 additions and 18 deletions

View File

@ -27,7 +27,7 @@ type ChangeLockReq struct {
} }
type ChangeAlertReq struct { type ChangeAlertReq struct {
Alert bool `json:"alert"` Alert bool `json:"alerts"`
For int `json:"for"` For int `json:"for"`
} }
@ -135,14 +135,16 @@ func main() {
Usage: "change lock status", Usage: "change lock status",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "yes", Name: "yes",
Usage: "lock the door", Usage: "lock the door",
Action: createManageLock(true), Aliases: []string{"y", "on", "1", "do"},
Action: createManageLock(true),
}, },
{ {
Name: "no", Name: "no",
Usage: "unlock the door", Usage: "unlock the door",
Action: createManageLock(false), Aliases: []string{"n", "off", "0", "undo"},
Action: createManageLock(false),
}, },
}, },
Action: getLocked, Action: getLocked,
@ -152,13 +154,15 @@ func main() {
Usage: "change alert status", Usage: "change alert status",
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: "yes", Name: "yes",
Usage: "resume alerts", Usage: "resume alerts",
Action: createManageAlert(true), Aliases: []string{"y", "on", "1", "do"},
Action: createManageAlert(true),
}, },
{ {
Name: "no", Name: "no",
Usage: "pause alerts", Usage: "pause alerts",
Aliases: []string{"n", "off", "0", "undo"},
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "for", Name: "for",
@ -322,7 +326,7 @@ func createManageAlert(alert bool) func(context.Context, *cli.Command) error {
action = "paused" action = "paused"
} }
fmt.Printf("alerts were %sd%s\n", action, rest) fmt.Printf("alerts were %s%s\n", action, rest)
return nil return nil
} }
} }

View File

@ -98,7 +98,7 @@ class App:
try: try:
r = urequests.post( r = urequests.post(
f"{self.server}/opened", f"{self.server}/opened",
headers={"Authorization": self.token, "Content-Type": "application/json"}, headers={"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"},
data=raw data=raw
) )
print(f"State updated [{r.status_code}] {r.content.decode()}") print(f"State updated [{r.status_code}] {r.content.decode()}")

View File

@ -23,14 +23,14 @@ const TimeFormat = "2006-01-02 15:04:05"
var token string var token string
// the condition is: distance >= threshold (is door open) // the condition is: distance >= threshold (is door open)
var opened bool var opened = false
var openedChange = make(chan any) var openedChange = make(chan any)
// is door locked // is door locked
var locked bool = false var locked = false
// alerts the user when door locked and but open? // alerts the user when door locked and but open?
var alerts bool = false var alerts = false
var gotifyToken string var gotifyToken string
var gotifyURL string var gotifyURL string

View File

@ -79,7 +79,9 @@ func setOpened(c echo.Context) error {
go sendAlert(action) go sendAlert(action)
} }
openedChange <- 0 go func() {
openedChange <- 0
}()
mut.Unlock() mut.Unlock()
return c.NoContent(http.StatusOK) return c.NoContent(http.StatusOK)
} }
@ -126,6 +128,7 @@ func setAlerts(c echo.Context) error {
} }
if data.For > 0 { if data.For > 0 {
log.Infof("pausing alerts for %d seconds", data.For)
go func() { go func() {
time.Sleep(time.Duration(data.For) * time.Second) time.Sleep(time.Duration(data.For) * time.Second)