2022-06-06 13:48:53 +00:00
|
|
|
package conf
|
|
|
|
|
2022-06-25 13:34:44 +00:00
|
|
|
import (
|
2022-11-01 11:14:49 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/alist-org/alist/v3/cmd/flags"
|
2022-06-25 13:34:44 +00:00
|
|
|
"github.com/alist-org/alist/v3/pkg/utils/random"
|
|
|
|
)
|
|
|
|
|
2022-06-06 13:48:53 +00:00
|
|
|
type Database struct {
|
|
|
|
Type string `json:"type" env:"DB_TYPE"`
|
|
|
|
Host string `json:"host" env:"DB_HOST"`
|
|
|
|
Port int `json:"port" env:"DB_PORT"`
|
|
|
|
User string `json:"user" env:"DB_USER"`
|
|
|
|
Password string `json:"password" env:"DB_PASS"`
|
|
|
|
Name string `json:"name" env:"DB_NAME"`
|
|
|
|
DBFile string `json:"db_file" env:"DB_FILE"`
|
|
|
|
TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
|
2022-06-27 06:01:15 +00:00
|
|
|
SSLMode string `json:"ssl_mode" env:"DB_SSL_MODE"`
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Scheme struct {
|
2023-07-08 12:17:05 +00:00
|
|
|
Address string `json:"address" env:"ADDR"`
|
|
|
|
HttpPort int `json:"http_port" env:"HTTP_PORT"`
|
|
|
|
HttpsPort int `json:"https_port" env:"HTTPS_PORT"`
|
|
|
|
ForceHttps bool `json:"force_https" env:"FORCE_HTTPS"`
|
|
|
|
CertFile string `json:"cert_file" env:"CERT_FILE"`
|
|
|
|
KeyFile string `json:"key_file" env:"KEY_FILE"`
|
|
|
|
UnixFile string `json:"unix_file" env:"UNIX_FILE"`
|
|
|
|
UnixFilePerm string `json:"unix_file_perm" env:"UNIX_FILE_PERM"`
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LogConfig struct {
|
2022-09-25 09:41:04 +00:00
|
|
|
Enable bool `json:"enable" env:"LOG_ENABLE"`
|
2022-08-30 07:22:54 +00:00
|
|
|
Name string `json:"name" env:"LOG_NAME"`
|
|
|
|
MaxSize int `json:"max_size" env:"MAX_SIZE"`
|
|
|
|
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
|
|
|
|
MaxAge int `json:"max_age" env:"MAX_AGE"`
|
|
|
|
Compress bool `json:"compress" env:"COMPRESS"`
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Config struct {
|
2023-02-08 14:01:26 +00:00
|
|
|
Force bool `json:"force" env:"FORCE"`
|
|
|
|
SiteURL string `json:"site_url" env:"SITE_URL"`
|
|
|
|
Cdn string `json:"cdn" env:"CDN"`
|
|
|
|
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
|
|
|
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
|
|
|
|
Database Database `json:"database"`
|
|
|
|
Scheme Scheme `json:"scheme"`
|
|
|
|
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
|
|
|
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
|
|
|
|
Log LogConfig `json:"log"`
|
2023-06-05 08:00:31 +00:00
|
|
|
DelayedStart int `json:"delayed_start" env:"DELAYED_START"`
|
2023-02-08 14:01:26 +00:00
|
|
|
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
|
|
|
|
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultConfig() *Config {
|
2022-11-01 11:14:49 +00:00
|
|
|
tempDir := filepath.Join(flags.DataDir, "temp")
|
2022-11-28 05:45:25 +00:00
|
|
|
indexDir := filepath.Join(flags.DataDir, "bleve")
|
2022-11-01 11:14:49 +00:00
|
|
|
logPath := filepath.Join(flags.DataDir, "log/log.log")
|
|
|
|
dbPath := filepath.Join(flags.DataDir, "data.db")
|
2022-06-06 13:48:53 +00:00
|
|
|
return &Config{
|
2023-07-04 09:56:02 +00:00
|
|
|
Scheme: Scheme{
|
|
|
|
Address: "0.0.0.0",
|
|
|
|
UnixFile: "",
|
|
|
|
HttpPort: 5244,
|
|
|
|
HttpsPort: -1,
|
|
|
|
ForceHttps: false,
|
|
|
|
CertFile: "",
|
|
|
|
KeyFile: "",
|
|
|
|
},
|
2022-09-27 06:05:00 +00:00
|
|
|
JwtSecret: random.String(16),
|
|
|
|
TokenExpiresIn: 48,
|
2022-11-01 11:14:49 +00:00
|
|
|
TempDir: tempDir,
|
2022-06-06 13:48:53 +00:00
|
|
|
Database: Database{
|
|
|
|
Type: "sqlite3",
|
|
|
|
Port: 0,
|
|
|
|
TablePrefix: "x_",
|
2022-11-01 11:14:49 +00:00
|
|
|
DBFile: dbPath,
|
2022-06-06 13:48:53 +00:00
|
|
|
},
|
2022-11-28 05:45:25 +00:00
|
|
|
BleveDir: indexDir,
|
2022-06-06 13:48:53 +00:00
|
|
|
Log: LogConfig{
|
2022-08-30 07:22:54 +00:00
|
|
|
Enable: true,
|
2022-11-01 11:14:49 +00:00
|
|
|
Name: logPath,
|
2022-08-30 07:22:54 +00:00
|
|
|
MaxSize: 10,
|
|
|
|
MaxBackups: 5,
|
|
|
|
MaxAge: 28,
|
2022-06-06 13:48:53 +00:00
|
|
|
},
|
2023-02-08 14:01:26 +00:00
|
|
|
MaxConnections: 0,
|
2023-02-23 14:33:54 +00:00
|
|
|
TlsInsecureSkipVerify: true,
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
|
|
|
}
|