2024-05-04 00:11:56 +07:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2024-05-22 22:45:38 +07:00
|
|
|
"xmr-remote-nodes/internal/monero"
|
2024-05-04 19:52:22 +07:00
|
|
|
|
2024-05-04 00:11:56 +07:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
2024-05-04 19:52:22 +07:00
|
|
|
func CheckProber(c *fiber.Ctx) error {
|
|
|
|
key := c.Get("X-Prober-Api-Key")
|
|
|
|
if key == "" {
|
|
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": "Unauthorized",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-27 07:17:27 +07:00
|
|
|
prober, err := monero.NewProber().CheckApi(key)
|
2024-05-04 19:52:22 +07:00
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": "No API key match",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-30 12:46:33 +07:00
|
|
|
c.Locals("prober_id", prober.ID)
|
2024-05-04 19:52:22 +07:00
|
|
|
return c.Next()
|
|
|
|
}
|