- Rename SCAN_POLL_INTERVAL_MINUTES to SCAN_POLL_INTERVAL_SECONDS in config - Update MediaScanner to accept interval in seconds instead of minutes - Adjust default polling interval from 3 minutes to 30 seconds for faster response - Add debug logging for fsnotify events to aid troubleshooting file watching This change improves media file detection responsiveness by reducing the polling interval from minutes to seconds, while maintaining the file watcher as the primary detection mechanism.
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
ServerPort string
|
|
BaseURL string
|
|
JWTSecret string
|
|
UploadPath string
|
|
DatabaseHost string
|
|
DatabasePort string
|
|
DatabaseUser string
|
|
DatabasePassword string
|
|
DatabaseName string
|
|
TestMode bool
|
|
RateLimitEnabled bool
|
|
RequestsPerMinute int
|
|
ScanPollIntervalSeconds int `env:"SCAN_POLL_INTERVAL_SECONDS" default:"30"`
|
|
}
|
|
|
|
func LoadConfig() *Config {
|
|
port := getEnv("SERVER_PORT", "8765")
|
|
return &Config{
|
|
ServerPort: port,
|
|
BaseURL: getEnv("BASE_URL", "http://localhost:"+port),
|
|
DatabaseHost: getEnv("DATABASE_HOST", "localhost"),
|
|
DatabasePort: getEnv("DATABASE_PORT", "5432"),
|
|
DatabaseUser: getEnv("DATABASE_USER", "postgres"),
|
|
DatabasePassword: getEnv("DATABASE_PASSWORD", "password"),
|
|
DatabaseName: getEnv("DATABASE_NAME", "bookhoard"),
|
|
JWTSecret: getEnv("JWT_SECRET", "your-secret-key"),
|
|
UploadPath: getEnv("UPLOAD_PATH", "./uploads"),
|
|
TestMode: getEnvBool("TEST_MODE", false),
|
|
RateLimitEnabled: getEnvBool("RATE_LIMIT_ENABLED", true),
|
|
RequestsPerMinute: getEnvInt("REQUESTS_PER_MINUTE", 10),
|
|
ScanPollIntervalSeconds: getEnvInt("SCAN_POLL_INTERVAL_SECONDS", 30),
|
|
}
|
|
}
|
|
|
|
func (c *Config) DatabaseURL() string {
|
|
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable",
|
|
c.DatabaseUser, c.DatabasePassword, c.DatabaseHost, c.DatabasePort, c.DatabaseName)
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func getEnvBool(key string, defaultValue bool) bool {
|
|
if value := os.Getenv(key); value != "" {
|
|
boolVal, err := strconv.ParseBool(value)
|
|
if err == nil {
|
|
return boolVal
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func getEnvInt(key string, defaultValue int) int {
|
|
if value := os.Getenv(key); value != "" {
|
|
intVal, err := strconv.Atoi(value)
|
|
if err == nil {
|
|
return intVal
|
|
}
|
|
}
|
|
return defaultValue
|
|
}
|