diff --git a/conf/config.yaml b/conf/config.yaml index 009bc19..edead3c 100755 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,11 +1,11 @@ mode: parallel containers: - - address: http://192.168.31.233:5700 - username: admin - password: admin - weigth: - mode: parallel - limit: 9999 + # - address: http://192.168.31.233:5700 + # username: admin + # password: admin + # weigth: + # mode: parallel + # limit: 9999 theme: static: ./static master: diff --git a/models/config.go b/models/config.go index 184b159..615f1da 100644 --- a/models/config.go +++ b/models/config.go @@ -31,6 +31,10 @@ type Yaml struct { 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 } var Balance = "balance" @@ -79,8 +83,8 @@ func initConfig() { //测试 if ExecPath == "/Users/cdle/Desktop/xdd" { Cdle = true - Config.QQID = 17745270 - Config.QQGroupID = 610790654 + // Config.QQID = 17745270 + // Config.QQGroupID = 610790654 } if Config.NoGhproxy { GhProxy = "" @@ -88,4 +92,16 @@ func initConfig() { 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" + } } diff --git a/models/init.go b/models/init.go index 7218325..3e1ceac 100644 --- a/models/init.go +++ b/models/init.go @@ -25,4 +25,5 @@ func init() { initCron() go initTgBot() InitReplies() + initTask() } diff --git a/models/task.go b/models/task.go index c201125..02eff25 100644 --- a/models/task.go +++ b/models/task.go @@ -1,14 +1,78 @@ package models +import ( + "io" + "os" + "strings" + + "github.com/beego/beego/v2/client/httplib" + "github.com/beego/beego/v2/core/logs" +) + type Task struct { + ID int Cron string Path string Enable bool Mode string //obo alo Word string + Run func() + Name string } type Env struct { Name string Value string } + +func initTask() { + for i := range Config.Tasks { + if Config.Tasks[i].Name == "" { + slice := strings.Split(Config.Tasks[i].Path, "/") + len := len(slice) + if len == 0 { + return + } + Config.Tasks[i].Name = slice[len-1] + } + createTask(&Config.Tasks[i]) + } +} + +func createTask(task *Task) { + id, err := c.AddFunc(task.Cron, func() { + runTask(task) + }) + if err != nil { + logs.Warn(task.Word, "任务创建失败:", err) + } else { + task.ID = int(id) + logs.Info(task.Word, "任务创建成功:", err) + } + +} + +func runTask(task *Task) { + var path = ExecPath + "/scripts/" + task.Name + if strings.Contains(task.Path, "http") { + f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777) + if err != nil { + logs.Warn("打开%s失败,", path, err) + } + url := task.Path + if strings.Contains(url, "raw.githubusercontent.com") { + url = GhProxy + url + } + r, err := httplib.Get(url).Response() + if err != nil { + logs.Warn("下载%s失败,", task.Path, err) + } + io.Copy(f, r.Body) + f.Close() + } + // lan := Config.Node + // if strings.Contains(task.Name, ".py") { + // lan = Config.Python + // } + // cmd := exec.Command(lan, ) +} diff --git a/qrcode.png b/qrcode.png new file mode 100644 index 0000000..eec782c Binary files /dev/null and b/qrcode.png differ