x
This commit is contained in:
parent
0f9f6fc265
commit
655a2bb016
@ -167,6 +167,9 @@ var handleMessage = func(msgs ...interface{}) interface{} {
|
||||
{ //tyt
|
||||
ss := regexp.MustCompile(`packetId=(\S+)(&|&)currentActId`).FindStringSubmatch(msg)
|
||||
if len(ss) > 0 {
|
||||
if Cdle {
|
||||
return "推毛线啊"
|
||||
}
|
||||
runTask(&Task{Path: "jd_tyt.js", Envs: []Env{
|
||||
{Name: "tytpacketId", Value: ss[1]},
|
||||
}}, msgs...)
|
||||
|
||||
60
models/cmd.go
Normal file
60
models/cmd.go
Normal file
@ -0,0 +1,60 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
|
||||
func cmd(str string, msgs ...interface{}) {
|
||||
cmd := exec.Command("sh", "-c", str)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
logs.Warn("cmd.StdoutPipe: ", err)
|
||||
return
|
||||
}
|
||||
cmd.Dir = ExecPath + "/scripts/"
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
logs.Warn("%v", err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
msg := ""
|
||||
reader := bufio.NewReader(stderr)
|
||||
for {
|
||||
line, err2 := reader.ReadString('\n')
|
||||
if err2 != nil || io.EOF == err2 {
|
||||
break
|
||||
}
|
||||
msg += line
|
||||
}
|
||||
if msg != "" {
|
||||
sendMessagee(msg, msgs...)
|
||||
}
|
||||
}()
|
||||
msg := ""
|
||||
reader := bufio.NewReader(stdout)
|
||||
st := time.Now()
|
||||
for {
|
||||
line, err2 := reader.ReadString('\n')
|
||||
if err2 != nil || io.EOF == err2 {
|
||||
break
|
||||
}
|
||||
msg += line
|
||||
nt := time.Now()
|
||||
if (nt.Unix() - st.Unix()) > 1 {
|
||||
go sendMessagee(msg, msgs...)
|
||||
st = nt
|
||||
msg = ""
|
||||
}
|
||||
}
|
||||
if msg != "" {
|
||||
sendMessagee(msg, msgs...)
|
||||
}
|
||||
err = cmd.Wait()
|
||||
}
|
||||
@ -17,6 +17,8 @@ func initCron() {
|
||||
logs.Info("资产推送任务就绪")
|
||||
}
|
||||
c.AddFunc("3 */1 * * *", initVersion)
|
||||
c.AddFunc("40 */1 * * *", GitPullAll)
|
||||
|
||||
}
|
||||
c.Start()
|
||||
}
|
||||
|
||||
@ -62,6 +62,7 @@ if(pins){
|
||||
}
|
||||
module.exports = cookies`, cookies))
|
||||
f.Close()
|
||||
go CopyConfigAll()
|
||||
tmp = []JdCookie{}
|
||||
for _, ck := range cks {
|
||||
if ck.Hack != True {
|
||||
|
||||
@ -3,42 +3,94 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
Git string
|
||||
filename string
|
||||
ok bool
|
||||
Task []Task
|
||||
path string
|
||||
}
|
||||
|
||||
var reposPath = ""
|
||||
|
||||
func (rp *Repo) init() {
|
||||
rp.filename = strings.Replace(strings.Replace(strings.Replace(rp.Git, "https://", "", -1), "/", "_", -1), ".git", "", -1)
|
||||
if !rp.exist() {
|
||||
rp.gitClone()
|
||||
} else {
|
||||
rp.gitPull()
|
||||
}
|
||||
rp.path = reposPath + "/" + rp.filename
|
||||
CopyConfigAll()
|
||||
rp.addTask()
|
||||
}
|
||||
|
||||
func (rp *Repo) exist() bool {
|
||||
if _, err := os.Stat(ExecPath + "/" + rp.filename); err != nil {
|
||||
if _, err := os.Stat(rp.path); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func initRepos() {
|
||||
if _, err := os.Stat(ExecPath); err != nil {
|
||||
os.MkdirAll(ExecPath, 777)
|
||||
reposPath = ExecPath + "/repos"
|
||||
if _, err := os.Stat(reposPath); err != nil {
|
||||
os.MkdirAll(reposPath, os.ModePerm)
|
||||
}
|
||||
for _, repo := range Config.Repos {
|
||||
repo.init()
|
||||
for i := range Config.Repos {
|
||||
Config.Repos[i].init()
|
||||
}
|
||||
}
|
||||
|
||||
func GitPullAll() {
|
||||
for i := range Config.Repos {
|
||||
if Config.Repos[i].exist() {
|
||||
Config.Repos[i].gitPull()
|
||||
Config.Repos[i].cpConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CopyConfigAll() {
|
||||
for i := range Config.Repos {
|
||||
if Config.Repos[i].exist() {
|
||||
Config.Repos[i].cpConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (rp *Repo) gitClone() {
|
||||
cmd := exec.Command("sh", "-c", fmt.Sprintf("git clone %s %s", rp.Git, rp.filename))
|
||||
cmd.Path = ExecPath
|
||||
fmt.Println("sh", "-c", fmt.Sprintf("git clone %s %s", rp.Git, rp.filename))
|
||||
fmt.Println(cmd.Output())
|
||||
cmd(fmt.Sprintf("cd %s && git clone %s %s", reposPath, rp.Git, rp.filename))
|
||||
}
|
||||
|
||||
func (rp *Repo) gitPull() {
|
||||
cmd(fmt.Sprintf("cd %s && git stash && git pull", rp.path))
|
||||
}
|
||||
|
||||
func (rp *Repo) cpConfig() {
|
||||
cmd(fmt.Sprintf(`cp jdCookie.js %s`, rp.path+"/jdCookie.js"))
|
||||
}
|
||||
|
||||
func (rp *Repo) addTask() {
|
||||
// dir_list, e := ioutil.ReadDir(rp.path)
|
||||
// if e != nil {
|
||||
// return
|
||||
// }
|
||||
// for _, v := range dir_list {
|
||||
// if strings.Contains(v.Name(), ".js") {
|
||||
// f, err := os.Open(rp.path + "/" + v.Name())
|
||||
// if err != nil {
|
||||
// continue
|
||||
// }
|
||||
// data, _ := ioutil.ReadAll(f)
|
||||
// f.Close()
|
||||
// // fmt.Println(data)
|
||||
// res := regexp.MustCompile("().*Env[(]['\"](\\S+)['\"][)]").FindStringSubmatch(string(data))
|
||||
// if len(res) > 0 {
|
||||
// fmt.Println(res[1])
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@ -159,53 +159,3 @@ func runTask(task *Task, msgs ...interface{}) string {
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func cmd(str string, msgs ...interface{}) {
|
||||
cmd := exec.Command("sh", "-c", str)
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
stderr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
logs.Warn("cmd.StdoutPipe: ", err)
|
||||
return
|
||||
}
|
||||
cmd.Dir = ExecPath + "/scripts/"
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
logs.Warn("%v", err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
msg := ""
|
||||
reader := bufio.NewReader(stderr)
|
||||
for {
|
||||
line, err2 := reader.ReadString('\n')
|
||||
if err2 != nil || io.EOF == err2 {
|
||||
break
|
||||
}
|
||||
msg += line
|
||||
}
|
||||
if msg != "" {
|
||||
sendMessagee(msg, msgs...)
|
||||
}
|
||||
}()
|
||||
msg := ""
|
||||
reader := bufio.NewReader(stdout)
|
||||
st := time.Now()
|
||||
for {
|
||||
line, err2 := reader.ReadString('\n')
|
||||
if err2 != nil || io.EOF == err2 {
|
||||
break
|
||||
}
|
||||
msg += line
|
||||
nt := time.Now()
|
||||
if (nt.Unix() - st.Unix()) > 1 {
|
||||
go sendMessagee(msg, msgs...)
|
||||
st = nt
|
||||
msg = ""
|
||||
}
|
||||
}
|
||||
if msg != "" {
|
||||
sendMessagee(msg, msgs...)
|
||||
}
|
||||
err = cmd.Wait()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user