This repository has been archived on 2026-07-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drive/backend/config/config.go
Elijah a7f76e2e97
Some checks failed
Automated Container Build / build-and-push (push) Failing after 53s
fix: add MaxLoginAttempts to Config struct
2026-05-26 13:34:31 -07:00

69 lines
1.7 KiB
Go

package config
import (
"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"
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
}