diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go index 6d819147..90dd11fe 100644 --- a/base/nfs/nfs.go +++ b/base/nfs/nfs.go @@ -136,6 +136,33 @@ func dir(m *ice.Message, root string, name string, level int, deep bool, dir_typ } } } +func travel(m *ice.Message, root string, name string, cb func(name string)) { + if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil { + cb(name) + } else { + for _, f := range fs { + if f.Name() == "." || f.Name() == ".." { + continue + } + if strings.HasPrefix(f.Name(), ".") { + continue + } + + p := path.Join(root, name, f.Name()) + if f, e = os.Lstat(p); e != nil { + m.Log("info", "%s", e) + continue + } else if (f.Mode()&os.ModeSymlink) != 0 && f.IsDir() { + continue + } + if f.IsDir() { + travel(m, root, path.Join(name, f.Name()), cb) + } else { + cb(path.Join(name, f.Name())) + } + } + } +} var Index = &ice.Context{Name: "nfs", Help: "存储模块", Caches: map[string]*ice.Cache{}, @@ -143,6 +170,22 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块", "trash": {Name: "trash", Help: "trash", Value: kit.Data("path", "var/trash")}, }, Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmd(ice.APP_SEARCH, "add", "dir", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + travel(m, "./", "", func(name string) { + if strings.Contains(name, arg[0]) { + m.Push("pod", m.Option(ice.MSG_USERPOD)) + m.Push("engine", "dir") + m.Push("favor", "./") + m.Push("id", "") + m.Push("type", "file") + m.Push("name", path.Base(name)) + m.Push("text", name) + } + }) + }})) + }}, + "dir": {Name: "dir", Help: "目录", List: kit.List( kit.MDB_INPUT, "text", "name", "path", "action", "auto", kit.MDB_INPUT, "button", "name", "查看", diff --git a/base/web/web.go b/base/web/web.go index 07bd4697..e2cb1f47 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -515,6 +515,61 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Conf(ice.WEB_SERVE, "meta.volcanos.repos"), m.Conf(ice.WEB_SERVE, "meta.volcanos.branch")) m.Conf(ice.WEB_FAVOR, "meta.template", favor_template) m.Conf(ice.WEB_SHARE, "meta.template", share_template) + + m.Cmd(ice.APP_SEARCH, "add", "favor", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("cache.limit", -2) + wg := &sync.WaitGroup{} + m.Richs(ice.WEB_FAVOR, nil, "*", func(key string, val map[string]interface{}) { + favor := kit.Format(kit.Value(val, "meta.name")) + wg.Add(1) + m.Info("routine %v", favor) + m.Gos(m, func(m *ice.Message) { + m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { + if favor == arg[0] || value["type"] == arg[0] || + strings.Contains(kit.Format(value["name"]), arg[0]) || strings.Contains(kit.Format(value["text"]), arg[0]) { + m.Push("pod", m.Option(ice.MSG_USERPOD)) + m.Push("engine", "favor") + m.Push("favor", favor) + m.Push("", value, []string{"id", "type", "name", "text"}) + } + }) + wg.Done() + }) + }) + wg.Wait() + }})) + + m.Cmd(ice.APP_SEARCH, "add", "story", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Richs(ice.WEB_STORY, "head", "*", func(key string, val map[string]interface{}) { + if val["story"] == arg[0] { + m.Push("pod", m.Option(ice.MSG_USERPOD)) + m.Push("engine", "story") + m.Push("favor", val["story"]) + m.Push("id", val["list"]) + + m.Push("type", val["scene"]) + m.Push("name", val["story"]) + m.Push("text", val["count"]) + } + }) + }})) + + m.Cmd(ice.APP_SEARCH, "add", "share", "base", m.AddCmd(&ice.Command{Name: "search word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("cache.limit", -2) + m.Grows(ice.WEB_SHARE, nil, "", "", func(index int, value map[string]interface{}) { + if value["share"] == arg[0] || value["type"] == arg[0] || + strings.Contains(kit.Format(value["name"]), arg[0]) || strings.Contains(kit.Format(value["text"]), arg[0]) { + m.Push("pod", m.Option(ice.MSG_USERPOD)) + m.Push("engine", "share") + m.Push("favor", value["type"]) + m.Push("id", value["share"]) + + m.Push("type", value["type"]) + m.Push("name", value["name"]) + m.Push("text", value["text"]) + } + }) + }})) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(ice.WEB_SPIDE, ice.WEB_SERVE, ice.WEB_GROUP, ice.WEB_LABEL, @@ -794,7 +849,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) { m.Push(key, value, []string{"time", "type", "name", "text"}) if m.Option(ice.MSG_USERUA) != "" { - m.Push("link", fmt.Sprintf(`%s`, m.Conf(ice.WEB_SHARE, "meta.domain"), value["name"], value["name"])) + m.Push("link", fmt.Sprintf(`%s`, + kit.Select(m.Conf(ice.WEB_SHARE, "meta.domain"), m.Option(ice.MSG_USERWEB)), + kit.Keys(m.Option(ice.MSG_USERPOD), value["name"]), value["name"])) } }) m.Sort("name") @@ -1119,27 +1176,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", return }) return - - case "search": - m.Option("cache.limit", -2) - wg := &sync.WaitGroup{} - m.Richs(ice.WEB_FAVOR, nil, "*", func(key string, val map[string]interface{}) { - favor := kit.Format(kit.Value(val, "meta.name")) - wg.Add(1) - m.Info("routine %v", favor) - m.Gos(m, func(m *ice.Message) { - m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { - if strings.Contains(favor, arg[1]) || strings.Contains(kit.Format(value["name"]), arg[1]) || strings.Contains(kit.Format(value["text"]), arg[1]) { - m.Push("pod", strings.Join(kit.Simple(m.Optionv("user.pod")), ".")) - m.Push("favor", favor) - m.Push("", value, []string{"id", "type", "name", "text"}) - } - }) - wg.Done() - }) - }) - wg.Wait() - return } m.Option("favor", arg[0]) diff --git a/conf.go b/conf.go index 01d7dcb5..ff3c43d1 100644 --- a/conf.go +++ b/conf.go @@ -34,6 +34,7 @@ const ( // MSG MSG_USERUA = "user.ua" MSG_USERURL = "user.url" MSG_USERPOD = "user.pod" + MSG_USERWEB = "user.web" MSG_USERNICK = "user.nick" MSG_USERNAME = "user.name" MSG_USERROLE = "user.role" diff --git a/core/chat/chat.go b/core/chat/chat.go index 4f0fba52..7aa6d1b7 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -4,6 +4,8 @@ import ( "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/toolkits" + + "sync" ) var Index = &ice.Context{Name: "chat", Help: "聊天中心", @@ -85,12 +87,14 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", }), "fe", "volcanos", )}, + "search": {Name: "search", Help: "search", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() m.Watch(ice.SYSTEM_INIT, m.Prefix("init")) m.Watch(ice.USER_CREATE, m.Prefix("auto")) + }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("river") @@ -196,12 +200,32 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", } }}, - "search": {Name: "search label=some word=启动流程 auto", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) < 2 { - m.Cmdy(ice.WEB_LABEL, arg) - return + "search": {Name: "search label kind word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + switch arg[0] { + case "add": + if m.Richs("search", nil, arg[1], nil) == nil { + m.Rich("search", nil, kit.Data(kit.MDB_NAME, arg[1])) + } + m.Richs("search", nil, arg[1], func(key string, value map[string]interface{}) { + m.Grow("search", kit.Keys(kit.MDB_HASH, key), kit.Dict( + kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3:], + )) + }) + case "get": + wg := &sync.WaitGroup{} + m.Richs("search", nil, arg[1], func(key string, value map[string]interface{}) { + wg.Add(1) + m.Gos(m, func(m *ice.Message) { + m.Grows("search", kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { + m.Cmdy(value[kit.MDB_TEXT], arg[2:]) + }) + wg.Done() + }) + }) + wg.Wait() + default: + m.Cmdy(ice.WEB_LABEL, arg[0], arg[1], "web.chat.search", "get", arg[2:]) } - m.Cmdy(ice.WEB_LABEL, arg[0], "*", "favor", "search", arg[1:]) }}, "commend": {Name: "commend label=some word=请求响应 auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { diff --git a/type.go b/type.go index 25155ae8..9f0fa468 100644 --- a/type.go +++ b/type.go @@ -19,6 +19,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" ) @@ -56,7 +57,7 @@ type Context struct { server Server wg *sync.WaitGroup - id int + id int64 } type Server interface { Spawn(m *Message, c *Context, arg ...string) Server @@ -65,9 +66,8 @@ type Server interface { Close(m *Message, arg ...string) bool } -func (c *Context) ID() int { - c.id++ - return c.id +func (c *Context) ID() int64 { + return atomic.AddInt64(&c.id, 1) } func (c *Context) Cap(key string, arg ...interface{}) string { if len(arg) > 0 { @@ -314,7 +314,7 @@ func (m *Message) Formats(key string) string { } func (m *Message) Spawns(arg ...interface{}) *Message { msg := m.Spawn(arg...) - msg.code = m.target.root.ID() + msg.code = int(m.target.root.ID()) m.messages = append(m.messages, msg) return msg } @@ -1573,6 +1573,13 @@ func (m *Message) Show(cmd string, arg ...string) bool { return false } +var count = int32(0) + +func (m *Message) AddCmd(cmd *Command) string { + name := fmt.Sprintf("_cb_%d", atomic.AddInt32(&count, 1)) + m.target.Commands[name] = cmd + return kit.Keys(m.target.Cap(CTX_FOLLOW), name) +} func (m *Message) Cmdy(arg ...interface{}) *Message { msg := m.Cmd(arg...) m.Copy(msg)