🔨 Replaces websockets with interval fetches
All checks were successful
Gitea Build Action / build-go (push) Successful in 36s
Gitea Build Action / build-nuxt (push) Successful in 10m7s

This commit is contained in:
2025-06-16 11:56:20 +02:00
parent 4b2248a6d7
commit d858b9e7c8
5 changed files with 55 additions and 74 deletions

View File

@@ -4,13 +4,10 @@ import (
"net/http"
"time"
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
)
var upgrader = websocket.Upgrader{}
func helloWorld(c echo.Context) error {
return c.JSON(http.StatusOK, "Hello world!")
}
@@ -23,39 +20,6 @@ func getOpened(c echo.Context) error {
return c.JSON(http.StatusOK, o)
}
func getOpenedWs(c echo.Context) error {
ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil)
if err != nil {
return err
}
defer func() { _ = ws.Close() }()
// empty the channel
emptied := false
for !emptied {
select {
case <-openedChange:
default:
emptied = true
}
}
for {
<-openedChange
mut.Lock()
err = ws.WriteJSON(opened)
mut.Unlock()
if err != nil {
log.Error(err)
break
}
}
return err
}
func setOpened(c echo.Context) error {
var data ChangeOpenReq
err := c.Bind(&data)
@@ -80,9 +44,6 @@ func setOpened(c echo.Context) error {
go sendAlert(action)
}
go func() {
openedChange <- 0
}()
mut.Unlock()
return c.NoContent(http.StatusOK)
}