From 67cfeb5e049bc9bf3444718cc91c54eecc5e5be1 Mon Sep 17 00:00:00 2001 From: shy Date: Fri, 1 Dec 2023 23:32:57 +0800 Subject: [PATCH] add rc_local.sh --- base/web/cache.go | 6 +++++- base/web/dream.go | 13 ++++++++++++- base/web/render.go | 8 +++++++- base/web/serve.go | 1 + base/web/spide.go | 3 +++ core/chat/cmd.go | 11 ++--------- core/code/xterm.go | 8 ++++++-- core/wiki/portal.css | 2 +- info.go | 2 ++ 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/base/web/cache.go b/base/web/cache.go index 3b41a989..68e2837f 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -154,6 +154,8 @@ func init() { }, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file", ctx.ACTION, WATCH), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) { if mdb.HashSelect(m, arg...); len(arg) == 0 || m.R != nil && m.R.Method == http.MethodGet { m.Option(ice.MSG_ACTION, "") + } else if m.Length() == 0 { + return } else if m.Append(nfs.FILE) == "" { m.PushScript(mdb.TEXT, m.Append(mdb.TEXT)) } else { @@ -171,7 +173,9 @@ func init() { action.Hand = ice.MergeHand(func(m *ice.Message, arg ...string) { up := Upload(m) m.Assert(len(up) > 1) - m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) }) + if m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) }).Length() == 0 { + SpideCache(m.Spawn(), kit.MergeURL2(m.Option(ice.MSG_USERWEB), SHARE_CACHE+up[0])) + } if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch { m.Cmdy(CACHE, WATCH, m.Option(mdb.HASH), path.Join(m.Option(nfs.PATH), up[1])) } diff --git a/base/web/dream.go b/base/web/dream.go index db294f81..808fabda 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -137,6 +137,16 @@ const DREAM = "dream" func init() { Index.MergeCommands(ice.Commands{ DREAM: {Name: "dream name@key auto create repos startall stopall publish cmd cat", Help: "梦想家", Icon: "Launchpad.png", Actions: ice.MergeActions(ice.Actions{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + m = m.Spawn() + m.GoSleep("10s", func() { + mdb.HashSelects(m).Table(func(value ice.Maps) { + if value[cli.RESTART] == "always" && nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK+value[mdb.NAME])) { + m.Cmd(DREAM, cli.START, kit.Dict(mdb.NAME, value[mdb.NAME])) + } + }) + }) + }}, ctx.CONFIG: {Hand: func(m *ice.Message, arg ...string) { for _, cmd := range kit.Reverse(arg) { m.Cmd(gdb.EVENT, gdb.LISTEN, gdb.EVENT, DREAM_TABLES, ice.CMD, cmd) @@ -262,7 +272,8 @@ func init() { PushStats(m, kit.Keys(m.CommandKey(), mdb.TOTAL), msg.Length(), "") } }}, - }, aaa.RoleAction(), StatsAction(), DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) { + }, aaa.RoleAction(), StatsAction(), DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", + mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template,restart")), Hand: func(m *ice.Message, arg ...string) { if ice.Info.NodeType == WORKER { return } diff --git a/base/web/render.go b/base/web/render.go index 2ec14bbe..f8daf6cb 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -132,12 +132,18 @@ func RenderCmds(m *ice.Message, cmds ...ice.Any) { } func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select(m.PrefixKey(), cmd)) + if msg.Length() == 0 { + RenderResult(m, kit.Format("not found command %s", cmd)) + return + } RenderCmds(m, kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP), ctx.INDEX, msg.Append(ctx.INDEX), ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY), mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)), )) } -func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) } +func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { + RenderPodCmd(m, "", cmd, arg...) +} func RenderVersion(m *ice.Message) string { if ice.Info.Make.Hash == "" { diff --git a/base/web/serve.go b/base/web/serve.go index 73c2a9f5..5dad3551 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -169,6 +169,7 @@ func _serve_auth(m *ice.Message, key string, cmds []string, w http.ResponseWrite cmds = append(kit.Split(cmds[0], ","), cmds[1:]...) } if r.URL.Path == PP(SPACE) { + aaa.SessCheck(m, m.Option(ice.MSG_SESSID)) return cmds, true } defer func() { m.Options(ice.MSG_CMDS, "", ice.MSG_SESSID, "") }() diff --git a/base/web/spide.go b/base/web/spide.go index a2bc5d93..def2de4c 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -401,6 +401,9 @@ func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any { func SpideSave(m *ice.Message, file, link string, cb func(count, total, value int)) *ice.Message { return m.Cmd(Prefix(SPIDE), ice.DEV, SPIDE_SAVE, file, http.MethodGet, link, cb) } +func SpideCache(m *ice.Message, link string) *ice.Message { + return m.Cmd(Prefix(SPIDE), ice.DEV, SPIDE_CACHE, http.MethodGet, link) +} func SpideOrigin(m *ice.Message, name string) string { return m.Cmdv("web.spide", name, CLIENT_ORIGIN) } diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 38cf00fa..5c9baf72 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -3,6 +3,7 @@ package chat import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/web" + kit "shylinux.com/x/toolkits" ) const CMD = "cmd" @@ -10,15 +11,7 @@ const CMD = "cmd" func init() { Index.MergeCommands(ice.Commands{ CMD: {Help: "命令", Actions: web.ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) { - if len(arg[0]) == 0 || arg[0] == "" { - web.RenderMain(m) - } else { - if m.IsCliUA() { - m.Cmdy(arg, m.Optionv(ice.ARG)).RenderResult() - } else { - web.RenderCmd(m, arg[0], arg[1:]) - } - } + web.RenderCmd(m, kit.Select(web.WIKI_WORD, arg, 0), kit.Slice(arg, 1)) }}, }) } diff --git a/core/code/xterm.go b/core/code/xterm.go index 8dc4d363..eaef7ae1 100644 --- a/core/code/xterm.go +++ b/core/code/xterm.go @@ -161,10 +161,14 @@ func init() { }}, }, chat.FavorAction(), ctx.ProcessAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path")), Hand: func(m *ice.Message, arg ...string) { if mdb.HashSelect(m, arg...); len(arg) == 0 { - m.Action(mdb.CREATE, mdb.PRUNES, ice.APP) + if web.IsLocalHost(m) { + m.Action(mdb.CREATE, mdb.PRUNES, ice.APP) + } else { + m.Action(mdb.CREATE, mdb.PRUNES) + } } else { kit.If(m.Length() == 0, func() { arg[0] = m.Cmdx("", mdb.CREATE, arg); mdb.HashSelect(m, arg[0]) }) - m.Push(mdb.HASH, arg[0]).Action(html.OUTPUT, ice.APP) + m.Push(mdb.HASH, arg[0]) ctx.DisplayLocal(m, "") } }}, diff --git a/core/wiki/portal.css b/core/wiki/portal.css index fcf71747..e673d420 100644 --- a/core/wiki/portal.css +++ b/core/wiki/portal.css @@ -42,8 +42,8 @@ body.dark fieldset.web.wiki.portal>div.output>div.header div.story[data-name=nav body.white fieldset.web.wiki.portal>div.output>div.header { color:silver; } body.light fieldset.web.wiki.portal>div.output>div.header { color:white; } body.light fieldset.web.wiki.portal>div.output>div.header div.story[data-name=navmenu] { --hover-fg-color:black; } -body.light fieldset.web.wiki.portal>div.output>div.header div.list { display:flex; } fieldset.web.wiki.portal>div.output>div.header div.story[data-name=navmenu] { --hover-fg-color:white; } +fieldset.web.wiki.portal>div.output>div.header div.list { display:flex; } body.mobile fieldset.web.wiki.portal { --portal-main-padding:10px; --legend-padding:10px; } body.mobile fieldset.web.wiki.portal>div.output>div.layout { display:block; } diff --git a/info.go b/info.go index cd5ce74f..62bc5e86 100644 --- a/info.go +++ b/info.go @@ -58,6 +58,7 @@ var Info = struct { PidPath string Traceid string Colors bool + Pwd string Lang string System string @@ -103,6 +104,7 @@ var Info = struct { } func init() { + Info.Pwd = kit.Path("") Info.Traceid = os.Getenv(LOG_TRACE) } func AddMergeAction(h ...Any) {