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 07aad3b8d4
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m24s
JWT key issue fix
2026-05-24 11:26:55 -07:00

59 lines
1.4 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
}
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", ""),
}
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
}