scan result
parent
73d1749579
commit
0118a0cbca
|
@ -34,6 +34,8 @@ const (
|
||||||
SentCmdNewScanner = 11
|
SentCmdNewScanner = 11
|
||||||
SentCmdDeleteScanner = 12
|
SentCmdDeleteScanner = 12
|
||||||
SentCmdUpdateScannerUsedBy = 13
|
SentCmdUpdateScannerUsedBy = 13
|
||||||
|
SentCmdScanResult = 14
|
||||||
|
SentCmdUpdateScannerLastUsed = 15
|
||||||
)
|
)
|
||||||
|
|
||||||
// commands received from web clients
|
// commands received from web clients
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package jxscanner
|
package jxscanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"janex/admin-dashboard-backend/modules/database"
|
"janex/admin-dashboard-backend/modules/database"
|
||||||
"janex/admin-dashboard-backend/modules/structs"
|
"janex/admin-dashboard-backend/modules/structs"
|
||||||
"janex/admin-dashboard-backend/modules/utils"
|
"janex/admin-dashboard-backend/modules/utils"
|
||||||
|
@ -68,14 +67,26 @@ func ScanResult(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedScanResult, err := base64.StdEncoding.DecodeString(body.ScanResult)
|
scannerId := c.Locals("scannerId").(string)
|
||||||
|
lastUsed := time.Now()
|
||||||
|
|
||||||
if err != nil {
|
database.DB.Model(&structs.Scanner{}).Where("id = ?", scannerId).Updates(&structs.Scanner{LastUsed: lastUsed})
|
||||||
log.Error().Msg("Failed to decode scan result, err: " + err.Error())
|
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debug().Msgf("scanning result %v", string(decodedScanResult))
|
socketclients.BroadcastMessage(structs.SendSocketMessage{
|
||||||
|
Cmd: utils.SentCmdUpdateScannerLastUsed,
|
||||||
|
Body: struct {
|
||||||
|
ScannerId string
|
||||||
|
LastUsed time.Time
|
||||||
|
}{
|
||||||
|
ScannerId: scannerId,
|
||||||
|
LastUsed: lastUsed,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
socketclients.SendMessageToUser(c.Locals("usedByUserId").(string), "", structs.SendSocketMessage{
|
||||||
|
Cmd: utils.SentCmdScanResult,
|
||||||
|
Body: body.ScanResult,
|
||||||
|
})
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,5 +63,8 @@ func scannerSessionValidation(c *fiber.Ctx) error {
|
||||||
return fiber.ErrUnauthorized
|
return fiber.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Locals("scannerId", scanner.Id)
|
||||||
|
c.Locals("usedByUserId", scanner.UsedByUserId)
|
||||||
|
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue