diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index 047501f1..51cb5274 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -94,7 +94,7 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块", chain := arg[0] if len(arg) > 1 { - chain = arg[0] + "." + arg[1] + chain = kit.Keys(arg[0], arg[1]) arg = arg[1:] } arg = arg[1:] diff --git a/base/web/share.go b/base/web/share.go index 0d3af08b..ebf4ed58 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -15,6 +15,7 @@ func init() { ice.WEB_SHARE: {Name: "share", Help: "共享链", Value: kit.Data( "index", "usr/volcanos/share.html", "template", share_template, + "expire", "72h", )}, }, Commands: map[string]*ice.Command{ @@ -77,7 +78,7 @@ func init() { // 创建共享 h := m.Rich(ice.WEB_SHARE, nil, kit.Dict( - kit.MDB_TIME, m.Time("10m"), + kit.MDB_TIME, m.Time(m.Conf(ice.WEB_SHARE, "meta.expire")), kit.MDB_TYPE, arg[0], kit.MDB_NAME, arg[1], kit.MDB_TEXT, arg[2], "extra", extra, )) @@ -128,7 +129,7 @@ func init() { m.Render(kit.Formats(value)) return case "share", "共享码": - m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/", m.Conf(ice.WEB_SHARE, "meta.domain"), key)) + m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/?share=%s", m.Conf(ice.WEB_SHARE, "meta.domain"), key, key)) return case "check", "安全码": m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict( @@ -155,7 +156,7 @@ func init() { case ice.TYPE_ACTION: if len(arg) == 1 { // 跳转主页 - m.Render("redirect", "/share/"+arg[0]+"/", "title", kit.Format(value["name"])) + m.Render("redirect", "/share", "share", arg[0], "title", kit.Format(value["name"])) break } diff --git a/base/web/web.go b/base/web/web.go index c157bccf..67529412 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -246,6 +246,7 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) { defer func() { msg.Cost("%s %v %v", r.URL.Path, msg.Optionv("cmds"), msg.Format("append")) }() if u, e := url.Parse(r.Header.Get("Referer")); e == nil { for k, v := range u.Query() { + msg.Info("%s: %v", k, v) msg.Option(k, v) } } diff --git a/core/chat/action.go b/core/chat/action.go new file mode 100644 index 00000000..699cc9f9 --- /dev/null +++ b/core/chat/action.go @@ -0,0 +1,219 @@ +package chat + +import ( + "github.com/shylinux/icebergs" + "github.com/shylinux/toolkits" +) + +func _action_share_create(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if m.Option("index") != "" { + arg = append(arg, "tool.0.pod", m.Option("node")) + arg = append(arg, "tool.0.ctx", m.Option("group")) + arg = append(arg, "tool.0.cmd", m.Option("index")) + arg = append(arg, "tool.0.args", m.Option("args")) + arg = append(arg, "tool.0.single", "yes") + } else { + m.Option(ice.MSG_RIVER, arg[5]) + m.Option(ice.MSG_STORM, arg[7]) + m.Cmd("/action", arg[5], arg[7]).Table(func(index int, value map[string]string, head []string) { + arg = append(arg, kit.Format("tool.%d.pod", index), value["node"]) + arg = append(arg, kit.Format("tool.%d.ctx", index), value["group"]) + arg = append(arg, kit.Format("tool.%d.cmd", index), value["index"]) + arg = append(arg, kit.Format("tool.%d.args", index), value["args"]) + }) + } + m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("name"), arg[2], arg[3], arg[4:]) +} +func _action_share_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) { + kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) { + m.Push("river", arg[0]) + m.Push("storm", arg[1]) + m.Push("action", index) + + m.Push("node", value["pod"]) + m.Push("group", value["ctx"]) + m.Push("index", value["cmd"]) + m.Push("args", value["args"]) + + msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, value["ctx"], value["cmd"]) + m.Push("name", value["cmd"]) + m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"]))) + m.Push("inputs", msg.Append("list")) + m.Push("feature", msg.Append("meta")) + }) + }) +} +func _action_share_update(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) { + kit.Fetch(kit.Value(value, kit.Keys("extra.tool", arg[2])), func(value map[string]interface{}) { + cmds := kit.Simple(m.Space(value["pod"]), kit.Keys(value["ctx"], value["cmd"]), arg[3:]) + m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds) + }) + }) +} + +func _action_proxy(m *ice.Message) (proxy []string) { + if m.Option("pod") != "" { + proxy = append(proxy, ice.WEB_PROXY, m.Option("pod")) + m.Option("pod", "") + } + return proxy +} +func _action_order(m *ice.Message, arg ...string) { + cmds := kit.Simple(kit.Keys(m.Option("group"), m.Option("index")), arg[3:]) + if m.Set(ice.MSG_RESULT); !m.Right(cmds) { + m.Render("status", 403, "not auth") + return + } + m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds) +} + +func _action_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := kit.Keys(kit.MDB_HASH, arg[0], "tool", kit.MDB_HASH, arg[1]) + m.Grows(ice.CHAT_RIVER, prefix, "", "", func(index int, value map[string]interface{}) { + if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok { + m.Push("river", arg[0]) + m.Push("storm", arg[1]) + m.Push("action", index) + + m.Push("node", meta["pod"]) + m.Push("group", meta["ctx"]) + m.Push("index", meta["cmd"]) + m.Push("args", kit.Select("[]", kit.Format(meta["args"]))) + + msg := m.Cmd(m.Space(meta["pod"]), ice.CTX_COMMAND, meta["ctx"], meta["cmd"]) + m.Push("name", meta["cmd"]) + m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"]))) + m.Push("feature", msg.Append("meta")) + m.Push("inputs", msg.Append("list")) + } + }) +} + +func init() { + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + "/action": {Name: "/action", Help: "工作台", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + switch arg[0] { + case "share": + _action_share_create(m, c, cmd, arg...) + return + } + if len(arg) == 0 || arg[0] == "" { + if m.Option("share") != "" { + if len(arg) < 3 { + _action_share_select(m, c, cmd, arg...) + return + } + _action_share_update(m, c, cmd, arg...) + } + return + } + + if m.Warn(m.Option(ice.MSG_RIVER) == "" || m.Option(ice.MSG_STORM) == "", "not join") { + _action_order(m, arg...) + return + } + + prefix := kit.Keys(kit.MDB_HASH, arg[0], "tool", kit.MDB_HASH, arg[1]) + if len(arg) == 2 { + if p := m.Option("pod"); p != "" { + m.Option("pod", "") + if m.Cmdy(ice.WEB_SPACE, p, "web.chat./action", arg); len(m.Appendv("river")) > 0 { + // 远程查询 + return + } + } + + // 命令列表 + _action_select(m, c, cmd, arg...) + return + } + + switch arg[2] { + case "save": + if p := m.Option("pod"); p != "" { + // 远程保存 + m.Option("pod", "") + m.Cmd(ice.WEB_SPACE, p, "web.chat./action", arg) + return + } + + // 保存应用 + m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, "list"), "") + for i := 3; i < len(arg)-4; i += 5 { + id := m.Grow(ice.CHAT_RIVER, kit.Keys(prefix), kit.Data( + "pod", arg[i], "ctx", arg[i+1], "cmd", arg[i+2], + "help", arg[i+3], "args", arg[i+4], + )) + m.Log(ice.LOG_INSERT, "storm: %s %d: %v", arg[1], id, arg[i:i+5]) + } + } + + if m.Option("_action") == "上传" { + msg := m.Cmd(ice.WEB_CACHE, "upload") + m.Option("_data", msg.Append("data")) + m.Option("_name", msg.Append("name")) + m.Cmd(ice.WEB_FAVOR, "upload", msg.Append("type"), msg.Append("name"), msg.Append("data")) + m.Option("_option", m.Optionv("option")) + } + + // 查询命令 + cmds := []string{} + m.Grows(ice.CHAT_RIVER, prefix, kit.MDB_ID, kit.Format(kit.Int(arg[2])+1), func(index int, value map[string]interface{}) { + if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok { + if len(arg) > 3 && arg[3] == "action" { + // 命令补全 + switch arg[4] { + case "input": + switch arg[5] { + case "location": + // 查询位置 + m.Copy(m.Cmd("aaa.location"), "append", "name") + return + } + + case "favor": + m.Cmdy(ice.WEB_FAVOR, arg[5:]) + return + + case "device": + // 记录位置 + m.Cmd(ice.WEB_FAVOR, kit.Select("device", m.Option("hot")), arg[5], arg[6], + kit.Select("", arg, 7), kit.KeyValue(map[string]interface{}{}, "", kit.UnMarshal(kit.Select("{}", arg, 8)))) + return + + case "upload": + m.Cmdy(ice.WEB_STORY, "upload") + return + + case "share": + list := []string{} + for k, v := range meta { + list = append(list, k, kit.Format(v)) + } + // 共享命令 + m.Cmdy(ice.WEB_SHARE, "add", "action", arg[5], arg[6], list) + return + } + } + + // 组装命令 + cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:]) + } + }) + + if len(cmds) == 0 { + return + } + + if !m.Right(cmds) { + m.Render("status", 403, "not auth") + return + } + + // 执行命令 + m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds) + }}, + }}, nil) +} diff --git a/core/chat/chat.go b/core/chat/chat.go index 5264e1f5..85913cf3 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -166,6 +166,12 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", web.Render(m, "cookie", m.Option(ice.MSG_SESSID, m.Cmdx(ice.AAA_USER, "login", m.Option(ice.MSG_USERNAME, arg[1]), arg[2]))) } + case "": + m.Info("what %v", m.Option("share")) + if m.Option("share") != "" { + return + } + default: // 群组检查 m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) { @@ -368,146 +374,6 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", "/target": {Name: "/target", Help: "对话框", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, "/source": {Name: "/source", Help: "输入框", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, - "/action": {Name: "/action", Help: "工作台", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - // 代理命令 - proxy := []string{} - if m.Option("pod") != "" { - proxy = append(proxy, ice.WEB_PROXY, m.Option("pod")) - m.Option("pod", "") - } - - if m.Warn(m.Option(ice.MSG_RIVER) == "" || m.Option(ice.MSG_STORM) == "", "not join") { - m.Set(ice.MSG_RESULT) - - cmds := kit.Simple(kit.Keys(m.Option("group"), m.Option("index")), arg[3:]) - if !m.Right(cmds) { - m.Render("status", 403, "not auth") - return - } - - // 执行命令 - m.Cmdy(proxy, cmds).Option("cmds", cmds) - return - // m.Render("status", 402, "not join") - } - - prefix := kit.Keys(kit.MDB_HASH, arg[0], "tool", kit.MDB_HASH, arg[1]) - if len(arg) == 2 { - if p := m.Option("pod"); p != "" { - m.Option("pod", "") - if m.Cmdy(ice.WEB_SPACE, p, "web.chat./action", arg); len(m.Appendv("river")) > 0 { - // 远程查询 - return - } - } - - // 命令列表 - m.Grows(ice.CHAT_RIVER, prefix, "", "", func(index int, value map[string]interface{}) { - if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok { - m.Push("river", arg[0]) - m.Push("storm", arg[1]) - m.Push("action", index) - - m.Push("node", meta["pod"]) - m.Push("group", meta["ctx"]) - m.Push("index", meta["cmd"]) - m.Push("args", kit.Select("[]", kit.Format(meta["args"]))) - - msg := m.Cmd(m.Space(meta["pod"]), ice.CTX_COMMAND, meta["ctx"], meta["cmd"]) - m.Push("name", meta["cmd"]) - m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"]))) - m.Push("feature", msg.Append("meta")) - m.Push("inputs", msg.Append("list")) - } - }) - return - } - - switch arg[2] { - case "save": - if p := m.Option("pod"); p != "" { - // 远程保存 - m.Option("pod", "") - m.Cmd(ice.WEB_SPACE, p, "web.chat./action", arg) - return - } - - // 保存应用 - m.Conf(ice.CHAT_RIVER, kit.Keys(prefix, "list"), "") - for i := 3; i < len(arg)-4; i += 5 { - id := m.Grow(ice.CHAT_RIVER, kit.Keys(prefix), kit.Data( - "pod", arg[i], "ctx", arg[i+1], "cmd", arg[i+2], - "help", arg[i+3], "args", arg[i+4], - )) - m.Log(ice.LOG_INSERT, "storm: %s %d: %v", arg[1], id, arg[i:i+5]) - } - } - - if m.Option("_action") == "上传" { - msg := m.Cmd(ice.WEB_CACHE, "upload") - m.Option("_data", msg.Append("data")) - m.Option("_name", msg.Append("name")) - m.Cmd(ice.WEB_FAVOR, "upload", msg.Append("type"), msg.Append("name"), msg.Append("data")) - m.Option("_option", m.Optionv("option")) - } - - // 查询命令 - cmds := []string{} - m.Grows(ice.CHAT_RIVER, prefix, kit.MDB_ID, kit.Format(kit.Int(arg[2])+1), func(index int, value map[string]interface{}) { - if meta, ok := kit.Value(value, "meta").(map[string]interface{}); ok { - if len(arg) > 3 && arg[3] == "action" { - // 命令补全 - switch arg[4] { - case "input": - switch arg[5] { - case "location": - // 查询位置 - m.Copy(m.Cmd("aaa.location"), "append", "name") - return - } - - case "favor": - m.Cmdy(ice.WEB_FAVOR, arg[5:]) - return - - case "device": - // 记录位置 - m.Cmd(ice.WEB_FAVOR, kit.Select("device", m.Option("hot")), arg[5], arg[6], - kit.Select("", arg, 7), kit.KeyValue(map[string]interface{}{}, "", kit.UnMarshal(kit.Select("{}", arg, 8)))) - return - - case "upload": - m.Cmdy(ice.WEB_STORY, "upload") - return - - case "share": - list := []string{} - for k, v := range meta { - list = append(list, k, kit.Format(v)) - } - // 共享命令 - m.Cmdy(ice.WEB_SHARE, "add", "action", arg[5], arg[6], list) - return - } - } - - // 组装命令 - cmds = kit.Simple(m.Space(meta["pod"]), kit.Keys(meta["ctx"], meta["cmd"]), arg[3:]) - } - }) - - if len(cmds) == 0 { - return - } - - if !m.Right(cmds) { - m.Render("status", 403, "not auth") - return - } - - // 执行命令 - m.Cmdy(proxy, cmds).Option("cmds", cmds) - }}, "search": {Name: "search label pod engine word", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { diff --git a/misc/git/git.go b/misc/git/git.go index 1330838c..33cf0845 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -109,7 +109,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", }) m.Sort("name") }}, - "total": {Name: "total name auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "total": {Name: "total name=auto auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 { // 提交详情 m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) {