From 5bdef4343624d6528348cd05ed56e611cf57e8a5 Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 16 Aug 2023 00:13:06 +0800 Subject: [PATCH] add some --- base/cli/system.go | 2 ++ base/ctx/command.go | 7 ++++--- base/ctx/display.go | 6 ++++++ base/mdb/mdb.go | 2 ++ base/tcp/port.go | 8 ++++++++ base/web/serve.go | 3 +++ base/web/spide.go | 18 ++++++++++++------ 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/base/cli/system.go b/base/cli/system.go index 601c360c..e9d0a9da 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -142,6 +142,8 @@ const ( CMD_OUT = "cmd_out" MAN = "man" + RUN = "run" + KILL = "kill" FIND = "find" GREP = "grep" EXEC = "exec" diff --git a/base/ctx/command.go b/base/ctx/command.go index ad5465f2..9ab9ac39 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -119,13 +119,14 @@ func PodCmd(m *ice.Message, arg ...ice.Any) bool { func Run(m *ice.Message, arg ...string) { kit.If(!PodCmd(m, arg) && aaa.Right(m, arg), func() { m.Cmdy(arg) }) } +func Command(m *ice.Message, arg ...string) { + kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) }) +} func CmdHandler(args ...ice.Any) ice.Handler { return func(m *ice.Message, arg ...string) { m.Cmdy(args...) } } func CmdAction(args ...ice.Any) ice.Actions { - return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), ice.RUN: {Hand: Run}, - COMMAND: {Hand: func(m *ice.Message, arg ...string) { kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) }) }}, - } + return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), ice.RUN: {Hand: Run}, COMMAND: {Hand: Command}} } func CmdList(m *ice.Message) *ice.Message { return m.Cmdy(COMMAND, mdb.SEARCH, COMMAND, ice.OptionFields(INDEX)) diff --git a/base/ctx/display.go b/base/ctx/display.go index 5e168863..b939af97 100644 --- a/base/ctx/display.go +++ b/base/ctx/display.go @@ -41,6 +41,12 @@ func DisplayStoryJSON(m displayMessage, arg ...ice.Any) displayMessage { func DisplayStorySpide(m displayMessage, arg ...ice.Any) displayMessage { return DisplayStory(m, "spide", arg...) } +func DisplayStudio(m *ice.Message, cmd ...string) displayMessage { + for i, k := range cmd { + cmd[i] = m.Prefix(k) + } + return DisplayStory(m.Cmdy(COMMAND, cmd), "studio.js") +} func DisplayLocal(m displayMessage, file string, arg ...ice.Any) displayMessage { kit.If(file == "", func() { file = path.Join(kit.PathName(5), kit.Keys(kit.FileName(5), nfs.JS)) }) kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_LOCAL, file) }) diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index cb508531..858c41ba 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -106,6 +106,8 @@ const ( PRUNES = "prunes" EXPORT = "export" IMPORT = "import" + PRUNE = "prune" + RENAME = "rename" DETAIL = "detail" FIELDS = "fields" diff --git a/base/tcp/port.go b/base/tcp/port.go index d2513d9b..fb4fd705 100644 --- a/base/tcp/port.go +++ b/base/tcp/port.go @@ -58,6 +58,14 @@ func init() { m.Push(arg[0], strings.Replace(value["local"], "0.0.0.0", "127.0.0.1", 1)) } }) + case "port": + m.Cmd(PORT, "socket", func(value ice.Maps) { + switch value["status"] { + case "LISTEN": + m.Push(arg[0], strings.TrimPrefix(value["local"], "0.0.0.0:")) + m.Push(mdb.NAME, "listen") + } + }) } }}, "socket": {Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/serve.go b/base/web/serve.go index f75d91f2..418fd449 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -193,6 +193,9 @@ func init() { }) }}, cli.SYSTEM: {Help: "系统", Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, "System Settings.app") }}, + "publicip": {Hand: func(m *ice.Message, arg ...string) { + m.Echo(kit.Formats(PublicIP(m))) + }}, "dark": {Help: "主题", Hand: func(m *ice.Message, arg ...string) { if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) { return diff --git a/base/web/spide.go b/base/web/spide.go index 962540c3..e4102a41 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -289,13 +289,19 @@ func init() { } func HostPort(m *ice.Message, host, port string, arg ...string) string { - if port == "443" { - return kit.Format("https://%s", host) - } else if port == "80" { - return kit.Format("http://%s", host) - } else { - return kit.Format("http://%s:%s", host, port) + if host == "" { + host = kit.ParseURL(UserHost(m)).Hostname() } + if port == "80" { + return kit.Format("http://%s", host) + } else if port == "443" { + return kit.Format("https://%s", host) + } else { + return kit.Format("%s://%s:%s", kit.ParseURL(UserHost(m)).Scheme, host, port) + } +} +func PublicIP(m *ice.Message) ice.Any { + return SpideGet(m, "http://ip-api.com/json") } func SpideGet(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodGet, arg))