mirror of
https://shylinux.com/x/icebergs
synced 2025-04-27 01:48:27 +08:00
opt ctx.CmdAction
This commit is contained in:
parent
b45f3e11b5
commit
3148969e64
@ -5,6 +5,32 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/mdb"
|
"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"
|
const CTX = "ctx"
|
||||||
|
|
||||||
var Index = &ice.Context{Name: CTX, Help: "标准模块", Commands: map[string]*ice.Command{
|
var Index = &ice.Context{Name: CTX, Help: "标准模块", Commands: map[string]*ice.Command{
|
||||||
|
@ -154,17 +154,6 @@ func selectAction(list map[string]*ice.Action, fields ...string) map[string]*ice
|
|||||||
}
|
}
|
||||||
return res
|
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 {
|
func HashAction(fields ...string) map[string]*ice.Action {
|
||||||
return selectAction(map[string]*ice.Action{
|
return selectAction(map[string]*ice.Action{
|
||||||
CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
@ -129,6 +129,16 @@ func _dir_show(m *ice.Message, root string, name string, level int, deep bool, d
|
|||||||
} else {
|
} else {
|
||||||
m.Push(field, "")
|
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:
|
default:
|
||||||
m.Push(field, "")
|
m.Push(field, "")
|
||||||
}
|
}
|
||||||
|
@ -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)
|
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() {
|
if s, e := os.Stat(pp); e == nil && !s.IsDir() {
|
||||||
|
@ -281,10 +281,13 @@ func init() {
|
|||||||
|
|
||||||
switch kind {
|
switch kind {
|
||||||
case CHROME: // 交互节点
|
case CHROME: // 交互节点
|
||||||
|
switch m.Option("cmd") {
|
||||||
|
case "pwd":
|
||||||
m.Go(func(msg *ice.Message) {
|
m.Go(func(msg *ice.Message) {
|
||||||
link := kit.MergeURL(_space_domain(msg), "grant", name)
|
link := kit.MergeURL(_space_domain(msg), "grant", name)
|
||||||
msg.Sleep("100ms").Cmd(SPACE, name, "pwd", name, link, msg.Cmdx(cli.QRCODE, link))
|
msg.Sleep("100ms").Cmd(SPACE, name, "pwd", name, link, msg.Cmdx(cli.QRCODE, link))
|
||||||
})
|
})
|
||||||
|
}
|
||||||
case WORKER: // 工作节点
|
case WORKER: // 工作节点
|
||||||
m.Event(DREAM_START, args...)
|
m.Event(DREAM_START, args...)
|
||||||
defer m.Event(DREAM_STOP, args...)
|
defer m.Event(DREAM_STOP, args...)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/web"
|
"shylinux.com/x/icebergs/base/web"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
@ -64,7 +65,7 @@ func init() {
|
|||||||
m.ProcessDisplay("/plugin/local/chat/div.js")
|
m.ProcessDisplay("/plugin/local/chat/div.js")
|
||||||
m.Push("text", kit.Formats(node))
|
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.Fields(len(arg), m.Conf(DIV, kit.META_FIELD))
|
||||||
m.Cmdy(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, kit.MDB_HASH, arg)
|
m.Cmdy(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, kit.MDB_HASH, arg)
|
||||||
m.Table(func(index int, value map[string]string, head []string) {
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
|
@ -19,7 +19,7 @@ func init() {
|
|||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
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))
|
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) {
|
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{}) {
|
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]) {
|
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) {
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(m.Space(m.Option(cli.POD)), mdb.RENDER, arg[1:])
|
m.Cmdy(m.Space(m.Option(cli.POD)), mdb.RENDER, arg[1:])
|
||||||
}},
|
}},
|
||||||
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, 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) {
|
|
||||||
if kit.Contains(arg[1], ";") {
|
if kit.Contains(arg[1], ";") {
|
||||||
arg = kit.Split(arg[1], ";", ";", ";")
|
arg = kit.Split(arg[1], ";", ";", ";")
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/ssh"
|
"shylinux.com/x/icebergs/base/ssh"
|
||||||
"shylinux.com/x/icebergs/base/web"
|
"shylinux.com/x/icebergs/base/web"
|
||||||
@ -70,7 +69,7 @@ func init() {
|
|||||||
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(arg[0], ctx.ACTION, cli.RUN, arg[2:])
|
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)))
|
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...) {
|
if m.Option(nfs.DIR_DEEP, ice.TRUE); !_wiki_list(m, cmd, arg...) {
|
||||||
_word_show(m, arg[0])
|
_word_show(m, arg[0])
|
||||||
@ -88,7 +87,7 @@ func init() {
|
|||||||
m.Push("args", ls[1])
|
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 {
|
if m.R.Method == http.MethodGet {
|
||||||
m.RenderIndex(web.SERVE, ice.VOLCANOS, "page/cmd.html")
|
m.RenderIndex(web.SERVE, ice.VOLCANOS, "page/cmd.html")
|
||||||
return // 目录
|
return // 目录
|
||||||
|
4
exec.go
4
exec.go
@ -156,6 +156,10 @@ func (m *Message) Space(arg interface{}) []string {
|
|||||||
func (m *Message) PodCmd(arg ...interface{}) bool {
|
func (m *Message) PodCmd(arg ...interface{}) bool {
|
||||||
if pod := m.Option("pod"); pod != "" {
|
if pod := m.Option("pod"); pod != "" {
|
||||||
m.Option("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...))
|
m.Cmdy(append([]interface{}{"space", pod}, arg...))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user