Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 91 additions & 179 deletions pkg/console/assets/css/output.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/console/assets/images/Glyph_Black.svg

This file was deleted.

3 changes: 3 additions & 0 deletions pkg/console/assets/images/OAPLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkg/console/assets/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions pkg/console/assets/input.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import "tailwindcss";

@variant dark (&:is(.dark, .dark *));

/* JSON Syntax Highlighting */
.json-key {
@apply text-blue-600 font-semibold;
Expand Down
30 changes: 30 additions & 0 deletions pkg/console/assets/js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function themeToggle() {
return {
theme: 'light',

init() {
console.log('Theme toggle initialized');
// Read current state from document (set by inline script)
const isDark = document.documentElement.classList.contains('dark');
this.theme = isDark ? 'dark' : 'light';
console.log('Current theme:', this.theme);
},

toggleTheme() {
console.log('Toggle clicked, current theme:', this.theme);
this.theme = this.theme === 'light' ? 'dark' : 'light';
console.log('New theme:', this.theme);
localStorage.setItem('theme', this.theme);
this.applyTheme();
},

applyTheme() {
console.log('Applying theme:', this.theme);
if (this.theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}
}
}
79 changes: 79 additions & 0 deletions pkg/console/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package console

import (
"context"
"sync"
"time"

"github.com/AudiusProject/audiusd/pkg/common"
)

// Cache is a generic thread-safe cache that periodically refreshes data in the background
type Cache[T any] struct {
mu sync.RWMutex
data T
lastUpdated time.Time
updateFunc func(context.Context) (T, error)
refreshRate time.Duration
logger *common.Logger
}

// NewCache creates a new cache with the given update function and refresh rate
func NewCache[T any](updateFunc func(context.Context) (T, error), refreshRate time.Duration, logger *common.Logger) *Cache[T] {
return &Cache[T]{
updateFunc: updateFunc,
refreshRate: refreshRate,
logger: logger,
}
}

// Get returns the cached data (thread-safe read)
func (c *Cache[T]) Get() T {
c.mu.RLock()
defer c.mu.RUnlock()
return c.data
}

// GetLastUpdated returns when the cache was last updated
func (c *Cache[T]) GetLastUpdated() time.Time {
c.mu.RLock()
defer c.mu.RUnlock()
return c.lastUpdated
}

// StartRefresh begins the background refresh loop
// Should be called in a goroutine
func (c *Cache[T]) StartRefresh(ctx context.Context) {
ticker := time.NewTicker(c.refreshRate)
defer ticker.Stop()

// Do initial refresh immediately (non-blocking)
c.refresh(ctx)

for {
select {
case <-ctx.Done():
c.logger.Info("Cache refresh stopped")
return
case <-ticker.C:
c.refresh(ctx)
}
}
}

// refresh updates the cached data by calling the update function
func (c *Cache[T]) refresh(ctx context.Context) {
start := time.Now()
data, err := c.updateFunc(ctx)
if err != nil {
c.logger.Warn("Cache refresh failed", "error", err, "duration", time.Since(start))
return
}

c.mu.Lock()
c.data = data
c.lastUpdated = time.Now()
c.mu.Unlock()

c.logger.Debug("Cache refreshed", "duration", time.Since(start))
}
70 changes: 5 additions & 65 deletions pkg/console/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
package main

import (
"context"
"fmt"
"log"
"os"
"path/filepath"
"time"

"github.com/AudiusProject/audiusd/pkg/common"
"github.com/AudiusProject/audiusd/pkg/console"
"github.com/AudiusProject/audiusd/pkg/etl"
"github.com/AudiusProject/audiusd/pkg/sdk"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"go.uber.org/zap"
)

func main() {
logger := common.NewLogger(nil)

logger.Info("Starting Console")

// Start postgres container with volume
dbURL, err := startPostgres(context.Background())
if err != nil {
log.Fatalf("Failed to start postgres: %s", err)
}
// Connect to postgres from Makefile (port 5444)
dbURL := "postgres://postgres:[email protected]:5444/audiusd?sslmode=disable"

logger.Info("pgURL", "url", dbURL)
// wait for postgres to be ready
time.Sleep(5 * time.Second)

auds := sdk.NewAudiusdSDK("rpc.audius.engineering")
auds := sdk.NewAudiusdSDK("creatornode.audius.co")

etl := etl.NewETLService(auds.Core, nil)
etl := etl.NewETLService(auds.Core, zap.NewNop())
etl.SetDBURL(dbURL)
etl.SetCheckReadiness(false)

Expand All @@ -45,52 +34,3 @@ func main() {
log.Fatal(err)
}
}

func startPostgres(ctx context.Context) (string, error) {
pguser := "postgres"
pgpass := "postgres"
pgdb := "audiusd"

// Get current working directory and create absolute path for postgres data
cwd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get current working directory: %w", err)
}

postgresDataPath := filepath.Join(cwd, "tmp", "postgres-data")

// Create the directory if it doesn't exist
if err := os.MkdirAll(postgresDataPath, 0755); err != nil {
return "", fmt.Errorf("failed to create postgres data directory: %w", err)
}

req := testcontainers.ContainerRequest{
Image: "postgres:15",
Name: "audiusd-console-postgres",
ExposedPorts: []string{"15432:5432/tcp"},
Env: map[string]string{
"POSTGRES_USER": pguser,
"POSTGRES_PASSWORD": pgpass,
"POSTGRES_DB": pgdb,
},
WaitingFor: wait.ForListeningPort("5432/tcp"),
}

postgresC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
Reuse: true,
})
if err != nil {
return "", fmt.Errorf("failed to start container: %w", err)
}

host, err := postgresC.Host(ctx)
if err != nil {
return "", fmt.Errorf("failed to get container host: %w", err)
}

// Use fixed port 15432 for consistent TablePlus connections
dsn := fmt.Sprintf("postgres://%s:%s@%s:15432/%s?sslmode=disable", pguser, pgpass, host, pgdb)
return dsn, nil
}
Loading