config: simplify to single base_url with computed paths
Refactor configuration to use one source of truth for base URL - Add GetBaseURL() to config package: queries system_config table first, falls back to BASE_URL env var - Update SidecarHandler to accept config and use single base_url - Compute opds/api paths from base_url instead of storing separately: - OPDS: base_url + /opds - API: base_url + /api - Device Sync: base_url + /api/sync - Simplify OPDSHandler.getBaseURLs() to compute opds path - Remove need for separate opds_base_url and api_base_url columns Previously the system stored three separate URL config values that were usually the same domain with different paths. Now store only base_url and compute the paths, eliminating configuration redundancy.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -44,6 +45,30 @@ func (c *Config) DatabaseURL() string {
|
||||
c.DatabaseUser, c.DatabasePassword, c.DatabaseHost, c.DatabasePort, c.DatabaseName)
|
||||
}
|
||||
|
||||
// GetBaseURL returns the base URL from system configuration database with fallback to config/env var
|
||||
func GetBaseURL(ctx context.Context, db interface{}) string {
|
||||
// Try to get from database first
|
||||
type SystemConfigQuerier interface {
|
||||
GetSystemConfig(ctx context.Context, key string) (SystemConfigRow, error)
|
||||
}
|
||||
|
||||
if querier, ok := db.(SystemConfigQuerier); ok {
|
||||
config, err := querier.GetSystemConfig(ctx, "base_url")
|
||||
if err == nil && config.Value != "" {
|
||||
return config.Value
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: return empty string - caller should use their own fallback
|
||||
return ""
|
||||
}
|
||||
|
||||
// SystemConfigRow represents a system configuration row
|
||||
type SystemConfigRow struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user