2024-06-12 18:44:12 +00:00
|
|
|
package write
|
|
|
|
|
2024-06-13 11:25:18 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2024-06-13 17:25:45 +00:00
|
|
|
"git.tek.govt.hu/dowerx/place/api/read"
|
2024-06-13 11:25:18 +00:00
|
|
|
"git.tek.govt.hu/dowerx/place/api/structs"
|
2024-06-13 12:43:09 +00:00
|
|
|
"git.tek.govt.hu/dowerx/place/auth"
|
|
|
|
"git.tek.govt.hu/dowerx/place/config"
|
2024-06-13 11:25:18 +00:00
|
|
|
"git.tek.govt.hu/dowerx/place/storage"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
2024-06-12 18:44:12 +00:00
|
|
|
|
2024-06-13 12:43:09 +00:00
|
|
|
var timeout int = config.GetConfig().Timeout
|
2024-06-13 11:25:18 +00:00
|
|
|
|
2024-06-13 12:43:09 +00:00
|
|
|
func Pixel(c *gin.Context) {
|
2024-06-13 17:25:45 +00:00
|
|
|
var info structs.Pixel
|
2024-06-13 11:25:18 +00:00
|
|
|
if c.ShouldBind(&info) != nil {
|
|
|
|
c.AbortWithStatus(400)
|
|
|
|
return
|
|
|
|
}
|
2024-06-12 18:44:12 +00:00
|
|
|
|
2024-06-13 12:43:09 +00:00
|
|
|
cookie, err := c.Cookie("place")
|
|
|
|
if err != nil {
|
|
|
|
cookie = auth.SetCookie(timeout)
|
|
|
|
c.SetCookie("place", cookie, timeout, "/", "", false, false)
|
|
|
|
} else {
|
|
|
|
if auth.GetCookie(cookie) {
|
|
|
|
c.Status(403)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-13 11:25:18 +00:00
|
|
|
if err := storage.SetPixel(info.X, info.Y, &info); err != nil {
|
|
|
|
c.AbortWithError(500, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-13 17:25:45 +00:00
|
|
|
go read.Connections.Send(info)
|
|
|
|
|
2024-06-13 11:25:18 +00:00
|
|
|
c.Status(200)
|
2024-06-12 18:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Bitmap(c *gin.Context) {
|
2024-06-13 11:25:18 +00:00
|
|
|
panic(errors.New("unimplomented"))
|
2024-06-12 18:44:12 +00:00
|
|
|
}
|