Skip to content

Commit cdc1925

Browse files
Clean up nodes, add unsplash, /discovery, /content routes
1 parent bb6e6d8 commit cdc1925

15 files changed

+272
-498
lines changed

api/content_node_monitor.go

Lines changed: 0 additions & 229 deletions
This file was deleted.

api/content_nodes.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package api
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gofiber/fiber/v2"
7+
)
8+
9+
func (app *ApiServer) contentNodes(c *fiber.Ctx) error {
10+
var contentNodes []fiber.Map
11+
for _, node := range app.validators.GetNodes() {
12+
if node.ServiceType == "content-node" {
13+
contentNodes = append(contentNodes, fiber.Map{
14+
"id": node.Id,
15+
"owner": node.Owner,
16+
"endpoint": node.Endpoint,
17+
"delegateWallet": node.DelegateWallet,
18+
"serviceType": node.ServiceType,
19+
"registeredAt": node.RegisteredAt,
20+
})
21+
}
22+
}
23+
24+
if strings.HasSuffix(c.Path(), "/verbose") {
25+
return c.JSON(fiber.Map{
26+
"data": contentNodes,
27+
})
28+
}
29+
30+
// Return just URLs as strings
31+
urls := make([]string, len(contentNodes))
32+
for i, node := range contentNodes {
33+
urls[i] = node["endpoint"].(string)
34+
}
35+
36+
return c.JSON(fiber.Map{
37+
"data": urls,
38+
})
39+
}

api/discovery_nodes.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package api
2+
3+
import (
4+
"strings"
5+
6+
"github.com/gofiber/fiber/v2"
7+
)
8+
9+
func (app *ApiServer) discoveryNodes(c *fiber.Ctx) error {
10+
var discoveryNodes []fiber.Map
11+
for _, node := range app.validators.GetNodes() {
12+
if node.ServiceType == "discovery-node" {
13+
discoveryNodes = append(discoveryNodes, fiber.Map{
14+
"id": node.Id,
15+
"owner": node.Owner,
16+
"endpoint": node.Endpoint,
17+
"delegateWallet": node.DelegateWallet,
18+
"serviceType": node.ServiceType,
19+
"registeredAt": node.RegisteredAt,
20+
})
21+
}
22+
}
23+
24+
if strings.HasSuffix(c.Path(), "/verbose") {
25+
return c.JSON(fiber.Map{
26+
"data": discoveryNodes,
27+
})
28+
}
29+
30+
// Return just URLs as strings
31+
urls := make([]string, len(discoveryNodes))
32+
for i, node := range discoveryNodes {
33+
urls[i] = node["endpoint"].(string)
34+
}
35+
36+
return c.JSON(fiber.Map{
37+
"data": urls,
38+
})
39+
}

api/health_check.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package api
22

33
import (
44
"context"
5-
"slices"
65

6+
"api.audius.co/config"
77
core_indexer "api.audius.co/indexer"
88
"connectrpc.com/connect"
99
corev1 "github.com/OpenAudio/go-openaudio/pkg/api/core/v1"
@@ -18,6 +18,7 @@ type contentNode struct {
1818
}
1919

2020
type networkInfo struct {
21+
Validators []config.Node `json:"validators"`
2122
ContentNodes []contentNode `json:"content_nodes"`
2223
}
2324

@@ -63,19 +64,6 @@ func (app *ApiServer) healthCheck(c *fiber.Ctx) error {
6364
return err
6465
}
6566

66-
healthyNodes := app.contentNodeMonitor.GetContentNodes()
67-
// Convert config.Node to contentNode
68-
contentNodes := make([]contentNode, 0, len(healthyNodes))
69-
for _, node := range healthyNodes {
70-
// icky reaching into config to check upload nodes
71-
if slices.Contains(app.config.UploadNodes, node.Endpoint) {
72-
contentNodes = append(contentNodes, contentNode{
73-
DelegateOwnerWallet: node.DelegateOwnerWallet,
74-
Endpoint: node.Endpoint,
75-
})
76-
}
77-
}
78-
7967
coreIndexerHealth, err := app.getCoreIndexerHealth(c.Context())
8068
if err != nil {
8169
app.logger.Error("Failed to get core indexer health", zap.Error(err))
@@ -89,9 +77,24 @@ func (app *ApiServer) healthCheck(c *fiber.Ctx) error {
8977
}
9078
}
9179

80+
nodes := app.validators.GetNodes()
81+
contentNodes := make([]contentNode, 0)
82+
for _, node := range nodes {
83+
for _, uploadNode := range app.config.UploadNodes {
84+
if node.Endpoint == uploadNode {
85+
contentNodes = append(contentNodes, contentNode{
86+
DelegateOwnerWallet: node.DelegateWallet,
87+
Endpoint: node.Endpoint,
88+
})
89+
break
90+
}
91+
}
92+
}
93+
9294
health := healthCheckResponse{
9395
CoreIndexer: coreIndexerHealth,
9496
Network: networkInfo{
97+
Validators: nodes,
9598
ContentNodes: contentNodes,
9699
},
97100
}

0 commit comments

Comments
 (0)