From 7481bb0fb9786c23f41f13ea8db710590a637a94 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Thu, 5 Aug 2021 20:21:38 +0800 Subject: [PATCH] add pod --- base/web/route.go | 3 +-- base/web/serve.go | 27 ++++++++++++++------------ base/web/space.go | 5 ++++- core/chat/pod.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 core/chat/pod.go diff --git a/base/web/route.go b/base/web/route.go index 2231ef7c..5bde5cd3 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -34,8 +34,7 @@ func _route_travel(m *ice.Message, route string) { func _route_list(m *ice.Message) { // 链接操作 m.Table(func(index int, value map[string]string, field []string) { - m.PushAnchor(value[kit.SSH_ROUTE], kit.MergeURL(m.Option(ice.MSG_USERWEB), - cli.POD, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.SSH_ROUTE]))) + m.PushAnchor(value[kit.SSH_ROUTE], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.SSH_ROUTE]))) switch value[kit.MDB_TYPE] { case WORKER: diff --git a/base/web/serve.go b/base/web/serve.go index d94fe57d..84fd6902 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -70,6 +70,19 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { } return true } +func _serve_params(msg *ice.Message, path string) { + switch ls := strings.Split(path, "/"); kit.Select("", ls, 1) { + case "share": + msg.Logs("refer", ls[1], ls[2]) + msg.Option(ls[1], ls[2]) + case "chat": + switch kit.Select("", ls, 2) { + case "pod": + msg.Logs("refer", ls[2], ls[3]) + msg.Option(ls[2], ls[3]) + } + } +} func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) { // 环境变量 msg.Option(mdb.CACHE_LIMIT, "10") @@ -79,24 +92,14 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon msg.Option(v.Name, v.Value) } - if ls := strings.Split(r.URL.Path, "/"); len(ls) > 2 && ls[1] == "share" { - msg.Logs("refer", ls[1], ls[2]) - msg.Option(ls[1], ls[2]) - } else { - msg.Debug("%v", ls) - } // 请求变量 + _serve_params(msg, r.URL.Path) if u, e := url.Parse(r.Header.Get("Referer")); e == nil { + _serve_params(msg, u.Path) for k, v := range u.Query() { msg.Logs("refer", k, v) msg.Option(k, v) } - if ls := strings.Split(u.Path, "/"); len(ls) > 2 && ls[1] == "share" { - msg.Logs("refer", ls[1], ls[2]) - msg.Option(ls[1], ls[2]) - } else { - msg.Debug("%v", ls) - } } // 请求地址 diff --git a/base/web/space.go b/base/web/space.go index 804e49fd..bcbac949 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -16,6 +16,9 @@ import ( kit "github.com/shylinux/toolkits" ) +func _space_link(m *ice.Message, pod string, arg ...interface{}) string { + return kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/chat/pod/"+pod, arg...) +} func _space_list(m *ice.Message, space string) { if space == "" { m.Fields(0, "time,type,name,text") @@ -195,7 +198,7 @@ func _space_search(m *ice.Message, kind, name, text string, arg ...string) { default: m.PushSearch(cli.CMD, SPACE, kit.MDB_TYPE, value[kit.MDB_TYPE], kit.MDB_NAME, value[kit.MDB_NAME], - kit.MDB_TEXT, kit.MergeURL(m.Option(ice.MSG_USERWEB), cli.POD, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.MDB_NAME])), value) + kit.MDB_TEXT, _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.MDB_NAME])), value) } }) diff --git a/core/chat/pod.go b/core/chat/pod.go new file mode 100644 index 00000000..ebc471b4 --- /dev/null +++ b/core/chat/pod.go @@ -0,0 +1,48 @@ +package chat + +import ( + "path" + + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/cli" + "github.com/shylinux/icebergs/base/ctx" + "github.com/shylinux/icebergs/base/web" + kit "github.com/shylinux/toolkits" +) + +const POD = "pod" + +func init() { + Index.Merge(&ice.Context{ + Commands: map[string]*ice.Command{ + "/pod/": {Name: "/pod/", Help: "节点", Action: map[string]*ice.Action{ + ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { + if len(arg) == 0 { + m.Push("index", CMD) + m.Push("args", "") + return + } + m.Cmdy(ctx.COMMAND, arg[0]) + }}, + cli.RUN: {Name: "command", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(arg) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.RenderDownload(path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_INDEX)))) + }}, + }, + Configs: map[string]*ice.Config{ + POD: {Name: POD, Help: "节点", Value: kit.Data( + kit.MDB_PATH, "./", kit.MDB_INDEX, "page/cmd.html", kit.MDB_TEMPLATE, ` + + + + + + + +`, + )}, + }, + }) +}