From 34a3b1ba690b7aa5a57f0cdae7b047f75db15a10 Mon Sep 17 00:00:00 2001 From: mleku Date: Tue, 23 Sep 2025 14:49:08 +0100 Subject: [PATCH] Add dynamic relay dashboard URL support and version increment to v0.8.2. - Introduced configuration option `RelayURL` for relay dashboard base URL. - Added dynamic dashboard URL functionality in `PaymentProcessor`. - Updated payment notifications to include dashboard access link. - Incremented version to v0.8.2. --- app/config/config.go | 1 + app/handle-auth.go | 4 +++ app/payment_processor.go | 54 +++++++++++++++++++++++++++++----------- app/server.go | 9 +++++++ pkg/version/version | 2 +- 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/app/config/config.go b/app/config/config.go index f8285ee..76f8929 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -45,6 +45,7 @@ type C struct { NWCUri string `env:"ORLY_NWC_URI" usage:"NWC (Nostr Wallet Connect) connection string for Lightning payments"` SubscriptionEnabled bool `env:"ORLY_SUBSCRIPTION_ENABLED" default:"false" usage:"enable subscription-based access control requiring payment for non-directory events"` MonthlyPriceSats int64 `env:"ORLY_MONTHLY_PRICE_SATS" default:"6000" usage:"price in satoshis for one month subscription (default ~$2 USD)"` + RelayURL string `env:"ORLY_RELAY_URL" usage:"base URL for the relay dashboard (e.g., https://relay.example.com)"` // Web UI and dev mode settings WebDisableEmbedded bool `env:"ORLY_WEB_DISABLE" default:"false" usage:"disable serving the embedded web UI; useful for hot-reload during development"` diff --git a/app/handle-auth.go b/app/handle-auth.go index ea27683..6576694 100644 --- a/app/handle-auth.go +++ b/app/handle-auth.go @@ -72,6 +72,10 @@ func (l *Listener) handleFirstTimeUser(pubkey []byte) { // Get payment processor to create welcome note if l.Server.paymentProcessor != nil { + // Set the dashboard URL based on the current HTTP request + dashboardURL := l.Server.DashboardURL(l.req) + l.Server.paymentProcessor.SetDashboardURL(dashboardURL) + if err := l.Server.paymentProcessor.CreateWelcomeNote(pubkey); err != nil { log.E.F("failed to create welcome note for first-time user: %v", err) } diff --git a/app/payment_processor.go b/app/payment_processor.go index 419deb0..cca0bac 100644 --- a/app/payment_processor.go +++ b/app/payment_processor.go @@ -27,12 +27,13 @@ import ( // PaymentProcessor handles NWC payment notifications and updates subscriptions type PaymentProcessor struct { - nwcClient *nwc.Client - db *database.D - config *config.C - ctx context.Context - cancel context.CancelFunc - wg sync.WaitGroup + nwcClient *nwc.Client + db *database.D + config *config.C + ctx context.Context + cancel context.CancelFunc + wg sync.WaitGroup + dashboardURL string } // NewPaymentProcessor creates a new payment processor @@ -301,8 +302,10 @@ Your paid subscription to this relay will expire in 7 days on %s. Don't lose access to your private relay! Extend your subscription today. -Relay: nostr:%s`, - expiryTime.Format("2006-01-02 15:04:05 UTC"), monthlyPrice, monthlyPrice, string(relayNpubForContent)) +Relay: nostr:%s + +Log in to the relay dashboard to access your configuration at: %s`, + expiryTime.Format("2006-01-02 15:04:05 UTC"), monthlyPrice, monthlyPrice, string(relayNpubForContent), pp.getDashboardURL()) // Build the event ev := event.New() @@ -402,8 +405,10 @@ Simply zap this note with your payment amount: Thank you for considering supporting decentralized communication! -Relay: nostr:%s`, - trialEnd.Format("2006-01-02 15:04:05 UTC"), monthlyPrice, dailyRate, monthlyPrice, string(relayNpubForContent)) +Relay: nostr:%s + +Log in to the relay dashboard to access your configuration at: %s`, + trialEnd.Format("2006-01-02 15:04:05 UTC"), monthlyPrice, dailyRate, monthlyPrice, string(relayNpubForContent), pp.getDashboardURL()) // Build the event ev := event.New() @@ -605,9 +610,9 @@ func (pp *PaymentProcessor) createPaymentNote(payerPubkey []byte, satsReceived i return fmt.Errorf("failed to encode relay npub: %w", err) } - // Create the note content with nostr:npub link - content := fmt.Sprintf("Payment received: %d sats for %d days. Subscription expires: %s\n\nRelay: nostr:%s", - satsReceived, days, expiryTime.Format("2006-01-02 15:04:05 UTC"), string(relayNpubForContent)) + // Create the note content with nostr:npub link and dashboard link + content := fmt.Sprintf("Payment received: %d sats for %d days. Subscription expires: %s\n\nRelay: nostr:%s\n\nLog in to the relay dashboard to access your configuration at: %s", + satsReceived, days, expiryTime.Format("2006-01-02 15:04:05 UTC"), string(relayNpubForContent), pp.getDashboardURL()) // Build the event ev := event.New() @@ -699,7 +704,9 @@ To extend your subscription after the trial ends, simply zap this note with the Relay: nostr:%s -Enjoy your time on the relay!`, monthlyPrice, monthlyPrice, string(relayNpubForContent)) +Log in to the relay dashboard to access your configuration at: %s + +Enjoy your time on the relay!`, monthlyPrice, monthlyPrice, string(relayNpubForContent), pp.getDashboardURL()) // Build the event ev := event.New() @@ -750,6 +757,25 @@ Enjoy your time on the relay!`, monthlyPrice, monthlyPrice, string(relayNpubForC return nil } +// SetDashboardURL sets the dynamic dashboard URL based on HTTP request +func (pp *PaymentProcessor) SetDashboardURL(url string) { + pp.dashboardURL = url +} + +// getDashboardURL returns the dashboard URL for the relay +func (pp *PaymentProcessor) getDashboardURL() string { + // Use dynamic URL if available + if pp.dashboardURL != "" { + return pp.dashboardURL + } + // Fallback to static config + if pp.config.RelayURL != "" { + return pp.config.RelayURL + } + // Default fallback if no URL is configured + return "https://your-relay.example.com" +} + // extractNpubFromDescription extracts an npub from the payment description func (pp *PaymentProcessor) extractNpubFromDescription(description string) string { // check if the entire description is just an npub diff --git a/app/server.go b/app/server.go index c57e8d6..bfbff9c 100644 --- a/app/server.go +++ b/app/server.go @@ -113,6 +113,15 @@ func (s *Server) ServiceURL(req *http.Request) (st string) { return proto + "://" + host } +// DashboardURL constructs HTTPS URL for the dashboard based on the HTTP request +func (s *Server) DashboardURL(req *http.Request) string { + host := req.Header.Get("X-Forwarded-Host") + if host == "" { + host = req.Host + } + return "https://" + host +} + // UserInterface sets up a basic Nostr NDK interface that allows users to log into the relay user interface func (s *Server) UserInterface() { if s.mux == nil { diff --git a/pkg/version/version b/pkg/version/version index 349ca0e..fe5b6a9 100644 --- a/pkg/version/version +++ b/pkg/version/version @@ -1 +1 @@ -v0.8.1 \ No newline at end of file +v0.8.2 \ No newline at end of file