diff --git a/base/gdb/routine.go b/base/gdb/routine.go index e74629bd..5eeda582 100644 --- a/base/gdb/routine.go +++ b/base/gdb/routine.go @@ -50,7 +50,7 @@ func init() { ls[0] = strings.TrimPrefix(ls[0], "icebergs/") } - m.PushPlugin(INNER, INNER, kit.SSH_RUN) + m.ShowPlugin("", INNER, kit.SSH_RUN) m.Push("args", kit.Format([]string{"usr/icebergs/", ls[0], ls[1]})) } }}, diff --git a/base/web/route.go b/base/web/route.go index c1614fdc..75204583 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -124,7 +124,7 @@ func init() { } } else if len(arg) > 2 { // 加载插件 - m.PushPlugins(arg[0], arg[1], arg[2], ctx.COMMAND) + m.ShowPlugin(arg[0], arg[1], arg[2], ctx.COMMAND) } else if len(arg) > 1 { // 命令列表 m.Cmd(SPACE, arg[0], ctx.CONTEXT, arg[1], ctx.COMMAND).Table(func(index int, value map[string]string, head []string) { diff --git a/conf.go b/conf.go index 377f5a7b..1f189fe3 100644 --- a/conf.go +++ b/conf.go @@ -55,6 +55,7 @@ const ( // RENDER RENDER_ANCHOR = "_anchor" RENDER_BUTTON = "_button" RENDER_IMAGES = "_images" + RENDER_VIDEOS = "_videos" RENDER_QRCODE = "_qrcode" RENDER_SCRIPT = "_script" RENDER_DOWNLOAD = "_download" diff --git a/core/code/favor.go b/core/code/favor.go index 2673c7e1..d0b399e2 100644 --- a/core/code/favor.go +++ b/core/code/favor.go @@ -53,7 +53,7 @@ func init() { return } - m.PushPlugin(INNER, INNER, mdb.RENDER) + m.ShowPlugin("", INNER, mdb.RENDER) m.Push(kit.SSH_ARG, kit.Format([]string{m.Option(kit.MDB_PATH), m.Option(kit.MDB_FILE), m.Option(kit.MDB_LINE)})) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/init.go b/init.go index cdaa16a4..e710da60 100644 --- a/init.go +++ b/init.go @@ -3,10 +3,12 @@ package ice import ( kit "github.com/shylinux/toolkits" + "fmt" "io" "os" "strings" "sync" + "sync/atomic" "time" ) @@ -30,6 +32,8 @@ var Info = struct { HostName string UserName string } + + nLocalCmd int32 }{} type Frame struct{ code int } @@ -221,3 +225,8 @@ func Name(name string, value interface{}) string { names[name] = value return name } +func (m *Message) AddCmd(cmd *Command) string { + name := fmt.Sprintf("_cb_%d", atomic.AddInt32(&Info.nLocalCmd, 1)) + m.target.Commands[name] = cmd + return kit.Keys(m.target.Cap(CTX_FOLLOW), name) +} diff --git a/misc.go b/misc.go index 7833ef29..0c8b2b30 100644 --- a/misc.go +++ b/misc.go @@ -10,7 +10,6 @@ import ( "net/url" "path" "strings" - "sync/atomic" ) func (m *Message) Prefix(arg ...string) string { @@ -42,7 +41,7 @@ func (m *Message) Watch(key string, arg ...string) *Message { if len(arg) == 0 { arg = append(arg, m.Prefix("auto")) } - m.Cmd("gdb.event", "action", "listen", "event", key, "cmd", strings.Join(arg, " ")) + m.Cmd("gdb.event", "action", "listen", "event", key, kit.SSH_CMD, strings.Join(arg, " ")) return m } func (m *Message) Event(key string, arg ...string) *Message { @@ -61,29 +60,21 @@ func (m *Message) Space(arg interface{}) []string { return []string{"web.space", kit.Format(arg)} } -func (m *Message) PushPlugins(pod, ctx, cmd string, arg ...string) { - m.Cmdy("space", pod, "context", ctx, "command", cmd) +func (m *Message) ShowPlugin(pod, ctx, cmd string, arg ...string) { + m.Cmdy("web.space", pod, "context", ctx, "command", cmd) m.Option(MSG_PROCESS, PROCESS_FIELD) m.Option(FIELD_PREFIX, arg) } -func (m *Message) PushPlugin(key string, arg ...string) { - m.Cmdy("command", key) - m.Option(MSG_PROCESS, PROCESS_FIELD) - m.Option(FIELD_PREFIX, arg) -} -func (m *Message) PushRender(key, view, name string, arg ...string) *Message { - return m.Push(key, _render(m, view, name, arg)) -} func (m *Message) PushPodCmd(cmd string, arg ...string) { m.Table(func(index int, value map[string]string, head []string) { - m.Push("pod", m.Option(MSG_USERPOD)) + m.Push(kit.SSH_POD, m.Option(MSG_USERPOD)) }) m.Cmd("web.space").Table(func(index int, value map[string]string, head []string) { - switch value["type"] { + switch value[kit.MDB_TYPE] { case "worker", "server": - m.Cmd("web.space", value["name"], m.Prefix(cmd), arg).Table(func(index int, val map[string]string, head []string) { - val["pod"] = kit.Keys(value["name"], val["pod"]) + m.Cmd("web.space", value[kit.MDB_NAME], m.Prefix(cmd), arg).Table(func(index int, val map[string]string, head []string) { + val[kit.SSH_POD] = kit.Keys(value[kit.MDB_NAME], val[kit.SSH_POD]) m.Push("", val, head) }) } @@ -109,12 +100,12 @@ func (m *Message) PushSearch(args ...interface{}) { func (m *Message) PushSearchWeb(cmd string, name string) { msg := m.Spawn() msg.Option("fields", "type,name,text") - msg.Cmd("mdb.select", m.Prefix(cmd), "", "hash").Table(func(index int, value map[string]string, head []string) { - text := kit.MergeURL(value["text"], value["name"], name) - if value["name"] == "" { - text = kit.MergeURL(value["text"] + url.QueryEscape(name)) + msg.Cmd("mdb.select", m.Prefix(cmd), "", kit.MDB_HASH).Table(func(index int, value map[string]string, head []string) { + text := kit.MergeURL(value[kit.MDB_TEXT], value[kit.MDB_NAME], name) + if value[kit.MDB_NAME] == "" { + text = kit.MergeURL(value[kit.MDB_TEXT] + url.QueryEscape(name)) } - m.PushSearch("cmd", cmd, "type", kit.Select("", value["type"]), "name", name, "text", text) + m.PushSearch(kit.SSH_CMD, cmd, kit.MDB_TYPE, kit.Select("", value[kit.MDB_TYPE]), kit.MDB_NAME, name, kit.MDB_TEXT, text) }) } @@ -124,11 +115,11 @@ func _render(m *Message, cmd string, args ...interface{}) string { } switch arg := kit.Simple(args...); cmd { - case RENDER_DOWNLOAD: // [name] link + case RENDER_DOWNLOAD: // [name] file if len(arg) == 1 { - arg[0] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[0]), "pod", m.Option(MSG_USERPOD)) + arg[0] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[0]), kit.SSH_POD, m.Option(MSG_USERPOD)) } else { - arg[1] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[1]), "pod", m.Option(MSG_USERPOD)) + arg[1] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[1]), kit.SSH_POD, m.Option(MSG_USERPOD)) } return fmt.Sprintf(`%s`, kit.Select(arg[0], arg, 1), path.Base(arg[0]), arg[0]) @@ -143,10 +134,13 @@ func _render(m *Message, cmd string, args ...interface{}) string { } return strings.Join(list, "") - case RENDER_IMAGES: // src size + case RENDER_IMAGES: // src [size] return fmt.Sprintf(``, arg[0], kit.Select("120", arg, 1)) - case RENDER_QRCODE: // text size height + case RENDER_VIDEOS: // src [size] + return fmt.Sprintf(`