Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/conf/config.go
2327 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
S3Transition TaskConfig `json:"s3_transition" envPrefix:"S3_TRANSITION_"`
64
AllowRetryCanceled bool `json:"allow_retry_canceled" env:"ALLOW_RETRY_CANCELED"`
65
}
66
67
type Cors struct {
68
AllowOrigins []string `json:"allow_origins" env:"ALLOW_ORIGINS"`
69
AllowMethods []string `json:"allow_methods" env:"ALLOW_METHODS"`
70
AllowHeaders []string `json:"allow_headers" env:"ALLOW_HEADERS"`
71
}
72
73
type S3 struct {
74
Enable bool `json:"enable" env:"ENABLE"`
75
Port int `json:"port" env:"PORT"`
76
SSL bool `json:"ssl" env:"SSL"`
77
}
78
79
type FTP struct {
80
Enable bool `json:"enable" env:"ENABLE"`
81
Listen string `json:"listen" env:"LISTEN"`
82
FindPasvPortAttempts int `json:"find_pasv_port_attempts" env:"FIND_PASV_PORT_ATTEMPTS"`
83
ActiveTransferPortNon20 bool `json:"active_transfer_port_non_20" env:"ACTIVE_TRANSFER_PORT_NON_20"`
84
IdleTimeout int `json:"idle_timeout" env:"IDLE_TIMEOUT"`
85
ConnectionTimeout int `json:"connection_timeout" env:"CONNECTION_TIMEOUT"`
86
DisableActiveMode bool `json:"disable_active_mode" env:"DISABLE_ACTIVE_MODE"`
87
DefaultTransferBinary bool `json:"default_transfer_binary" env:"DEFAULT_TRANSFER_BINARY"`
88
EnableActiveConnIPCheck bool `json:"enable_active_conn_ip_check" env:"ENABLE_ACTIVE_CONN_IP_CHECK"`
89
EnablePasvConnIPCheck bool `json:"enable_pasv_conn_ip_check" env:"ENABLE_PASV_CONN_IP_CHECK"`
90
}
91
92
type SFTP struct {
93
Enable bool `json:"enable" env:"ENABLE"`
94
Listen string `json:"listen" env:"LISTEN"`
95
}
96
97
type Config struct {
98
Force bool `json:"force" env:"FORCE"`
99
SiteURL string `json:"site_url" env:"SITE_URL"`
100
Cdn string `json:"cdn" env:"CDN"`
101
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
102
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
103
Database Database `json:"database" envPrefix:"DB_"`
104
Meilisearch Meilisearch `json:"meilisearch" envPrefix:"MEILISEARCH_"`
105
Scheme Scheme `json:"scheme"`
106
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
107
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
108
DistDir string `json:"dist_dir"`
109
Log LogConfig `json:"log"`
110
DelayedStart int `json:"delayed_start" env:"DELAYED_START"`
111
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
112
MaxConcurrency int `json:"max_concurrency" env:"MAX_CONCURRENCY"`
113
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
114
Tasks TasksConfig `json:"tasks" envPrefix:"TASKS_"`
115
Cors Cors `json:"cors" envPrefix:"CORS_"`
116
S3 S3 `json:"s3" envPrefix:"S3_"`
117
FTP FTP `json:"ftp" envPrefix:"FTP_"`
118
SFTP SFTP `json:"sftp" envPrefix:"SFTP_"`
119
LastLaunchedVersion string `json:"last_launched_version"`
120
}
121
122
func DefaultConfig() *Config {
123
tempDir := filepath.Join(flags.DataDir, "temp")
124
indexDir := filepath.Join(flags.DataDir, "bleve")
125
logPath := filepath.Join(flags.DataDir, "log/log.log")
126
dbPath := filepath.Join(flags.DataDir, "data.db")
127
return &Config{
128
Scheme: Scheme{
129
Address: "0.0.0.0",
130
UnixFile: "",
131
HttpPort: 5244,
132
HttpsPort: -1,
133
ForceHttps: false,
134
CertFile: "",
135
KeyFile: "",
136
},
137
JwtSecret: random.String(16),
138
TokenExpiresIn: 48,
139
TempDir: tempDir,
140
Database: Database{
141
Type: "sqlite3",
142
Port: 0,
143
TablePrefix: "x_",
144
DBFile: dbPath,
145
},
146
Meilisearch: Meilisearch{
147
Host: "http://localhost:7700",
148
},
149
BleveDir: indexDir,
150
Log: LogConfig{
151
Enable: true,
152
Name: logPath,
153
MaxSize: 50,
154
MaxBackups: 30,
155
MaxAge: 28,
156
},
157
MaxConnections: 0,
158
MaxConcurrency: 64,
159
TlsInsecureSkipVerify: false,
160
Tasks: TasksConfig{
161
Download: TaskConfig{
162
Workers: 5,
163
MaxRetry: 1,
164
// TaskPersistant: true,
165
},
166
Transfer: TaskConfig{
167
Workers: 5,
168
MaxRetry: 2,
169
// TaskPersistant: true,
170
},
171
Upload: TaskConfig{
172
Workers: 5,
173
},
174
Copy: TaskConfig{
175
Workers: 5,
176
MaxRetry: 2,
177
// TaskPersistant: true,
178
},
179
Decompress: TaskConfig{
180
Workers: 5,
181
MaxRetry: 2,
182
// TaskPersistant: true,
183
},
184
DecompressUpload: TaskConfig{
185
Workers: 5,
186
MaxRetry: 2,
187
},
188
S3Transition: TaskConfig{
189
Workers: 5,
190
MaxRetry: 2,
191
// TaskPersistant: true,
192
},
193
AllowRetryCanceled: false,
194
},
195
Cors: Cors{
196
AllowOrigins: []string{"*"},
197
AllowMethods: []string{"*"},
198
AllowHeaders: []string{"*"},
199
},
200
S3: S3{
201
Enable: false,
202
Port: 5246,
203
SSL: false,
204
},
205
FTP: FTP{
206
Enable: false,
207
Listen: ":5221",
208
FindPasvPortAttempts: 50,
209
ActiveTransferPortNon20: false,
210
IdleTimeout: 900,
211
ConnectionTimeout: 30,
212
DisableActiveMode: false,
213
DefaultTransferBinary: false,
214
EnableActiveConnIPCheck: true,
215
EnablePasvConnIPCheck: true,
216
},
217
SFTP: SFTP{
218
Enable: false,
219
Listen: ":5222",
220
},
221
LastLaunchedVersion: "",
222
}
223
}
224
225