Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/conf/config.go
1560 views
1
package conf
2
3
import (
4
"path/filepath"
5
6
"github.com/alist-org/alist/v3/cmd/flags"
7
"github.com/alist-org/alist/v3/pkg/utils/random"
8
)
9
10
type Database struct {
11
Type string `json:"type" env:"TYPE"`
12
Host string `json:"host" env:"HOST"`
13
Port int `json:"port" env:"PORT"`
14
User string `json:"user" env:"USER"`
15
Password string `json:"password" env:"PASS"`
16
Name string `json:"name" env:"NAME"`
17
DBFile string `json:"db_file" env:"FILE"`
18
TablePrefix string `json:"table_prefix" env:"TABLE_PREFIX"`
19
SSLMode string `json:"ssl_mode" env:"SSL_MODE"`
20
DSN string `json:"dsn" env:"DSN"`
21
}
22
23
type Meilisearch struct {
24
Host string `json:"host" env:"HOST"`
25
APIKey string `json:"api_key" env:"API_KEY"`
26
IndexPrefix string `json:"index_prefix" env:"INDEX_PREFIX"`
27
}
28
29
type Scheme struct {
30
Address string `json:"address" env:"ADDR"`
31
HttpPort int `json:"http_port" env:"HTTP_PORT"`
32
HttpsPort int `json:"https_port" env:"HTTPS_PORT"`
33
ForceHttps bool `json:"force_https" env:"FORCE_HTTPS"`
34
CertFile string `json:"cert_file" env:"CERT_FILE"`
35
KeyFile string `json:"key_file" env:"KEY_FILE"`
36
UnixFile string `json:"unix_file" env:"UNIX_FILE"`
37
UnixFilePerm string `json:"unix_file_perm" env:"UNIX_FILE_PERM"`
38
EnableH2c bool `json:"enable_h2c" env:"ENABLE_H2C"`
39
}
40
41
type LogConfig struct {
42
Enable bool `json:"enable" env:"LOG_ENABLE"`
43
Name string `json:"name" env:"LOG_NAME"`
44
MaxSize int `json:"max_size" env:"MAX_SIZE"`
45
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
46
MaxAge int `json:"max_age" env:"MAX_AGE"`
47
Compress bool `json:"compress" env:"COMPRESS"`
48
}
49
50
type TaskConfig struct {
51
Workers int `json:"workers" env:"WORKERS"`
52
MaxRetry int `json:"max_retry" env:"MAX_RETRY"`
53
TaskPersistant bool `json:"task_persistant" env:"TASK_PERSISTANT"`
54
}
55
56
type TasksConfig struct {
57
Download TaskConfig `json:"download" envPrefix:"DOWNLOAD_"`
58
Transfer TaskConfig `json:"transfer" envPrefix:"TRANSFER_"`
59
Upload TaskConfig `json:"upload" envPrefix:"UPLOAD_"`
60
Copy TaskConfig `json:"copy" envPrefix:"COPY_"`
61
Decompress TaskConfig `json:"decompress" envPrefix:"DECOMPRESS_"`
62
DecompressUpload TaskConfig `json:"decompress_upload" envPrefix:"DECOMPRESS_UPLOAD_"`
63
AllowRetryCanceled bool `json:"allow_retry_canceled" env:"ALLOW_RETRY_CANCELED"`
64
}
65
66
type Cors struct {
67
AllowOrigins []string `json:"allow_origins" env:"ALLOW_ORIGINS"`
68
AllowMethods []string `json:"allow_methods" env:"ALLOW_METHODS"`
69
AllowHeaders []string `json:"allow_headers" env:"ALLOW_HEADERS"`
70
}
71
72
type S3 struct {
73
Enable bool `json:"enable" env:"ENABLE"`
74
Port int `json:"port" env:"PORT"`
75
SSL bool `json:"ssl" env:"SSL"`
76
}
77
78
type FTP struct {
79
Enable bool `json:"enable" env:"ENABLE"`
80
Listen string `json:"listen" env:"LISTEN"`
81
FindPasvPortAttempts int `json:"find_pasv_port_attempts" env:"FIND_PASV_PORT_ATTEMPTS"`
82
ActiveTransferPortNon20 bool `json:"active_transfer_port_non_20" env:"ACTIVE_TRANSFER_PORT_NON_20"`
83
IdleTimeout int `json:"idle_timeout" env:"IDLE_TIMEOUT"`
84
ConnectionTimeout int `json:"connection_timeout" env:"CONNECTION_TIMEOUT"`
85
DisableActiveMode bool `json:"disable_active_mode" env:"DISABLE_ACTIVE_MODE"`
86
DefaultTransferBinary bool `json:"default_transfer_binary" env:"DEFAULT_TRANSFER_BINARY"`
87
EnableActiveConnIPCheck bool `json:"enable_active_conn_ip_check" env:"ENABLE_ACTIVE_CONN_IP_CHECK"`
88
EnablePasvConnIPCheck bool `json:"enable_pasv_conn_ip_check" env:"ENABLE_PASV_CONN_IP_CHECK"`
89
}
90
91
type SFTP struct {
92
Enable bool `json:"enable" env:"ENABLE"`
93
Listen string `json:"listen" env:"LISTEN"`
94
}
95
96
type Config struct {
97
Force bool `json:"force" env:"FORCE"`
98
SiteURL string `json:"site_url" env:"SITE_URL"`
99
Cdn string `json:"cdn" env:"CDN"`
100
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
101
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
102
Database Database `json:"database" envPrefix:"DB_"`
103
Meilisearch Meilisearch `json:"meilisearch" envPrefix:"MEILISEARCH_"`
104
Scheme Scheme `json:"scheme"`
105
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
106
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
107
DistDir string `json:"dist_dir"`
108
Log LogConfig `json:"log"`
109
DelayedStart int `json:"delayed_start" env:"DELAYED_START"`
110
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
111
MaxConcurrency int `json:"max_concurrency" env:"MAX_CONCURRENCY"`
112
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
113
Tasks TasksConfig `json:"tasks" envPrefix:"TASKS_"`
114
Cors Cors `json:"cors" envPrefix:"CORS_"`
115
S3 S3 `json:"s3" envPrefix:"S3_"`
116
FTP FTP `json:"ftp" envPrefix:"FTP_"`
117
SFTP SFTP `json:"sftp" envPrefix:"SFTP_"`
118
LastLaunchedVersion string `json:"last_launched_version"`
119
}
120
121
func DefaultConfig() *Config {
122
tempDir := filepath.Join(flags.DataDir, "temp")
123
indexDir := filepath.Join(flags.DataDir, "bleve")
124
logPath := filepath.Join(flags.DataDir, "log/log.log")
125
dbPath := filepath.Join(flags.DataDir, "data.db")
126
return &Config{
127
Scheme: Scheme{
128
Address: "0.0.0.0",
129
UnixFile: "",
130
HttpPort: 5244,
131
HttpsPort: -1,
132
ForceHttps: false,
133
CertFile: "",
134
KeyFile: "",
135
},
136
JwtSecret: random.String(16),
137
TokenExpiresIn: 48,
138
TempDir: tempDir,
139
Database: Database{
140
Type: "sqlite3",
141
Port: 0,
142
TablePrefix: "x_",
143
DBFile: dbPath,
144
},
145
Meilisearch: Meilisearch{
146
Host: "http://localhost:7700",
147
},
148
BleveDir: indexDir,
149
Log: LogConfig{
150
Enable: true,
151
Name: logPath,
152
MaxSize: 50,
153
MaxBackups: 30,
154
MaxAge: 28,
155
},
156
MaxConnections: 0,
157
MaxConcurrency: 64,
158
TlsInsecureSkipVerify: true,
159
Tasks: TasksConfig{
160
Download: TaskConfig{
161
Workers: 5,
162
MaxRetry: 1,
163
// TaskPersistant: true,
164
},
165
Transfer: TaskConfig{
166
Workers: 5,
167
MaxRetry: 2,
168
// TaskPersistant: true,
169
},
170
Upload: TaskConfig{
171
Workers: 5,
172
},
173
Copy: TaskConfig{
174
Workers: 5,
175
MaxRetry: 2,
176
// TaskPersistant: true,
177
},
178
Decompress: TaskConfig{
179
Workers: 5,
180
MaxRetry: 2,
181
// TaskPersistant: true,
182
},
183
DecompressUpload: TaskConfig{
184
Workers: 5,
185
MaxRetry: 2,
186
},
187
AllowRetryCanceled: false,
188
},
189
Cors: Cors{
190
AllowOrigins: []string{"*"},
191
AllowMethods: []string{"*"},
192
AllowHeaders: []string{"*"},
193
},
194
S3: S3{
195
Enable: false,
196
Port: 5246,
197
SSL: false,
198
},
199
FTP: FTP{
200
Enable: false,
201
Listen: ":5221",
202
FindPasvPortAttempts: 50,
203
ActiveTransferPortNon20: false,
204
IdleTimeout: 900,
205
ConnectionTimeout: 30,
206
DisableActiveMode: false,
207
DefaultTransferBinary: false,
208
EnableActiveConnIPCheck: true,
209
EnablePasvConnIPCheck: true,
210
},
211
SFTP: SFTP{
212
Enable: false,
213
Listen: ":5222",
214
},
215
LastLaunchedVersion: "",
216
}
217
}
218
219