package config import ( "log" "os" "strconv" ) type Config struct { Port string DataDir string StorageDir string JWTSecret string JWTExpirySecs int DBPath string ThumbnailDir string TrashDir string VersionsDir string BackupDir string MaxLoginAttempts int LockoutSeconds int OnlyOfficeJWT string OnlyOfficeHost string PublicURL string InternalAPIURL string } func Load() *Config { cfg := &Config{ Port: getEnv("PORT", "5827"), DataDir: getEnv("DATA_DIR", "/app/data"), StorageDir: getEnv("STORAGE_DIR", "/storage"), JWTSecret: getEnv("JWT_SECRET", ""), JWTExpirySecs: getEnvInt("JWT_EXPIRY_SECS", 900), // 15 minutes MaxLoginAttempts: getEnvInt("MAX_LOGIN_ATTEMPTS", 5), LockoutSeconds: getEnvInt("LOCKOUT_SECONDS", 300), // 5 minutes OnlyOfficeJWT: getEnv("ONLYOFFICE_JWT_SECRET", ""), OnlyOfficeHost: getEnv("ONLYOFFICE_HOST", "office.elijahkuntz.com"), PublicURL: getEnv("PUBLIC_URL", ""), InternalAPIURL: getEnv("INTERNAL_API_URL", "http://192.168.50.81:5827/api"), } if cfg.InternalAPIURL == "" && cfg.PublicURL != "" { cfg.InternalAPIURL = cfg.PublicURL } cfg.DBPath = cfg.DataDir + "/drive.db" cfg.ThumbnailDir = cfg.DataDir + "/thumbnails" cfg.TrashDir = cfg.StorageDir + "/.trash" cfg.VersionsDir = cfg.StorageDir + "/.versions" cfg.BackupDir = cfg.StorageDir + "/.backups" if cfg.OnlyOfficeJWT == "" { log.Println("WARNING: ONLYOFFICE_JWT_SECRET not set \u2014 Document Server requests will NOT be authenticated.") log.Println(" Anyone with network access to the Document Server can open/edit documents.") } return cfg } func getEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { return value } return fallback } func getEnvInt(key string, fallback int) int { if value, ok := os.LookupEnv(key); ok { if intVal, err := strconv.Atoi(value); err == nil { return intVal } } return fallback }