diff --git a/base/aaa/user.go b/base/aaa/user.go index 6a8c61d1..26b1cb88 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -119,7 +119,6 @@ func init() { }, Commands: map[string]*ice.Command{ USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey()) UserRoot(ice.Pulse) }}, mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/ctx/command.go b/base/ctx/command.go index 8dbc209e..13ffaca9 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -80,9 +80,6 @@ const COMMAND = "command" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ COMMAND: {Name: "command key auto", Help: "命令", Action: map[string]*ice.Action{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey()) - }}, mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" { _command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2)) diff --git a/base/nfs/dir.go b/base/nfs/dir.go index bca27324..39b0a251 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -235,7 +235,6 @@ func init() { }, Commands: map[string]*ice.Command{ DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey()) m.Cmd(mdb.RENDER, mdb.CREATE, m.CommandKey(), m.PrefixKey()) }}, mdb.SEARCH: {Name: "search type name", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/broad.go b/base/web/broad.go index 48fccb94..b5479df5 100644 --- a/base/web/broad.go +++ b/base/web/broad.go @@ -56,6 +56,12 @@ func _serve_udp(m *ice.Message, host, port string) { } } } +func _broad_search(m *ice.Message, kind, name, text string, arg ...string) { + m.Richs(BROAD, nil, mdb.FOREACH, func(key string, value map[string]interface{}) { + value = kit.GetMeta(value) + m.PushSearch(mdb.TYPE, "friend", mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value) + }) +} const BROAD = "broad" @@ -70,7 +76,6 @@ func init() { kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT))) m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV)) }}, - ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf(BROAD, "", "") }}, }, mdb.HashAction( mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port", )), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/base/web/space.go b/base/web/space.go index f7b51df1..b2445146 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -258,6 +258,7 @@ func _space_fork(m *ice.Message) { const ( CHROME = "chrome" + FRIEND = "friend" MASTER = "master" MYSELF = "myself" SERVER = "server" @@ -284,11 +285,11 @@ func init() { }, Commands: map[string]*ice.Command{ SPACE: {Name: "space name cmd auto invite", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey()) m.Conf(SPACE, mdb.HASH, "") }}, mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { _space_search(m, arg[0], arg[1], kit.Select("", arg, 2)) + _broad_search(m, arg[0], arg[1], kit.Select("", arg, 2)) }}, aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) { for _, k := range []string{ice.MISC, ice.CORE, ice.BASE} { diff --git a/base/web/spide.go b/base/web/spide.go index 747f469b..fe658e4e 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -334,18 +334,15 @@ const SPIDE = "spide" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data( - mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url", - LOGHEADERS, ice.FALSE, - )}, + SPIDE: {Name: SPIDE, Help: "蜘蛛侠", Value: kit.Data(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url", LOGHEADERS, ice.FALSE)}, }, Commands: map[string]*ice.Command{ SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Action: ice.MergeAction(map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { conf := m.Confm(cli.RUNTIME, "conf") - m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://:9020", conf["ctx_ops"])) + m.Cmd(SPIDE, mdb.CREATE, ice.OPS, kit.Select("http://127.0.0.1:9020", conf["ctx_ops"])) m.Cmd(SPIDE, mdb.CREATE, ice.DEV, kit.Select("http://contexts.woa.com:80", conf["ctx_dev"])) - // m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"])) m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://shylinux.com:443", conf["ctx_shy"])) + // m.Cmd(SPIDE, mdb.CREATE, ice.SHY, kit.Select("https://contexts.com.cn:443", conf["ctx_shy"])) }}, mdb.CREATE: {Name: "create name address", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS)) diff --git a/core/chat/website.go b/core/chat/website.go index 2c379420..fb659967 100644 --- a/core/chat/website.go +++ b/core/chat/website.go @@ -178,6 +178,11 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...) return true } +func _website_search(m *ice.Message, kind, name, text string, arg ...string) { + m.Cmd(m.PrefixKey()).Table(func(index int, value map[string]string, head []string) { + m.PushSearch(value, mdb.TEXT, m.MergeURL2(path.Join("/chat/website", value[nfs.PATH]))) + }) +} const WEBSITE = "website" @@ -216,6 +221,9 @@ func init() { } }}, "inner": {Hand: func(m *ice.Message, arg ...string) {}}, + mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { + _website_search(m, arg[0], arg[1], kit.Select("", arg, 2)) + }}, mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.EchoIFrame(_website_url(m, strings.TrimPrefix(path.Join(arg[2], arg[1]), SRC_WEBSITE))) }}, diff --git a/core/code/go.go b/core/code/go.go index 50431f6a..d643bff4 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -178,7 +178,6 @@ func init() { Index.Register(&ice.Context{Name: GO, Help: "后端", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, m.Prefix(GO)) - m.Cmd(mdb.SEARCH, mdb.CREATE, GO, m.Prefix(GO)) m.Cmd(mdb.ENGINE, mdb.CREATE, GO, m.Prefix(GO)) LoadPlug(m, GO, MOD, SUM) diff --git a/core/code/inner.go b/core/code/inner.go index 4754fc9a..82f1ee0b 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -111,6 +111,7 @@ func init() { _inner_exec(m, arg[0], arg[1], arg[2]) }}, mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + return m.Option(nfs.DIR_ROOT, arg[2]) m.Option(cli.CMD_DIR, kit.Path(arg[2])) m.Cmdy(mdb.SEARCH, arg[0], arg[1], arg[2]) diff --git a/core/code/vimer.go b/core/code/vimer.go index a2c39cd2..086ef79a 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -36,6 +36,9 @@ func init() { m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT))) m.Cmdy(TEMPLATE, nfs.DEFS) }}, + mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + m.PushSearch(mdb.TYPE, "go", mdb.NAME, "src/main.go", mdb.TEXT, m.MergeURL2("/chat/cmd/web.code.vimer")) + }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch m.Option(ctx.ACTION) { case web.DREAM: diff --git a/core/wiki/word.go b/core/wiki/word.go index 5053e529..7b91030c 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -38,10 +38,8 @@ func init() { )}, }, Commands: map[string]*ice.Command{ WORD: {Name: "word path=src/main.shy@key auto play", Help: "语言文字", Meta: kit.Dict(ice.DisplayLocal("")), Action: ice.MergeAction(map[string]*ice.Action{ - ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, m.CommandKey(), m.PrefixKey()) - }}, mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + m.PushSearch(mdb.TYPE, "shy", mdb.NAME, "src/main.shy", mdb.TEXT, m.MergeURL2("/chat/cmd/web.wiki.word")) m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH).Table(func(index int, value map[string]string, head []string) { if arg[1] == "" { if value[mdb.TYPE] == SPARK { diff --git a/type.go b/type.go index a3ead4f2..626b1a49 100644 --- a/type.go +++ b/type.go @@ -14,6 +14,9 @@ import ( kit "shylinux.com/x/toolkits" ) +type CommandHandler func(m *Message, c *Context, key string, arg ...string) +type ActionHandler func(m *Message, arg ...string) + type Cache struct { Name string Help string @@ -35,7 +38,7 @@ type Command struct { Help string Action map[string]*Action Meta map[string]interface{} - Hand func(m *Message, c *Context, key string, arg ...string) + Hand CommandHandler List []interface{} } type Server interface { @@ -95,6 +98,7 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context { s.Merge(s) return s } + func (c *Context) Merge(s *Context) *Context { if c.Commands == nil { c.Commands = map[string]*Command{} @@ -129,25 +133,46 @@ func (c *Context) Merge(s *Context) *Context { cmd.List = c.split(cmd.Name) } + merge := func(pre *Command, before bool, key string, cmd *Command, cb ...CommandHandler) { + last := pre.Hand + pre.Hand = func(m *Message, c *Context, _key string, arg ...string) { + if before { + last(m, c, _key, arg...) + } + m._key, m._cmd = key, cmd + for _, cb := range cb { + if cb != nil { + cb(m, c, key, arg...) + } + } + m._key, m._cmd = _key, pre + if !before { + last(m, c, _key, arg...) + } + } + } + for k, a := range cmd.Action { - // if p, ok := c.Commands[k]; ok && s != c { if p, ok := c.Commands[k]; ok { - key := key - switch last, next := p.Hand, a.Hand; k { + switch hand := a.Hand; k { case CTX_INIT: - p.Hand = func(m *Message, c *Context, _key string, arg ...string) { - last(m, c, _key, arg...) - m._key, m._cmd = key, cmd - next(m, arg...) - m._key, m._cmd = _key, p - } + merge(p, true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) { + hand(m, arg...) + }) case CTX_EXIT: - p.Hand = func(m *Message, c *Context, _key string, arg ...string) { - m._key, m._cmd = key, cmd - next(m, arg...) - m._key, m._cmd = _key, p - last(m, c, _key, arg...) - } + merge(p, false, key, cmd, func(m *Message, c *Context, _key string, arg ...string) { + hand(m, arg...) + }) + } + } + if s != c { + switch k { + case "search": + merge(c.Commands[CTX_INIT], true, key, cmd, func(m *Message, c *Context, _key string, arg ...string) { + if m.CommandKey() != "search" { + m.Cmd("search", "create", m.CommandKey(), m.PrefixKey()) + } + }) } }