diff --git a/base/web/route.go b/base/web/route.go
index 4e2c24f4..c1614fdc 100644
--- a/base/web/route.go
+++ b/base/web/route.go
@@ -75,14 +75,13 @@ func init() {
ROUTE: {Name: "route route ctx cmd auto invite share", Help: "路由器", Action: map[string]*ice.Action{
SHARE: {Name: "share", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
p := kit.MergeURL(m.Option(ice.MSG_USERWEB), SHARE, m.Cmdx(SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN))
+ m.EchoAnchor(p)
m.EchoScript(p)
m.EchoQRCode(p)
- m.EchoAnchor(p)
}},
aaa.INVITE: {Name: "invite", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
for _, k := range []string{"tmux", "base", "miss"} {
m.Cmdy("web.code.publish", "contexts", k)
- m.EchoScript("break")
}
m.EchoScript("shell", "# 共享环境", m.Option(ice.MSG_USERWEB))
diff --git a/base/web/serve.go b/base/web/serve.go
index 83b1c252..35c05c82 100644
--- a/base/web/serve.go
+++ b/base/web/serve.go
@@ -167,9 +167,9 @@ func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *htt
// 主机认证
}
- if _, ok := msg.Target().Commands[LOGIN]; ok {
+ if _, ok := msg.Target().Commands[WEB_LOGIN]; ok {
// 权限检查
- msg.Target().Cmd(msg, LOGIN, r.URL.Path, cmds...)
+ msg.Target().Cmd(msg, WEB_LOGIN, r.URL.Path, cmds...)
return cmds, msg.Result() != "false"
}
diff --git a/base/web/share.go b/base/web/share.go
index fc14569c..9e20299d 100644
--- a/base/web/share.go
+++ b/base/web/share.go
@@ -99,6 +99,7 @@ func init() {
if len(arg) > 0 {
m.PushAnchor(kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/"+arg[0], SHARE, arg[0]))
+ m.PushScript("shell", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/"+arg[0], SHARE, arg[0]))
m.PushQRCode("share", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/"+arg[0], SHARE, arg[0]))
}
}},
diff --git a/conf.go b/conf.go
index 248d2af5..377f5a7b 100644
--- a/conf.go
+++ b/conf.go
@@ -54,6 +54,7 @@ const ( // RENDER
RENDER_RESULT = "_result"
RENDER_ANCHOR = "_anchor"
RENDER_BUTTON = "_button"
+ RENDER_IMAGES = "_images"
RENDER_QRCODE = "_qrcode"
RENDER_SCRIPT = "_script"
RENDER_DOWNLOAD = "_download"
diff --git a/core/chat/file.go b/core/chat/file.go
index d4378c3e..4088cf06 100644
--- a/core/chat/file.go
+++ b/core/chat/file.go
@@ -27,7 +27,7 @@ func init() {
m.Option(mdb.FIELDS, kit.Select("time,hash,name", mdb.DETAIL, len(arg) > 0))
m.Cmdy(mdb.SELECT, FILES, "", mdb.HASH, "hash", arg)
m.Table(func(index int, value map[string]string, head []string) {
- m.PushRender("link", "download", value[kit.MDB_NAME], kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+value["data"]))
+ m.PushDownload(value[kit.MDB_NAME], kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+value["data"]))
})
if len(arg) == 0 {
m.SortTimeR(kit.MDB_TIME)
diff --git a/core/chat/river.go b/core/chat/river.go
index ef57ee84..72e54185 100644
--- a/core/chat/river.go
+++ b/core/chat/river.go
@@ -130,8 +130,8 @@ func init() {
m.Option(mdb.FIELDS, "time,type,name,share")
m.Cmdy(mdb.SELECT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), NODE), mdb.HASH)
m.Table(func(index int, value map[string]string, head []string) {
- m.PushRender(kit.MDB_LINK, "a", value[kit.MDB_NAME],
- kit.MergeURL(m.Option(ice.MSG_USERWEB), kit.SSH_POD, kit.Keys(m.Option(kit.SSH_POD), value[kit.MDB_NAME])))
+ m.PushAnchor(value[kit.MDB_NAME], kit.MergeURL(m.Option(ice.MSG_USERWEB),
+ kit.SSH_POD, kit.Keys(m.Option(kit.SSH_POD), value[kit.MDB_NAME])))
})
m.PushAction(mdb.REMOVE)
return
@@ -255,7 +255,7 @@ func init() {
m.Richs(USER, nil, value[aaa.USERNAME], func(key string, val map[string]interface{}) {
val = kit.GetMeta(val)
m.Push(aaa.USERNICK, val[aaa.USERNICK])
- m.PushRender(aaa.AVATAR, "img", kit.Format(val[aaa.AVATAR]), kit.Select("60", "240", m.Option(mdb.FIELDS) == mdb.DETAIL))
+ m.PushImages(aaa.AVATAR, kit.Format(val[aaa.AVATAR]), kit.Select("60", "240", m.Option(mdb.FIELDS) == mdb.DETAIL))
})
})
diff --git a/core/code/compile.go b/core/code/compile.go
index e97299a8..72fbcf6d 100644
--- a/core/code/compile.go
+++ b/core/code/compile.go
@@ -70,7 +70,7 @@ func init() {
} else {
m.Log_EXPORT("source", main, "target", file)
m.Push(kit.MDB_TIME, m.Time())
- m.PushRender(kit.MDB_LINK, "download", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/publish/"+path.Base(file)))
+ m.PushDownload(kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/publish/"+path.Base(file)))
m.Echo(file)
}
}},
diff --git a/core/wiki/word.go b/core/wiki/word.go
index 2c49679c..0a86927f 100644
--- a/core/wiki/word.go
+++ b/core/wiki/word.go
@@ -98,10 +98,9 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
m.Echo(`
`, name)
for _, l := range strings.Split(text, "\n") {
m.Echo("
")
+ m.Echo("").Echo("").Echo(l).Echo("")
m.Echo("
")
}
m.Echo("
")
diff --git a/misc.go b/misc.go
index b6b9d431..7833ef29 100644
--- a/misc.go
+++ b/misc.go
@@ -72,13 +72,165 @@ func (m *Message) PushPlugin(key string, arg ...string) {
m.Option(FIELD_PREFIX, arg)
}
func (m *Message) PushRender(key, view, name string, arg ...string) *Message {
- if m.Option(MSG_USERUA) == "" {
- return m
+ 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.Cmd("web.space").Table(func(index int, value map[string]string, head []string) {
+ switch value["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.Push("", val, head)
+ })
+ }
+ })
+}
+func (m *Message) PushSearch(args ...interface{}) {
+ data := kit.Dict(args...)
+ for _, k := range kit.Split(m.Option("fields")) {
+ switch k {
+ case kit.SSH_POD:
+ m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[kit.SSH_POD]))
+ case kit.SSH_CTX:
+ m.Push(k, m.Prefix())
+ case kit.SSH_CMD:
+ m.Push(k, data[kit.SSH_CMD])
+ case kit.MDB_TIME:
+ m.Push(k, kit.Select(m.Time(), data[k]))
+ default:
+ m.Push(k, kit.Select("", data[k]))
+ }
}
- if strings.Contains(m.Option(MSG_USERUA), "curl") {
- return m
+}
+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))
+ }
+ m.PushSearch("cmd", cmd, "type", kit.Select("", value["type"]), "name", name, "text", text)
+ })
+}
+
+func _render(m *Message, cmd string, args ...interface{}) string {
+ if m.Option(MSG_USERUA) == "" || strings.Contains(m.Option(MSG_USERUA), "curl") {
+ return ""
}
+ switch arg := kit.Simple(args...); cmd {
+ case RENDER_DOWNLOAD: // [name] link
+ if len(arg) == 1 {
+ arg[0] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[0]), "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))
+ }
+ return fmt.Sprintf(`%s`, kit.Select(arg[0], arg, 1), path.Base(arg[0]), arg[0])
+
+ case RENDER_ANCHOR: // [name] link
+ return fmt.Sprintf(`%s`, kit.Select(arg[0], arg, 1), arg[0])
+
+ case RENDER_BUTTON: // name...
+ list := []string{}
+ for _, k := range kit.Split(strings.Join(arg, ",")) {
+ list = append(list, fmt.Sprintf(``,
+ k, kit.Select(k, kit.Value(m.cmd.Meta, kit.Keys("trans", k)))))
+ }
+ return strings.Join(list, "")
+
+ case RENDER_IMAGES: // src size
+ return fmt.Sprintf(`
`, arg[0], kit.Select("120", arg, 1))
+
+ case RENDER_QRCODE: // text size height
+ buf := bytes.NewBuffer(make([]byte, 0, MOD_BUFS))
+ if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
+ m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
+ }
+ src := "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
+ return fmt.Sprintf(`
`, src, arg[0], kit.Select("240", arg, 1))
+
+ case RENDER_SCRIPT: // type text
+ if arg[1] == "break" {
+ return "
"
+ }
+ list := []string{}
+ list = append(list, kit.Format(``, arg[0]))
+ for _, l := range strings.Split(arg[1], "\n") {
+ list = append(list, "
")
+ switch arg[0] {
+ case "shell":
+ list = append(list, "")
+ default:
+ list = append(list, "")
+ }
+ list = append(list, "")
+ list = append(list, l)
+ list = append(list, "")
+ list = append(list, "
")
+ }
+ list = append(list, "
")
+ return strings.Join(list, "")
+ }
+ return ""
+}
+func (m *Message) PushDownload(arg ...interface{}) { // [name] link
+ m.Push("link", _render(m, RENDER_DOWNLOAD, arg...))
+}
+func (m *Message) PushAnchor(arg ...interface{}) { // [name] link
+ m.Push("link", _render(m, RENDER_ANCHOR, arg...))
+}
+func (m *Message) PushButton(arg ...string) {
+ m.Push("action", _render(m, RENDER_BUTTON, strings.Join(arg, ",")))
+}
+func (m *Message) PushScript(text string, arg ...string) *Message {
+ mime := "shell"
+ if len(arg) > 0 {
+ mime, text = text, strings.Join(arg, "\n")
+ }
+ return m.Push("script", _render(m, RENDER_SCRIPT, mime, text))
+}
+func (m *Message) PushImages(key, src string, arg ...string) { // src [size]
+ m.Push(key, _render(m, RENDER_IMAGES, src, arg))
+}
+func (m *Message) PushQRCode(key string, text string, arg ...string) { // text [size]
+ m.Push(key, _render(m, RENDER_QRCODE, text, arg))
+}
+func (m *Message) PushAction(list ...interface{}) {
+ m.Table(func(index int, value map[string]string, head []string) {
+ m.PushButton(kit.Simple(list...)...)
+ })
+}
+
+func (m *Message) EchoAnchor(arg ...interface{}) *Message { // [name] link
+ return m.Echo(_render(m, RENDER_ANCHOR, arg...))
+}
+func (m *Message) EchoButton(arg ...string) *Message {
+ return m.Echo(_render(m, RENDER_BUTTON, strings.Join(arg, ",")))
+}
+func (m *Message) EchoScript(text string, arg ...string) *Message {
+ mime := "shell"
+ if len(arg) > 0 {
+ mime, text = text, strings.Join(arg, "\n")
+ }
+ return m.Echo(_render(m, RENDER_SCRIPT, mime, text))
+}
+func (m *Message) EchoQRCode(text string, arg ...string) *Message { // text [size]
+ return m.Echo(_render(m, RENDER_QRCODE, text, arg))
+}
+
+func (m *Message) SortStr(key string) { m.Sort(key, "str") }
+func (m *Message) SortStrR(key string) { m.Sort(key, "str_r") }
+func (m *Message) SortInt(key string) { m.Sort(key, "int") }
+func (m *Message) SortIntR(key string) { m.Sort(key, "int_r") }
+func (m *Message) SortTime(key string) { m.Sort(key, "time") }
+func (m *Message) SortTimeR(key string) { m.Sort(key, "time_r") }
+
+func (m *Message) PushRenderOld(key, view, name string, arg ...string) *Message {
switch view {
case "button":
list := []string{}
@@ -100,151 +252,6 @@ func (m *Message) PushRender(key, view, name string, arg ...string) *Message {
}
return m
}
-func (m *Message) PushDownload(name string, arg ...string) { // name [file]
- if len(arg) == 0 {
- name = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", name), "pod", m.Option(MSG_USERPOD))
- } else {
- arg[0] = kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/local", arg[0]), "pod", m.Option(MSG_USERPOD))
- }
- m.PushRender("link", "download", name, arg...)
-}
-func (m *Message) PushSearch(args ...interface{}) {
- data := kit.Dict(args...)
- for _, k := range kit.Split(m.Option("fields")) {
- switch k {
- case kit.SSH_POD:
- m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[kit.SSH_POD]))
- case kit.SSH_CTX:
- m.Push(k, m.Prefix())
- case kit.SSH_CMD:
- m.Push(k, data[kit.SSH_CMD])
- case kit.MDB_TIME:
- m.Push(k, m.Time())
- case kit.MDB_SIZE:
- m.Push(k, "")
- case kit.MDB_TYPE:
- m.Push(k, data[kit.MDB_TYPE])
- case kit.MDB_NAME:
- m.Push(k, data[kit.MDB_NAME])
- case kit.MDB_TEXT:
- m.Push(k, data[kit.MDB_TEXT])
- default:
- m.Push(k, data[k])
- }
- }
-}
-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))
- }
- m.PushSearch("cmd", cmd, "type", kit.Select("", value["type"]), "name", name, "text", text)
- })
-}
-func (m *Message) PushAction(list ...interface{}) {
- m.Table(func(index int, value map[string]string, head []string) {
- m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))
- })
-}
-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.Cmd("web.space").Table(func(index int, value map[string]string, head []string) {
- switch value["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.Push("", val, head)
- })
- }
- })
-}
-
-func (m *Message) SortStr(key string) { m.Sort(key, "str") }
-func (m *Message) SortStrR(key string) { m.Sort(key, "str_r") }
-func (m *Message) SortInt(key string) { m.Sort(key, "int") }
-func (m *Message) SortIntR(key string) { m.Sort(key, "int_r") }
-func (m *Message) SortTime(key string) { m.Sort(key, "time") }
-func (m *Message) SortTimeR(key string) { m.Sort(key, "time_r") }
-
-func _render(m *Message, cmd string, args ...interface{}) string {
- switch arg := kit.Simple(args...); cmd {
- case RENDER_ANCHOR: // [name] link
- return fmt.Sprintf(`%s`, kit.Select(arg[0], arg, 1), arg[0])
-
- case RENDER_BUTTON: // name...
- list := []string{}
- for _, k := range kit.Split(strings.Join(arg, ",")) {
- list = append(list, fmt.Sprintf(``,
- k, kit.Select(k, kit.Value(m.cmd.Meta, kit.Keys("trans", k)))))
- }
- return strings.Join(list, "")
-
- case RENDER_QRCODE: // text size height
- buf := bytes.NewBuffer(make([]byte, 0, MOD_BUFS))
- if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
- m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
- }
- arg[0] = "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
- return fmt.Sprintf(`
`, arg[0], kit.Select("240", arg, 1))
-
- case RENDER_SCRIPT: // type text
- list := []string{}
- list = append(list, kit.Format(``, arg[0]))
- for _, l := range strings.Split(arg[1], "\n") {
- list = append(list, "
")
- switch arg[0] {
- case "shell":
- list = append(list, "")
- default:
- list = append(list, "")
- }
- list = append(list, "")
- list = append(list, l)
- list = append(list, "")
- list = append(list, "
")
- }
- list = append(list, "
")
- return strings.Join(list, "")
-
- case RENDER_DOWNLOAD: // file [link]
- return fmt.Sprintf(`%s`, kit.Select(arg[0], arg, 1), path.Base(arg[0]), arg[0])
- }
- return ""
-}
-func (m *Message) PushAnchor(arg ...interface{}) { // [name] link
- m.Push("link", _render(m, RENDER_ANCHOR, arg...))
-}
-func (m *Message) PushButton(arg ...string) {
- m.Push("action", _render(m, RENDER_BUTTON, strings.Join(arg, ",")))
-}
-func (m *Message) PushQRCode(key string, text string, arg ...string) { // text [size]
- m.Push(key, _render(m, RENDER_QRCODE, text, arg))
-}
-func (m *Message) EchoAnchor(arg ...interface{}) *Message { // [name] link
- return m.Echo(_render(m, RENDER_ANCHOR, arg...))
-}
-func (m *Message) EchoButton(arg ...string) *Message {
- return m.Echo(_render(m, RENDER_BUTTON, strings.Join(arg, ",")))
-}
-func (m *Message) EchoQRCode(text string, arg ...string) *Message { // text [size]
- return m.Echo(_render(m, RENDER_QRCODE, text, arg))
-}
-func (m *Message) EchoScript(text string, arg ...string) *Message {
- if text == "break" {
- return m.Echo("
")
- }
- mime := "shell"
- if len(arg) > 0 {
- mime, text = text, strings.Join(arg, "\n")
- }
- return m.Echo(_render(m, RENDER_SCRIPT, mime, text))
-}
var count = int32(0)
diff --git a/misc/chrome/spide.go b/misc/chrome/spide.go
index 32162890..79c88b80 100644
--- a/misc/chrome/spide.go
+++ b/misc/chrome/spide.go
@@ -30,7 +30,7 @@ func init() {
m.Push(kit.MDB_TYPE, value[kit.MDB_TYPE])
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
m.PushButton("download")
- m.PushRender(kit.MDB_TEXT, value[kit.MDB_TYPE], value[kit.MDB_LINK])
+ m.PushRenderOld(kit.MDB_TEXT, value[kit.MDB_TYPE], value[kit.MDB_LINK])
m.Push(kit.MDB_LINK, value[kit.MDB_LINK])
})
break
diff --git a/misc/lark/lark.go b/misc/lark/lark.go
index 2a9f604c..cdf89d73 100644
--- a/misc/lark/lark.go
+++ b/misc/lark/lark.go
@@ -137,7 +137,7 @@ var Index = &ice.Context{Name: LARK, Help: "机器人",
kit.Fetch(kit.Value(msg.Optionv("content_data"), "data.user_list"), func(index int, value map[string]interface{}) {
msg := m.Cmd(EMPLOYEE, value[OPEN_ID])
- m.PushRender(aaa.AVATAR, "img", msg.Append("avatar_72"))
+ m.PushImages(aaa.AVATAR, msg.Append("avatar_72"))
m.Push(aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1"))
m.Push(kit.MDB_NAME, msg.Append(kit.MDB_NAME))
m.Push(kit.MDB_TEXT, msg.Append("description"))
@@ -193,7 +193,7 @@ var Index = &ice.Context{Name: LARK, Help: "机器人",
msg := _lark_get(m, "bot", "/open-apis/chat/v4/info", "chat_id", m.Option(CHAT_ID))
kit.Fetch(kit.Value(msg.Optionv("content_data"), "data.members"), func(index int, value map[string]interface{}) {
msg := m.Cmd(EMPLOYEE, value[OPEN_ID])
- m.PushRender(aaa.AVATAR, "img", msg.Append("avatar_72"))
+ m.PushImages(aaa.AVATAR, msg.Append("avatar_72"))
m.Push(aaa.GENDER, kit.Select("女", "男", msg.Append(aaa.GENDER) == "1"))
m.Push(kit.MDB_NAME, msg.Append(kit.MDB_NAME))
m.Push(kit.MDB_TEXT, msg.Append("description"))
@@ -205,7 +205,7 @@ var Index = &ice.Context{Name: LARK, Help: "机器人",
msg := _lark_get(m, "bot", "/open-apis/chat/v4/list")
kit.Fetch(kit.Value(msg.Optionv("content_data"), "data.groups"), func(index int, value map[string]interface{}) {
m.Push(CHAT_ID, value[CHAT_ID])
- m.PushRender(aaa.AVATAR, "img", kit.Format(value[aaa.AVATAR]), "72")
+ m.PushImages(aaa.AVATAR, kit.Format(value[aaa.AVATAR]), "72")
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
m.Push(kit.MDB_TEXT, value["description"])
m.Push(OPEN_ID, value["owner_open_id"])
@@ -390,7 +390,8 @@ var Index = &ice.Context{Name: LARK, Help: "机器人",
m.Echo(list[rand.Intn(len(list))])
}},
- web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
+ web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ }},
"/msg": {Name: "/msg", Help: "聊天消息", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
data := m.Optionv(ice.MSG_USERDATA)
if kit.Value(data, "action") != nil {