From 4e9b49a970982a09ef5d56ef112e2d879af1b694 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sat, 3 Dec 2022 18:05:38 +0800 Subject: [PATCH] opt chat --- base/ctx/command.go | 5 +++-- base/web/cache.go | 7 +++++-- core/chat/action.go | 5 ++--- core/chat/cmd.go | 4 ++-- core/chat/demo.go | 18 ------------------ core/wiki/field.go | 2 +- exec.go | 4 ++-- 7 files changed, 15 insertions(+), 30 deletions(-) delete mode 100644 core/chat/demo.go diff --git a/base/ctx/command.go b/base/ctx/command.go index adaaa900..6b0fec8e 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -120,14 +120,15 @@ func Run(m *ice.Message, arg ...string) { } } } - if Upload(m); !PodCmd(m, arg) && aaa.Right(m, arg) { + if !PodCmd(m, arg) && aaa.Right(m, arg) { m.Cmdy(arg) } } -var Upload = func(*ice.Message) {} +var Upload = func(*ice.Message) []string { return nil } func PodCmd(m *ice.Message, arg ...ice.Any) bool { + Upload(m) if pod := m.Option(ice.POD); pod != "" { m.Option(ice.POD, "") m.Cmdy(append(kit.List(ice.SPACE, pod), arg...)...) diff --git a/base/web/cache.go b/base/web/cache.go index 1b5edff7..2b670049 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -155,7 +155,7 @@ func init() { } watch := action.Hand == nil action.Hand = ice.MergeHand(func(m *ice.Message, arg ...string) { - up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)) + up := Upload(m) m.Assert(len(up) > 1) m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Tables(func(value ice.Maps) { m.Options(value) }) if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch { @@ -167,11 +167,14 @@ func init() { }) ctx.Upload = Upload } -func Upload(m *ice.Message) { +func Upload(m *ice.Message) []string { if up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(up) == 1 { if m.Cmdy(CACHE, UPLOAD).Optionv(ice.MSG_UPLOAD, kit.Simple(m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" { m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, MergeURL2(m, path.Join(SHARE_CACHE, m.Append(mdb.HASH)))) } + return kit.Simple(m.Optionv(ice.MSG_UPLOAD)) + } else { + return up } } func PushDisplay(m *ice.Message, mime, name, link string) { diff --git a/core/chat/action.go b/core/chat/action.go index 71190bb4..4f5be6dd 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -21,13 +21,13 @@ func _action_exec(m *ice.Message, river, storm, index string, arg ...string) { }).Length() == 0, ice.ErrNotRight, index, arg) { return } - if web.Upload(m); !ctx.PodCmd(m, index, arg) { + if !ctx.PodCmd(m, index, arg) { m.Cmdy(index, arg) } } func _action_auth(m *ice.Message, share string) *ice.Message { msg := m.Cmd(web.SHARE, share) - if m.Warn(msg.Append(mdb.TIME) < m.Time(), ice.ErrNotValid, share, msg.Append(mdb.TIME), m.Time()) { + if web.IsNotValidShare(m, msg.Append(mdb.TIME)) { msg.Append(mdb.TYPE, "") return msg } @@ -58,7 +58,6 @@ func _action_share(m *ice.Message, arg ...string) { m.Cmdy(ctx.COMMAND, msg.Append(mdb.NAME)) break } - web.Upload(m) m.Cmdy(msg.Append(mdb.NAME), arg[2:]) } } diff --git a/core/chat/cmd.go b/core/chat/cmd.go index 7f4e6cad..54933f99 100644 --- a/core/chat/cmd.go +++ b/core/chat/cmd.go @@ -28,8 +28,8 @@ func _cmd_file(m *ice.Message, arg ...string) bool { web.RenderCmd(m, kit.Select(ctx.CAN_PLUGIN, ctx.GetFileCmd(p))) default: if p = strings.TrimPrefix(p, ice.SRC+ice.PS); nfs.ExistsFile(m, path.Join(ice.SRC, p)) { - if msg := m.Cmd(mdb.RENDER, kit.Ext(p)); msg.Length() > 0 { - m.Cmdy(mdb.RENDER, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult() + if msg := m.Cmd(mdb.ENGINE, kit.Ext(p)); msg.Length() > 0 { + m.Cmdy(mdb.ENGINE, kit.Ext(p), p, ice.SRC+ice.PS).RenderResult() break } } diff --git a/core/chat/demo.go b/core/chat/demo.go deleted file mode 100644 index 691c0c16..00000000 --- a/core/chat/demo.go +++ /dev/null @@ -1,18 +0,0 @@ -package chat - -import ( - ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/mdb" -) - -func init() { - Index.MergeCommands(ice.Commands{ - "demo-hash": {Actions: ice.MergeActions(mdb.HashAction(), ctx.CmdAction())}, - "demo-status-hash": {Actions: ice.MergeActions(mdb.StatusHashAction(), ctx.CmdAction())}, - "demo-list": {Actions: ice.MergeActions(mdb.ListAction(), ctx.CmdAction())}, - "demo-page-list": {Actions: ice.MergeActions(mdb.PageListAction(), ctx.CmdAction())}, - "demo-zone": {Actions: ice.MergeActions(mdb.ZoneAction(), ctx.CmdAction())}, - "demo-page-zone": {Actions: ice.MergeActions(mdb.PageZoneAction(), ctx.CmdAction())}, - }) -} diff --git a/core/wiki/field.go b/core/wiki/field.go index 3124ff13..f791c00b 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -113,7 +113,7 @@ func init() {
`), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) { - if arg[1] == ctx.ARGS { + if kit.Select("", arg, 1) == ctx.ARGS { arg = kit.Simple("", arg) } if arg = _name(m, arg); strings.Contains(arg[1], ice.NL) { diff --git a/exec.go b/exec.go index 400c0792..8f7b4457 100644 --- a/exec.go +++ b/exec.go @@ -18,8 +18,8 @@ func (m *Message) TryCatch(msg *Message, catch bool, cb ...func(msg *Message)) * default: fileline := m.FormatStack(2, 1) m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("chain", msg.FormatChain()) - m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", m.FormatStack(1, 100)) - m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, SP, m.FormatStack(1, 5)) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", m.FormatStack(2, 100)) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, SP, m.FormatStack(2, 5)) if len(cb) > 1 { m.TryCatch(msg, catch, cb[1:]...) } else if !catch {