diff --git a/base/web/dream.go b/base/web/dream.go index a8e15e7d..286d57f3 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -63,26 +63,29 @@ func _dream_start(m *ice.Message, name string) { m.Info("already exists %v", pid) return } - for i := 0; i < 3; i++ { - if msg := m.Cmd(SPACE, name); msg.Length() > 0 { - m.Info("already exists %v", name) - return - } - m.Sleep300ms() + } + for i := 0; i < 3; i++ { + if msg := m.Cmd(SPACE, name); msg.Length() > 0 { + m.Info("already exists %v", name) + return } + m.Sleep300ms() } defer ToastProcess(m)() - defer m.Sleep3s() m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.EnvList(kit.Simple( cli.CTX_OPS, Domain(tcp.LOCALHOST, m.Cmdv(SERVE, tcp.PORT)), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_PID, ice.VAR_LOG_ICE_PID, cli.CTX_ROOT, kit.Path(""), cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username, )...), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE) defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "") + bin := kit.Select(kit.Path(os.Args[0]), cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN)) + if strings.Count(m.Cmdx(cli.SYSTEM, "sh", "-c", "ps aux | grep "+bin), bin) > 0 { + return + } + defer m.Sleep3s() gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE)) kit.If(m.Option(nfs.BINARY), func(p string) { _dream_binary(m, p) }) kit.If(m.Option(nfs.TEMPLATE), func(p string) { _dream_template(m, p) }) - m.Cmd(cli.DAEMON, kit.Select(kit.Path(os.Args[0]), cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN)), - SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME), cli.DAEMON, ice.OPS) + m.Cmd(cli.DAEMON, bin, SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME), cli.DAEMON, ice.OPS) } func _dream_binary(m *ice.Message, p string) { if bin := path.Join(m.Option(cli.CMD_DIR), ice.BIN_ICE_BIN); nfs.Exists(m, bin) { diff --git a/base/web/space.go b/base/web/space.go index 29e678e4..24c8c565 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -140,24 +140,34 @@ func _space_exec(m *ice.Message, source, target []string, c *websocket.Conn) { func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) { defer func() { m.Warn(recover()) }() if m.Options(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:]); !m.Warn(c.WriteMessage(1, []byte(m.FormatMeta()))) { - m.Log(tcp.SEND, "%v->%v %v %v", source, target, m.Detailv(), m.FormatsMeta(nil)) + if source != nil { + m.Log(tcp.SEND, "%v->%v %v %v", source, target, m.Detailv(), m.FormatsMeta(nil)) + } } } func _space_send(m *ice.Message, name string, arg ...string) (h string) { - wait, done := m.Wait("180s", func(msg *ice.Message, arg ...string) { + withecho := true + kit.If(len(arg) > 0 && arg[0] == "toast", func() { withecho = false; m.Option(ice.MSG_DEBUG, ice.FALSE) }) + wait, done := m.Wait(kit.Select("", "180s", withecho), func(msg *ice.Message, arg ...string) { m.Cost(kit.Format("%v->[%v] %v %v", m.Optionv(ice.MSG_SOURCE), name, m.Detailv(), msg.FormatSize())).Copy(msg) }) - h = mdb.HashCreate(m.Spawn(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done)) - defer mdb.HashRemove(m.Spawn(), mdb.HASH, h) + if withecho { + h = mdb.HashCreate(m.Spawn(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done)) + defer mdb.HashRemove(m.Spawn(), mdb.HASH, h) + } if target := kit.Split(name, nfs.PT, nfs.PT); !mdb.HashSelectDetail(m, target[0], func(value ice.Map) { if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, mdb.TARGET) { kit.For([]string{ice.MSG_USERROLE}, func(k string) { m.Optionv(k, m.Optionv(k)) }) kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { m.Optionv(k, m.Optionv(k)) }) - _space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{h}, target, c) + if withecho { + _space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{h}, target, c) + } else { + _space_echo(m.Set(ice.MSG_DETAIL, arg...), nil, target, c) + } } }) { m.Warn(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, ice.ErrNotFound, SPACE, name) - } else { + } else if withecho { m.Warn(!wait(), "time out") } return diff --git a/core/wiki/word.go b/core/wiki/word.go index 6dac6dee..bebcda2f 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -68,7 +68,8 @@ func init() { code.COMPLETE: {Hand: func(m *ice.Message, arg ...string) { kit.If(kit.IsIn(kit.Split(m.Option(mdb.TEXT))[0], IMAGE, VIDEO, AUDIO), func() { m.Cmdy(FEEL).CutTo(nfs.PATH, mdb.NAME) }) }}, - "favor": {Help: "收藏", Icon: "bi bi-star", Hand: func(m *ice.Message, arg ...string) { + // "favor": {Help: "收藏", Icon: "bi bi-star", Hand: func(m *ice.Message, arg ...string) { + "favor": {Help: "收藏", Hand: func(m *ice.Message, arg ...string) { m.Cmd(web.CHAT_FAVOR, mdb.CREATE, mdb.TYPE, nfs.SHY, mdb.NAME, path.Base(arg[0]), mdb.TEXT, arg[0]) m.ProcessHold("favor success") }}, diff --git a/exec.go b/exec.go index 21226b2d..c39bd641 100644 --- a/exec.go +++ b/exec.go @@ -76,6 +76,9 @@ func (m *Message) GoWait(cb func(func()), arg ...Any) *Message { return m.Go(func() { cb(func() { res <- true }) }, arg...) } func (m *Message) Wait(d string, cb ...Handler) (wait func() bool, done Handler) { + if d == "" { + return nil, nil + } sync := make(chan bool, 2) t := time.AfterFunc(kit.Duration(d), func() { sync <- false }) return func() bool { return <-sync }, func(msg *Message, arg ...string) { diff --git a/misc/git/repos.go b/misc/git/repos.go index 3614cc10..ca4f7144 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -120,14 +120,17 @@ func _repos_each(m *ice.Message, title string, cb func(*git.Repository, ice.Maps }) } func _repos_each_origin(m *ice.Message, title string, cb func(*git.Repository, string, *http.BasicAuth, ice.Maps) error) { - _repos_each(m, "", func(repos *git.Repository, value ice.Maps) error { + m.Option("repos.auth", _repos_credentials(m)) + _repos_each(m, title, func(repos *git.Repository, value ice.Maps) error { if value[ORIGIN] == "" { return nil } else if remote, err := repos.Remote(ORIGIN); err != nil { return err } else { remoteURL := _repos_remote(m, remote.Config().URLs[0]) - return cb(repos, remoteURL, _repos_auth(m, remoteURL), value) + auth := _repos_auth(m, remoteURL) + m.Info("%s: %s %s", m.ActionKey(), auth.Username, remoteURL) + return cb(repos, remoteURL, auth, value) } }) } @@ -140,13 +143,13 @@ func _repos_credentials(m *ice.Message) map[string]*url.URL { return list } func _repos_auth(m *ice.Message, origin string) *http.BasicAuth { - list := _repos_credentials(m) + list, ok := m.Optionv("repos.auth").(map[string]*url.URL) + kit.If(!ok, func() { list = _repos_credentials(m) }) if u, ok := list[kit.ParseURL(_repos_remote(m, origin)).Host]; !ok { return nil } else if password, ok := u.User.Password(); !ok { return nil } else { - m.Debug("auth %v:%v", u.User.Username(), password) return &http.BasicAuth{Username: u.User.Username(), Password: password} } } @@ -538,6 +541,7 @@ func init() { kit.If(_last > last, func() { last = _last }) } } + m.Info("%s: %s", m.ActionKey(), value[REPOS]) return _repos_status(m, value[REPOS], repos) }) remote := ice.Info.Make.Remote