From 3148969e642d64e4b64f0006c92a19d8920bdc8b Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 13 Sep 2021 10:18:30 +0800 Subject: [PATCH] opt ctx.CmdAction --- base/ctx/ctx.go | 26 ++++++++++++++++++++++++++ base/mdb/hash.go | 11 ----------- base/nfs/dir.go | 10 ++++++++++ base/web/share.go | 2 +- base/web/space.go | 11 +++++++---- core/chat/div.go | 3 ++- core/chat/search.go | 10 ++-------- core/wiki/word.go | 5 ++--- exec.go | 4 ++++ 9 files changed, 54 insertions(+), 28 deletions(-) diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index 4e1ace00..48708d0a 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -5,6 +5,32 @@ import ( "shylinux.com/x/icebergs/base/mdb" ) +func selectAction(list map[string]*ice.Action, fields ...string) map[string]*ice.Action { + if len(fields) == 0 { + return list + } + + res := map[string]*ice.Action{} + for _, field := range fields { + res[field] = list[field] + } + return res +} +func CmdAction(fields ...string) map[string]*ice.Action { + return selectAction(map[string]*ice.Action{ + "command": {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { + if !m.PodCmd("command", arg) { + m.Cmdy("command", arg) + } + }}, + "run": {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + if !m.PodCmd(arg) { + m.Cmdy(arg) + } + }}, + }, fields...) +} + const CTX = "ctx" var Index = &ice.Context{Name: CTX, Help: "标准模块", Commands: map[string]*ice.Command{ diff --git a/base/mdb/hash.go b/base/mdb/hash.go index 6df9ff83..50fd8d96 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -154,17 +154,6 @@ func selectAction(list map[string]*ice.Action, fields ...string) map[string]*ice } return res } -func CmdAction(fields ...string) map[string]*ice.Action { - return selectAction(map[string]*ice.Action{ - "command": {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy("command", arg) - }}, - "run": {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg) - }}, - }, fields...) -} - func HashAction(fields ...string) map[string]*ice.Action { return selectAction(map[string]*ice.Action{ CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 29257f90..02c50cd2 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -129,6 +129,16 @@ func _dir_show(m *ice.Message, root string, name string, level int, deep bool, d } else { m.Push(field, "") } + case "show": + p := kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/local/"+path.Join(name, f.Name()), "pod", m.Option(ice.MSG_USERPOD)) + switch kit.Ext(f.Name()) { + case "jpg": + m.PushImages(field, p) + case "mp4": + m.PushVideos(field, p) + default: + m.Push(field, "") + } default: m.Push(field, "") } diff --git a/base/web/share.go b/base/web/share.go index 558cb6d7..9f776986 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -57,7 +57,7 @@ func _share_local(m *ice.Message, arg ...string) { } // 上传文件 - m.Cmdy(SPACE, m.Option(cli.POD), SPIDE, SPIDE_DEV, SPIDE_RAW, _share_link(m, "/share/proxy/"), + m.Cmdy(SPACE, m.Option(cli.POD), SPIDE, SPIDE_DEV, SPIDE_RAW, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"), SPIDE_PART, m.OptionSimple(cli.POD), kit.MDB_PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p) if s, e := os.Stat(pp); e == nil && !s.IsDir() { diff --git a/base/web/space.go b/base/web/space.go index a91070fc..8a6c7807 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -281,10 +281,13 @@ func init() { switch kind { case CHROME: // 交互节点 - m.Go(func(msg *ice.Message) { - link := kit.MergeURL(_space_domain(msg), "grant", name) - msg.Sleep("100ms").Cmd(SPACE, name, "pwd", name, link, msg.Cmdx(cli.QRCODE, link)) - }) + switch m.Option("cmd") { + case "pwd": + m.Go(func(msg *ice.Message) { + link := kit.MergeURL(_space_domain(msg), "grant", name) + msg.Sleep("100ms").Cmd(SPACE, name, "pwd", name, link, msg.Cmdx(cli.QRCODE, link)) + }) + } case WORKER: // 工作节点 m.Event(DREAM_START, args...) defer m.Event(DREAM_STOP, args...) diff --git a/core/chat/div.go b/core/chat/div.go index e239c128..399e153a 100644 --- a/core/chat/div.go +++ b/core/chat/div.go @@ -5,6 +5,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" @@ -64,7 +65,7 @@ func init() { m.ProcessDisplay("/plugin/local/chat/div.js") m.Push("text", kit.Formats(node)) }}, - }, mdb.HashAction(), mdb.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }, mdb.HashAction(), ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Fields(len(arg), m.Conf(DIV, kit.META_FIELD)) m.Cmdy(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, kit.MDB_HASH, arg) m.Table(func(index int, value map[string]string, head []string) { diff --git a/core/chat/search.go b/core/chat/search.go index 71c8e898..5ea5951a 100644 --- a/core/chat/search.go +++ b/core/chat/search.go @@ -19,7 +19,7 @@ func init() { ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmd(mdb.SEARCH, mdb.CREATE, P_SEARCH, m.Prefix(P_SEARCH)) }}, - P_SEARCH: {Name: P_SEARCH, Help: "搜索引擎", Action: map[string]*ice.Action{ + P_SEARCH: {Name: P_SEARCH, Help: "搜索引擎", Action: ice.MergeAction(map[string]*ice.Action{ mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { m.Richs(P_SEARCH, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) { if value = kit.GetMeta(value); arg[1] != "" && !kit.Contains(value[kit.MDB_NAME], arg[1]) { @@ -31,13 +31,7 @@ func init() { mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(m.Space(m.Option(cli.POD)), mdb.RENDER, arg[1:]) }}, - ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(ctx.COMMAND, arg) - }}, - cli.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(arg) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if kit.Contains(arg[1], ";") { arg = kit.Split(arg[1], ";", ";", ";") } diff --git a/core/wiki/word.go b/core/wiki/word.go index 89b230df..b0d5b368 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -7,7 +7,6 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/ssh" "shylinux.com/x/icebergs/base/web" @@ -70,7 +69,7 @@ func init() { web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], ctx.ACTION, cli.RUN, arg[2:]) }}, - }, mdb.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Option(nfs.DIR_REG, m.Conf(WORD, kit.Keym(kit.MDB_REGEXP))) if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) { _word_show(m, arg[0]) @@ -88,7 +87,7 @@ func init() { m.Push("args", ls[1]) } }}, - }, mdb.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if m.R.Method == http.MethodGet { m.RenderIndex(web.SERVE, ice.VOLCANOS, "page/cmd.html") return // 目录 diff --git a/exec.go b/exec.go index bf070c5e..b08014a8 100644 --- a/exec.go +++ b/exec.go @@ -156,6 +156,10 @@ func (m *Message) Space(arg interface{}) []string { func (m *Message) PodCmd(arg ...interface{}) bool { if pod := m.Option("pod"); pod != "" { m.Option("pod", "") + if m.Option("_upload") != "" { + msg := m.Cmd("cache", "upload") + m.Option(MSG_UPLOAD, msg.Append(kit.MDB_HASH), msg.Append(kit.MDB_NAME), msg.Append(kit.MDB_SIZE)) + } m.Cmdy(append([]interface{}{"space", pod}, arg...)) return true }