add more routes

This commit is contained in:
2026-09-06 21:57:03 +08:00
parent 4688c10585
commit 5743a36f51
35 changed files with 202373 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
package device
import (
"bdgrp_go/db"
"bdgrp_go/pbutil"
"bdgrp_go/routes"
"bdgrp_go/utils"
"fmt"
"github.com/gofiber/fiber/v2"
)
func init() {
path := routes.PathOf()
routes.Register(func(app *fiber.App) {
app.Put(path, updateDevice)
fmt.Println("Loaded:", path)
})
}
func updateDevice(c *fiber.Ctx) error {
decrypted, err := utils.Decrypt(c.Body())
if err != nil {
fmt.Println(err)
}
decoded, err := pbutil.Decode("DeviceInfoUpdateRequest", decrypted)
userid := c.Params("userid")
user := db.FindUser(userid)
user["deviceModel"] = decoded["deviceModel"]
user["operatingSystem"] = decoded["operatingSystem"]
db.Save()
data := map[string]any{
"deviceModel": user["deviceModel"],
"operatingSystem": user["operatingSystem"],
"clientVersion": user["clientVersion"],
}
encoded, err := pbutil.Encode("UserRegistration", data)
if err != nil {
fmt.Println(err)
}
encrypted, err := utils.Encrypt(encoded)
if err != nil {
fmt.Println(err)
}
return c.Send(encrypted)
}