forked from whzsyx/xdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
108 lines (101 loc) · 2.65 KB
/
config.go
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
package models
import (
"io"
"io/ioutil"
"os"
"github.com/beego/beego/v2/client/httplib"
"github.com/beego/beego/v2/core/logs"
"gopkg.in/yaml.v2"
)
type Yaml struct {
Containers []Container
// Tasks []Task
Qrcode string
Master string
Mode string
Static string
Database string
QywxKey string `yaml:"qywx_key"`
Resident string
UserAgent string `yaml:"user_agent"`
Theme string
TelegramBotToken string `yaml:"telegram_bot_token"`
TelegramUserID int `yaml:"telegram_user_id"`
QQID int64 `yaml:"qquid"`
QQGroupID int64 `yaml:"qqgid"`
DefaultPriority int `yaml:"default_priority"`
NoGhproxy bool `yaml:"no_ghproxy"`
QbotPublicMode bool `yaml:"qbot_public_mode"`
DailyAssetPushCron string `yaml:"daily_asset_push_cron"`
Version string `yaml:"version"`
Node string
Npm string
Python string
Pip string
NoAdmin bool `yaml:"no_admin"`
QbotConfigFile string `yaml:"qbot_config_file"`
Repos []Repo
}
var Balance = "balance"
var Parallel = "parallel"
var GhProxy = "https://ghproxy.com/"
var Cdle = false
var Config Yaml
func initConfig() {
confDir := ExecPath + "/conf"
if _, err := os.Stat(confDir); err != nil {
os.MkdirAll(confDir, os.ModePerm)
}
for _, name := range []string{"app.conf", "config.yaml", "reply.php"} {
f, err := os.OpenFile(ExecPath+"/conf/"+name, os.O_RDWR|os.O_CREATE, 0777)
if err != nil {
logs.Warn(err)
}
s, _ := ioutil.ReadAll(f)
if len(s) == 0 {
logs.Info("下载配置%s", name)
r, err := httplib.Get(GhProxy + "https://raw.githubusercontent.com/cdle/xdd/main/conf/demo_" + name).Response()
if err == nil {
io.Copy(f, r.Body)
}
}
f.Close()
}
content, err := ioutil.ReadFile(ExecPath + "/conf/config.yaml")
if err != nil {
logs.Warn("解析config.yaml读取错误: %v", err)
}
if yaml.Unmarshal(content, &Config) != nil {
logs.Warn("解析config.yaml出错: %v", err)
}
if ExecPath == "/Users/cdle/Desktop/xdd" || Config.NoAdmin {
Cdle = true
}
if Config.Master == "" {
Config.Master = "xxxx"
}
if Config.Mode != Parallel {
Config.Mode = Balance
}
if Config.Qrcode != "" {
Config.Theme = Config.Qrcode
}
if Config.NoGhproxy {
GhProxy = ""
}
if Config.Database == "" {
Config.Database = ExecPath + "/.xdd.db"
}
if Config.Npm == "" {
Config.Npm = "npm"
}
if Config.Node == "" {
Config.Node = "node"
}
if Config.Python == "" {
Config.Python = "python3"
}
if Config.Pip == "" {
Config.Pip = "Pip3"
}
}