forked from x/icebergs
add app_search
This commit is contained in:
parent
87c4f3c998
commit
2b0d1f08d7
@ -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: "存储模块",
|
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
|
||||||
Caches: map[string]*ice.Cache{},
|
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")},
|
"trash": {Name: "trash", Help: "trash", Value: kit.Data("path", "var/trash")},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
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(
|
"dir": {Name: "dir", Help: "目录", List: kit.List(
|
||||||
kit.MDB_INPUT, "text", "name", "path", "action", "auto",
|
kit.MDB_INPUT, "text", "name", "path", "action", "auto",
|
||||||
kit.MDB_INPUT, "button", "name", "查看",
|
kit.MDB_INPUT, "button", "name", "查看",
|
||||||
|
@ -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_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_FAVOR, "meta.template", favor_template)
|
||||||
m.Conf(ice.WEB_SHARE, "meta.template", share_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) {
|
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,
|
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.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
|
||||||
m.Push(key, value, []string{"time", "type", "name", "text"})
|
m.Push(key, value, []string{"time", "type", "name", "text"})
|
||||||
if m.Option(ice.MSG_USERUA) != "" {
|
if m.Option(ice.MSG_USERUA) != "" {
|
||||||
m.Push("link", fmt.Sprintf(`<a target="_blank" href="%s?pod=%s">%s</a>`, m.Conf(ice.WEB_SHARE, "meta.domain"), value["name"], value["name"]))
|
m.Push("link", fmt.Sprintf(`<a target="_blank" href="%s?pod=%s">%s</a>`,
|
||||||
|
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")
|
m.Sort("name")
|
||||||
@ -1119,27 +1176,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
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])
|
m.Option("favor", arg[0])
|
||||||
|
1
conf.go
1
conf.go
@ -34,6 +34,7 @@ const ( // MSG
|
|||||||
MSG_USERUA = "user.ua"
|
MSG_USERUA = "user.ua"
|
||||||
MSG_USERURL = "user.url"
|
MSG_USERURL = "user.url"
|
||||||
MSG_USERPOD = "user.pod"
|
MSG_USERPOD = "user.pod"
|
||||||
|
MSG_USERWEB = "user.web"
|
||||||
MSG_USERNICK = "user.nick"
|
MSG_USERNICK = "user.nick"
|
||||||
MSG_USERNAME = "user.name"
|
MSG_USERNAME = "user.name"
|
||||||
MSG_USERROLE = "user.role"
|
MSG_USERROLE = "user.role"
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"github.com/shylinux/icebergs"
|
"github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
|
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||||
@ -85,12 +87,14 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
}),
|
}),
|
||||||
"fe", "volcanos",
|
"fe", "volcanos",
|
||||||
)},
|
)},
|
||||||
|
"search": {Name: "search", Help: "search", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Load()
|
m.Load()
|
||||||
m.Watch(ice.SYSTEM_INIT, m.Prefix("init"))
|
m.Watch(ice.SYSTEM_INIT, m.Prefix("init"))
|
||||||
m.Watch(ice.USER_CREATE, m.Prefix("auto"))
|
m.Watch(ice.USER_CREATE, m.Prefix("auto"))
|
||||||
|
|
||||||
}},
|
}},
|
||||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Save("river")
|
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) {
|
"search": {Name: "search label kind word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) < 2 {
|
switch arg[0] {
|
||||||
m.Cmdy(ice.WEB_LABEL, arg)
|
case "add":
|
||||||
return
|
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) {
|
"commend": {Name: "commend label=some word=请求响应 auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) < 2 {
|
if len(arg) < 2 {
|
||||||
|
17
type.go
17
type.go
@ -19,6 +19,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ type Context struct {
|
|||||||
server Server
|
server Server
|
||||||
|
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
id int
|
id int64
|
||||||
}
|
}
|
||||||
type Server interface {
|
type Server interface {
|
||||||
Spawn(m *Message, c *Context, arg ...string) Server
|
Spawn(m *Message, c *Context, arg ...string) Server
|
||||||
@ -65,9 +66,8 @@ type Server interface {
|
|||||||
Close(m *Message, arg ...string) bool
|
Close(m *Message, arg ...string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ID() int {
|
func (c *Context) ID() int64 {
|
||||||
c.id++
|
return atomic.AddInt64(&c.id, 1)
|
||||||
return c.id
|
|
||||||
}
|
}
|
||||||
func (c *Context) Cap(key string, arg ...interface{}) string {
|
func (c *Context) Cap(key string, arg ...interface{}) string {
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
@ -314,7 +314,7 @@ func (m *Message) Formats(key string) string {
|
|||||||
}
|
}
|
||||||
func (m *Message) Spawns(arg ...interface{}) *Message {
|
func (m *Message) Spawns(arg ...interface{}) *Message {
|
||||||
msg := m.Spawn(arg...)
|
msg := m.Spawn(arg...)
|
||||||
msg.code = m.target.root.ID()
|
msg.code = int(m.target.root.ID())
|
||||||
m.messages = append(m.messages, msg)
|
m.messages = append(m.messages, msg)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
@ -1573,6 +1573,13 @@ func (m *Message) Show(cmd string, arg ...string) bool {
|
|||||||
return false
|
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 {
|
func (m *Message) Cmdy(arg ...interface{}) *Message {
|
||||||
msg := m.Cmd(arg...)
|
msg := m.Cmd(arg...)
|
||||||
m.Copy(msg)
|
m.Copy(msg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user