2024-05-03 17:11:56 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2024-10-29 13:41:22 +00:00
|
|
|
"fmt"
|
2024-05-04 10:24:47 +00:00
|
|
|
"strconv"
|
2024-07-06 18:28:44 +00:00
|
|
|
|
2024-10-29 13:41:22 +00:00
|
|
|
"github.com/a-h/templ"
|
|
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/handler/views"
|
2024-07-06 18:28:44 +00:00
|
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/monero"
|
2024-10-31 15:45:26 +00:00
|
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/paging"
|
2024-05-03 17:11:56 +00:00
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2024-10-29 13:41:22 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/adaptor"
|
2024-05-03 17:11:56 +00:00
|
|
|
)
|
|
|
|
|
2024-11-06 14:34:05 +00:00
|
|
|
// Redirect old `/remote-nodes/logs/?node_id={id}` path to `/remote-nodes/id/{id}`
|
|
|
|
//
|
|
|
|
// This is temporary handler to redirect old path to new one. Once search
|
|
|
|
// engine results updated to the new path, this handler should be removed.
|
|
|
|
func (s *fiberServer) redirectLogs(c *fiber.Ctx) error {
|
|
|
|
id := c.QueryInt("node_id", 0)
|
|
|
|
if id == 0 {
|
|
|
|
return c.Redirect("/remote-nodes", fiber.StatusMovedPermanently)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Redirect(fmt.Sprintf("/remote-nodes/id/%d", id), fiber.StatusMovedPermanently)
|
|
|
|
}
|
|
|
|
|
2024-10-29 13:41:22 +00:00
|
|
|
// Render Home Page
|
2024-10-29 14:30:04 +00:00
|
|
|
func (s *fiberServer) homeHandler(c *fiber.Ctx) error {
|
2024-10-29 13:41:22 +00:00
|
|
|
p := views.Meta{
|
|
|
|
Title: "Monero Remote Node",
|
|
|
|
Description: "A website that helps you monitor your favourite Monero remote nodes, but YOU BETTER RUN AND USE YOUR OWN NODE.",
|
|
|
|
Keywords: "monero,monero,xmr,monero node,xmrnode,cryptocurrency,monero remote node,monero testnet,monero stagenet",
|
|
|
|
Robots: "INDEX,FOLLOW",
|
2024-11-06 11:00:25 +00:00
|
|
|
Permalink: s.url,
|
2024-10-29 13:41:22 +00:00
|
|
|
Identifier: "/",
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Set("Link", fmt.Sprintf(`<%s>; rel="canonical"`, p.Permalink))
|
|
|
|
home := views.BaseLayout(p, views.Home())
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(home))
|
|
|
|
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
2024-10-30 07:23:45 +00:00
|
|
|
// Render Add Node Page
|
|
|
|
func (s *fiberServer) addNodeHandler(c *fiber.Ctx) error {
|
2024-11-04 16:53:09 +00:00
|
|
|
switch c.Method() {
|
|
|
|
case fiber.MethodPut:
|
|
|
|
type formData struct {
|
|
|
|
Protocol string `form:"protocol"`
|
|
|
|
Hostname string `form:"hostname"`
|
|
|
|
Port int `form:"port"`
|
|
|
|
}
|
|
|
|
var f formData
|
|
|
|
|
|
|
|
if err := c.BodyParser(&f); err != nil {
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(views.Alert("error", "Cannot parse the request body")))
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
moneroRepo := monero.New()
|
|
|
|
if err := moneroRepo.Add(f.Protocol, f.Hostname, uint(f.Port)); err != nil {
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(views.Alert("error", err.Error())))
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(views.Alert("success", "Node added successfully")))
|
|
|
|
return handler(c)
|
|
|
|
}
|
2024-10-30 07:23:45 +00:00
|
|
|
p := views.Meta{
|
|
|
|
Title: "Add Monero Node",
|
|
|
|
Description: "You can use this page to add known remote node to the system so my bots can monitor it.",
|
|
|
|
Keywords: "monero,monero node,monero public node,monero wallet,list monero node,monero node monitoring",
|
|
|
|
Robots: "INDEX,FOLLOW",
|
2024-11-06 11:00:25 +00:00
|
|
|
Permalink: s.url + "/add-node",
|
2024-10-30 07:23:45 +00:00
|
|
|
Identifier: "/add-node",
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Set("Link", fmt.Sprintf(`<%s>; rel="canonical"`, p.Permalink))
|
|
|
|
home := views.BaseLayout(p, views.AddNode())
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(home))
|
|
|
|
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:17:51 +00:00
|
|
|
// Returns a single node information based on `id` query param
|
|
|
|
func Node(c *fiber.Ctx) error {
|
2024-05-06 18:08:01 +00:00
|
|
|
nodeId, err := c.ParamsInt("id", 0)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if nodeId == 0 {
|
|
|
|
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": "Invalid node id",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-06 18:08:01 +00:00
|
|
|
node, err := moneroRepo.Node(nodeId)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": node,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-31 15:45:26 +00:00
|
|
|
// Render Remote Nodes Page
|
|
|
|
func (s *fiberServer) remoteNodesHandler(c *fiber.Ctx) error {
|
|
|
|
p := views.Meta{
|
|
|
|
Title: "Public Monero Remote Nodes List",
|
|
|
|
Description: "Although it's possible to use these existing public Monero nodes, you're MUST RUN AND USE YOUR OWN NODE!",
|
|
|
|
Keywords: "monero remote nodes,public monero nodes,monero public nodes,monero wallet,tor monero node,monero cors rpc",
|
|
|
|
Robots: "INDEX,FOLLOW",
|
2024-11-06 11:00:25 +00:00
|
|
|
Permalink: s.url + "/remote-nodes",
|
2024-10-31 15:45:26 +00:00
|
|
|
Identifier: "/remote-nodes",
|
|
|
|
}
|
|
|
|
|
|
|
|
moneroRepo := monero.New()
|
|
|
|
query := monero.QueryNodes{
|
|
|
|
Paging: paging.Paging{
|
|
|
|
Limit: c.QueryInt("limit", 10), // rows per page
|
|
|
|
Page: c.QueryInt("page", 1),
|
|
|
|
SortBy: c.Query("sort_by", "id"),
|
2024-11-03 13:43:43 +00:00
|
|
|
SortDirection: c.Query("sort_direction", "desc"),
|
2024-11-04 10:17:23 +00:00
|
|
|
Refresh: c.Query("refresh"),
|
2024-10-31 15:45:26 +00:00
|
|
|
},
|
|
|
|
Host: c.Query("host"),
|
|
|
|
Nettype: c.Query("nettype", "any"),
|
|
|
|
Protocol: c.Query("protocol", "any"),
|
|
|
|
CC: c.Query("cc", "any"),
|
|
|
|
Status: c.QueryInt("status", -1),
|
2024-11-03 13:24:55 +00:00
|
|
|
CORS: c.Query("cors"),
|
2024-10-31 15:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes, err := moneroRepo.Nodes(query)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-11-03 10:37:11 +00:00
|
|
|
countries, err := moneroRepo.Countries()
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-31 15:45:26 +00:00
|
|
|
pagination := paging.NewPagination(query.Page, nodes.TotalPages)
|
|
|
|
|
|
|
|
// handle request from HTMX
|
|
|
|
if c.Get("HX-Target") == "tbl_nodes" {
|
2024-11-03 10:37:11 +00:00
|
|
|
cmp := views.BlankLayout(views.TableNodes(nodes, countries, query, pagination))
|
2024-10-31 15:45:26 +00:00
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(cmp))
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Set("Link", fmt.Sprintf(`<%s>; rel="canonical"`, p.Permalink))
|
2024-11-03 10:37:11 +00:00
|
|
|
home := views.BaseLayout(p, views.RemoteNodes(nodes, countries, query, pagination))
|
2024-10-31 15:45:26 +00:00
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(home))
|
|
|
|
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
2024-11-04 09:36:22 +00:00
|
|
|
// Returns a single node information based on `id` query param.
|
2024-11-06 09:45:34 +00:00
|
|
|
// This used for node modal and node details page including node probe logs.
|
2024-11-04 09:36:22 +00:00
|
|
|
func (s *fiberServer) nodeHandler(c *fiber.Ctx) error {
|
2024-11-06 09:45:34 +00:00
|
|
|
nodeID, err := c.ParamsInt("id", 0)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if nodeID == 0 {
|
|
|
|
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": "Invalid node id",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
moneroRepo := monero.New()
|
|
|
|
node, err := moneroRepo.Node(nodeID)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
2024-11-04 09:36:22 +00:00
|
|
|
switch c.Get("HX-Target") {
|
|
|
|
case "modal-section":
|
|
|
|
cmp := views.ModalLayout(fmt.Sprintf("Node #%d", nodeID), views.Node(node))
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(cmp))
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
2024-11-06 09:45:34 +00:00
|
|
|
queryLogs := monero.QueryLogs{
|
|
|
|
Paging: paging.Paging{
|
|
|
|
Limit: c.QueryInt("limit", 10), // rows per page
|
|
|
|
Page: c.QueryInt("page", 1),
|
|
|
|
SortBy: c.Query("sort_by", "id"),
|
|
|
|
SortDirection: c.Query("sort_direction", "desc"),
|
|
|
|
Refresh: c.Query("refresh"),
|
|
|
|
},
|
|
|
|
NodeID: int(node.ID),
|
|
|
|
Status: c.QueryInt("status", -1),
|
|
|
|
FailedReason: c.Query("failed_reason"),
|
|
|
|
}
|
|
|
|
|
|
|
|
logs, err := moneroRepo.Logs(queryLogs)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pagination := paging.NewPagination(queryLogs.Page, logs.TotalPages)
|
|
|
|
|
|
|
|
// handle datatable logs filters, sort request from HTMX
|
|
|
|
if c.Get("HX-Target") == "tbl_logs" {
|
|
|
|
cmp := views.BlankLayout(views.TableLogs(fmt.Sprintf("/remote-nodes/id/%d", node.ID), logs, queryLogs, pagination))
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(cmp))
|
|
|
|
return handler(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
p := views.Meta{
|
|
|
|
Title: fmt.Sprintf("%s on Port %d", node.Hostname, node.Port),
|
|
|
|
Description: fmt.Sprintf("Monero %s remote node %s running on port %d", node.Nettype, node.Hostname, node.Port),
|
|
|
|
Keywords: fmt.Sprintf("monero log,monero node log,monitoring monero log,monero,xmr,monero node,xmrnode,cryptocurrency,monero %s,%s", node.Nettype, node.Hostname),
|
|
|
|
Robots: "INDEX,FOLLOW",
|
2024-11-06 11:00:25 +00:00
|
|
|
Permalink: s.url + "/remote-nodes/id/" + strconv.Itoa(int(node.ID)),
|
2024-11-06 09:45:34 +00:00
|
|
|
Identifier: "/remote-nodes",
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Set("Link", fmt.Sprintf(`<%s>; rel="canonical"`, p.Permalink))
|
|
|
|
cmp := views.BaseLayout(p, views.NodeDetails(node, logs, queryLogs, pagination))
|
|
|
|
handler := adaptor.HTTPHandler(templ.Handler(cmp))
|
|
|
|
return handler(c)
|
2024-11-04 09:36:22 +00:00
|
|
|
}
|
|
|
|
|
2024-10-31 15:45:26 +00:00
|
|
|
// Returns a list of nodes (API)
|
2024-06-03 07:17:51 +00:00
|
|
|
func Nodes(c *fiber.Ctx) error {
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-26 22:13:03 +00:00
|
|
|
query := monero.QueryNodes{
|
2024-10-31 15:45:26 +00:00
|
|
|
Paging: paging.Paging{
|
|
|
|
Limit: c.QueryInt("limit", 10), // rows per page
|
|
|
|
Page: c.QueryInt("page", 1),
|
|
|
|
SortBy: c.Query("sort_by", "id"),
|
2024-11-03 13:43:43 +00:00
|
|
|
SortDirection: c.Query("sort_direction", "desc"),
|
2024-11-04 10:17:23 +00:00
|
|
|
Refresh: c.Query("refresh"),
|
2024-10-31 15:45:26 +00:00
|
|
|
},
|
|
|
|
Host: c.Query("host"),
|
|
|
|
Nettype: c.Query("nettype", "any"),
|
|
|
|
Protocol: c.Query("protocol", "any"),
|
|
|
|
CC: c.Query("cc", "any"),
|
|
|
|
Status: c.QueryInt("status", -1),
|
2024-11-03 13:24:55 +00:00
|
|
|
CORS: c.Query("cors"),
|
2024-05-04 11:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes, err := moneroRepo.Nodes(query)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": nodes,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Returns probe logs reported by nodes
|
|
|
|
//
|
|
|
|
// The embadded web UI use `node_id` query param to filter logs
|
2024-05-06 10:19:17 +00:00
|
|
|
func ProbeLogs(c *fiber.Ctx) error {
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-26 23:38:11 +00:00
|
|
|
query := monero.QueryLogs{
|
2024-11-06 09:45:34 +00:00
|
|
|
Paging: paging.Paging{
|
|
|
|
Limit: c.QueryInt("limit", 10), // rows per page
|
|
|
|
Page: c.QueryInt("page", 1),
|
|
|
|
SortBy: c.Query("sort_by", "id"),
|
|
|
|
SortDirection: c.Query("sort_direction", "desc"),
|
|
|
|
Refresh: c.Query("refresh"),
|
|
|
|
},
|
|
|
|
NodeID: c.QueryInt("node_id", 0),
|
|
|
|
Status: c.QueryInt("status", -1),
|
|
|
|
FailedReason: c.Query("failed_reason"),
|
2024-05-06 10:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
logs, err := moneroRepo.Logs(query)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": logs,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Handles `POST /nodes` request to add a new node
|
2024-11-04 16:53:09 +00:00
|
|
|
//
|
|
|
|
// Deprecated: AddNode is deprecated, use s.addNodeHandler with put method instead
|
2024-05-04 10:24:47 +00:00
|
|
|
func AddNode(c *fiber.Ctx) error {
|
|
|
|
formPort := c.FormValue("port")
|
|
|
|
port, err := strconv.Atoi(formPort)
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": "Invalid port number",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol := c.FormValue("protocol")
|
|
|
|
hostname := c.FormValue("hostname")
|
|
|
|
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-04 10:24:47 +00:00
|
|
|
if err := moneroRepo.Add(protocol, hostname, uint(port)); err != nil {
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Query Ok",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Returns majority network fees
|
2024-05-31 06:30:56 +00:00
|
|
|
func NetFees(c *fiber.Ctx) error {
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-06 06:19:48 +00:00
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
2024-05-31 06:30:56 +00:00
|
|
|
"data": moneroRepo.NetFees(),
|
2024-05-06 06:19:48 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Returns list of countries (count by nodes)
|
2024-05-06 06:35:15 +00:00
|
|
|
func Countries(c *fiber.Ctx) error {
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-05-06 06:35:15 +00:00
|
|
|
countries, err := moneroRepo.Countries()
|
|
|
|
if err != nil {
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": countries,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Returns node to be probed by the client (prober)
|
|
|
|
//
|
|
|
|
// This handler should protected by `CheckProber` middleware.
|
2024-05-04 12:27:21 +00:00
|
|
|
func GiveJob(c *fiber.Ctx) error {
|
|
|
|
acceptTor := c.QueryInt("accept_tor", 0)
|
2024-09-05 17:08:59 +00:00
|
|
|
acceptIPv6 := c.QueryInt("accept_ipv6", 0)
|
2024-05-04 12:27:21 +00:00
|
|
|
|
2024-05-26 23:15:40 +00:00
|
|
|
moneroRepo := monero.New()
|
2024-09-05 17:08:59 +00:00
|
|
|
node, err := moneroRepo.GiveJob(acceptTor, acceptIPv6)
|
2024-05-04 12:27:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": node,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
// Handles probe report submission by the prober
|
|
|
|
//
|
|
|
|
// This handler should protected by `CheckProber` middleware.
|
2024-05-04 18:42:47 +00:00
|
|
|
func ProcessJob(c *fiber.Ctx) error {
|
2024-06-03 07:20:10 +00:00
|
|
|
var report monero.ProbeReport
|
2024-05-04 18:42:47 +00:00
|
|
|
|
|
|
|
if err := c.BodyParser(&report); err != nil {
|
|
|
|
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-03 07:20:10 +00:00
|
|
|
moneroRepo := monero.New()
|
|
|
|
|
2024-05-04 18:42:47 +00:00
|
|
|
if err := moneroRepo.ProcessJob(report, c.Locals("prober_id").(int64)); err != nil {
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
"status": "error",
|
|
|
|
"message": err.Error(),
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(fiber.Map{
|
|
|
|
"status": "ok",
|
|
|
|
"message": "Success",
|
|
|
|
"data": nil,
|
|
|
|
})
|
|
|
|
}
|