-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.go
More file actions
116 lines (98 loc) · 3.01 KB
/
Copy pathconfig.go
File metadata and controls
116 lines (98 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
type Config struct {
OwnerPubkey string
RelayName string
RelayDescription string
DBPath string
RelayURL string
RelayPort string
RefreshInterval int
MinFollowers int
RelayContact string
RelayIcon string
PowWhitelist int
PowDMWhitelist int
BlossomAssetsPath string
BlossomPublicURL string
BackupBlossomMedia bool
MaxFileSizeMB int
FetchAllInteractions bool
SkipDeletions bool
Negentropy bool
NegentropyAuth bool
}
func LoadConfig() Config {
godotenv.Load(".env")
if os.Getenv("REFRESH_INTERVAL") == "" {
os.Setenv("REFRESH_INTERVAL", "3")
}
refreshInterval, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL"))
log.Println("📝 Set refresh interval to", refreshInterval, "hours")
if os.Getenv("MIN_FOLLOWERS") == "" {
os.Setenv("MIN_FOLLOWERS", "1")
}
if os.Getenv("POW_WHITELIST") == "" {
os.Setenv("POW_WHITELIST", "999")
}
if os.Getenv("POW_DM_WHITELIST") == "" {
os.Setenv("POW_DM_WHITELIST", "999")
}
if os.Getenv("BLOSSOM_BACKUP_MEDIA") == "" {
os.Setenv("BLOSSOM_BACKUP_MEDIA", "FALSE")
}
if os.Getenv("FETCH_ALL_INTERACTIONS") == "" {
os.Setenv("FETCH_ALL_INTERACTIONS", "FALSE")
}
if os.Getenv("SKIP_DELETIONS") == "" {
os.Setenv("SKIP_DELETIONS", "FALSE")
}
if os.Getenv("NEGENTROPY") == "" {
os.Setenv("NEGENTROPY", "TRUE")
}
if os.Getenv("NEGENTROPY_AUTH") == "" {
os.Setenv("NEGENTROPY_AUTH", "TRUE")
}
if os.Getenv("BLOSSOM_MAX_FILE_MB") == "" {
os.Setenv("BLOSSOM_MAX_FILE_MB", "10")
}
minFollowers, _ := strconv.Atoi(os.Getenv("MIN_FOLLOWERS"))
PowWhitelist, _ := strconv.Atoi(os.Getenv("POW_WHITELIST"))
PowDMWhitelist, _ := strconv.Atoi(os.Getenv("POW_DM_WHITELIST"))
maxFileSizeMB, _ := strconv.Atoi(os.Getenv("BLOSSOM_MAX_FILE_MB"))
config := Config{
OwnerPubkey: getEnv("OWNER_PUBKEY"),
RelayName: getEnv("RELAY_NAME"),
RelayDescription: getEnv("RELAY_DESCRIPTION"),
RelayContact: getEnv("RELAY_CONTACT"),
RelayIcon: getEnv("RELAY_ICON"),
DBPath: getEnv("DB_PATH"),
RelayURL: getEnv("RELAY_URL"),
RelayPort: getEnv("RELAY_PORT"),
RefreshInterval: refreshInterval,
MinFollowers: minFollowers,
PowWhitelist: PowWhitelist,
PowDMWhitelist: PowDMWhitelist,
BlossomAssetsPath: getEnv("BLOSSOM_ASSETS_PATH"),
BlossomPublicURL: getEnv("BLOSSOM_PUBLIC_URL"),
BackupBlossomMedia: getEnv("BLOSSOM_BACKUP_MEDIA") == "TRUE",
MaxFileSizeMB: maxFileSizeMB,
FetchAllInteractions: getEnv("FETCH_ALL_INTERACTIONS") == "TRUE",
SkipDeletions: getEnv("SKIP_DELETIONS") == "TRUE",
Negentropy: getEnv("NEGENTROPY") == "TRUE",
NegentropyAuth: getEnv("NEGENTROPY_AUTH") == "TRUE",
}
return config
}
func getEnv(key string) string {
value, exists := os.LookupEnv(key)
if !exists {
log.Fatalf("Environment variable %s not set", key)
}
return value
}