From 5f6cb250a115e3e26263a9e5f2a26e0ac4b504f2 Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 17 Oct 2023 10:42:26 +0800 Subject: [PATCH] add some --- base/web/dream.go | 3 ++- base/web/option.go | 13 +++++++++++++ base/web/render.go | 6 +++--- base/web/serve.go | 5 +++-- base/web/space.go | 3 +++ core/chat/pod.go | 2 +- logs.go | 2 +- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/base/web/dream.go b/base/web/dream.go index 31d31f0e..f28c35ee 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -256,10 +256,11 @@ func init() { _dream_start(m, m.Option(mdb.NAME)) }}, cli.STOP: {Hand: func(m *ice.Message, arg ...string) { + defer ToastProcess(m)() + defer m.Sleep3s() gdb.Event(m, DREAM_STOP, arg) m.Cmd(SPACE, mdb.MODIFY, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP) m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT) - m.Sleep300ms() }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { gdb.Event(m, DREAM_TRASH, arg) diff --git a/base/web/option.go b/base/web/option.go index 08f6c568..ca0797f9 100644 --- a/base/web/option.go +++ b/base/web/option.go @@ -12,6 +12,7 @@ import ( "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/log" "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/tcp" kit "shylinux.com/x/toolkits" "shylinux.com/x/toolkits/file" @@ -51,6 +52,18 @@ func MergeLink(m *ice.Message, url string, arg ...ice.Any) string { kit.If(m.Option(log.DEBUG) == ice.TRUE, func() { arg = append(arg, log.DEBUG, ice.TRUE) }) return kit.MergeURL(strings.Split(MergeURL2(m, url), QS)[0], arg...) } +func ParseLink(m *ice.Message, url string) ice.Maps { + list := ice.Maps{} + u := kit.ParseURL(url) + switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] { + case CHAT: + kit.For(arg[1:], func(k, v string) { list[k] = v }) + case SHARE: + list[arg[0]] = arg[1] + } + kit.For(u.Query(), func(k string, v []string) { list[k] = v[0] }) + return list +} func ProcessPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { m.ProcessOpen(m.MergePodCmd(pod, cmd, arg...)) } diff --git a/base/web/render.go b/base/web/render.go index f8c91a3f..891519d0 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -42,7 +42,7 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool { case COOKIE: // value [name [path [expire]]] RenderCookie(m, arg[0], arg[1:]...) case STATUS, ice.RENDER_STATUS: // [code [text]] - RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), strings.Join(kit.Slice(arg, 1), " ")) + RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), kit.Select(m.Result(), strings.Join(kit.Slice(arg, 1), " "))) case ice.RENDER_REDIRECT: // url [arg...] http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect) case ice.RENDER_DOWNLOAD: // file [type [name]] @@ -124,11 +124,11 @@ func RenderMain(m *ice.Message) *ice.Message { if m.IsCliUA() { return m.RenderDownload(path.Join(ice.USR_INTSHELL, ice.INDEX_SH)) } - m.OptionDefault(nfs.VERSION, RenderVersion(m)+kit.Select("", "&pod="+m.Option(ice.MSG_USERPOD), m.Option(ice.MSG_USERPOD) != "")) + m.Option(nfs.VERSION, RenderVersion(m)+kit.Select("", "&pod="+m.Option(ice.MSG_USERPOD), m.Option(ice.MSG_USERPOD) != "")) return RenderTemplate(m, "main.html") } func RenderCmds(m *ice.Message, list ...ice.Any) { - m.OptionDefault(nfs.VERSION, RenderVersion(m)+kit.Select("", "&pod="+m.Option(ice.MSG_USERPOD), m.Option(ice.MSG_USERPOD) != "")) + m.Option(nfs.VERSION, RenderVersion(m)+kit.Select("", "&pod="+m.Option(ice.MSG_USERPOD), m.Option(ice.MSG_USERPOD) != "")) RenderTemplate(m.Options(mdb.LIST, kit.Format(list)), "cmds.html") } func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { diff --git a/base/web/serve.go b/base/web/serve.go index 70e51f4e..bf755eb0 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -58,7 +58,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { } else { r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0]) } - if !kit.HasPrefix(r.URL.String(), VOLCANOS, REQUIRE_SRC, REQUIRE_MODULES, INTSHELL) { + if !kit.HasPrefix(r.URL.String(), VOLCANOS, REQUIRE_MODULES, INTSHELL) { r.Header.Set(ice.LOG_TRACEID, log.Traceid()) m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID))) } @@ -66,7 +66,8 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, ice.MAIN)) } if r.Method == http.MethodGet { - msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent(), ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID)) + msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent(), ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID), + ParseLink(m, kit.Select(r.URL.String(), r.Referer()))) if path.Join(r.URL.Path) == nfs.PS { if Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...) { return false diff --git a/base/web/space.go b/base/web/space.go index 73bc80ce..cf57326b 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -205,6 +205,9 @@ func init() { m.Cmd(SPACE, pod, SPIDE, ice.DEV, CACHE, SHARE_CACHE+ls[0]) } m.Options(key, []string{}, ice.MSG_USERPOD, pod).Cmdy(append(kit.List(ice.SPACE, pod), arg...)...) + if m.IsErr() { + m.Warn(m.IsErr(), kit.Select("", m.Resultv(), 1), kit.Slice(m.Resultv(), 2)) + } return true } } diff --git a/core/chat/pod.go b/core/chat/pod.go index 5be355dd..d1a6e356 100644 --- a/core/chat/pod.go +++ b/core/chat/pod.go @@ -30,7 +30,7 @@ func init() { m.Cmd(web.DREAM, cli.START, kit.Dict(mdb.NAME, arg[0])) } if len(arg) == 1 { - m.Cmdy(web.SPACE, arg[0], web.SPACE, ice.MAIN, kit.Dict(nfs.VERSION, web.RenderVersion(m), ice.MSG_USERPOD, arg[0])) + m.Cmdy(web.SPACE, arg[0], web.SPACE, ice.MAIN, kit.Dict(ice.MSG_USERPOD, arg[0])) } else if arg[1] == CMD { web.RenderPodCmd(m, arg[0], arg[2], arg[3:]) } diff --git a/logs.go b/logs.go index 7d18051a..9ece046b 100644 --- a/logs.go +++ b/logs.go @@ -119,7 +119,7 @@ func (m *Message) Warn(err Any, arg ...Any) bool { return false } str, meta := m.join(arg...) - if m.log(LOG_WARN, str, meta...); !m.IsErr() && len(arg) > 0 { + if m.log(LOG_WARN, str, meta...); len(arg) > 0 { m.error(arg...) kit.If(map[string]int{ ErrNotLogin: http.StatusUnauthorized,