From 054c3ebca7617da5494543370a1c172c617caef8 Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 5 May 2021 23:47:30 +0800 Subject: [PATCH] opt some --- base/web/render.go | 23 +++++++++++++++-------- base/web/serve.go | 6 ++++++ core/chat/action.go | 34 +++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/base/web/render.go b/base/web/render.go index 69fbc9fb..3905ea81 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -1,16 +1,15 @@ package web import ( + "fmt" + "net/http" + "path" + "time" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/aaa" "github.com/shylinux/icebergs/base/cli" kit "github.com/shylinux/toolkits" - - "fmt" - "net/http" - "path" - "strings" - "time" ) const ( @@ -91,9 +90,17 @@ func RenderCookie(msg *ice.Message, value string, arg ...string) { // name path func RenderType(w http.ResponseWriter, name, mime string) { if mime != "" { w.Header().Set(ContentType, mime) - } else if strings.HasSuffix(name, ".css") { + return + } + + switch kit.Ext(name) { + case "css": w.Header().Set(ContentType, "text/css; charset=utf-8") - } else { + case "pdf": + w.Header().Set(ContentType, "application/pdf") + + default: + break w.Header().Set(ContentType, ContentHTML) } } diff --git a/base/web/serve.go b/base/web/serve.go index d82a8f2e..b923ec03 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -171,6 +171,12 @@ func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *htt if ls := strings.Split(r.URL.Path, "/"); msg.Conf(SERVE, kit.Keym(aaa.BLACK, ls[1])) == "true" { return cmds, false // 黑名单 } else if msg.Conf(SERVE, kit.Keym(aaa.WHITE, ls[1])) == "true" { + if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" { + share := msg.Cmd(SHARE, msg.Option(SHARE)) + msg.Option(ice.MSG_USERNAME, share.Append(aaa.USERNAME)) + msg.Option(ice.MSG_USERROLE, share.Append(aaa.USERROLE)) + msg.Debug("login ") + } return cmds, true // 白名单 } diff --git a/core/chat/action.go b/core/chat/action.go index 33067c28..24b922f7 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -54,27 +54,31 @@ func _action_right(m *ice.Message, river string, storm string) (ok bool) { } return ok } -func _action_share(m *ice.Message, cmd string, arg ...string) { +func _action_share(m *ice.Message, arg ...string) { switch msg := m.Cmd(web.SHARE, arg[1]); msg.Append(kit.MDB_TYPE) { case web.FIELD: if cmd := kit.Keys(msg.Append(web.RIVER), msg.Append(web.STORM)); len(arg) == 2 { m.Push("index", cmd) m.Push("title", msg.Append(kit.MDB_NAME)) m.Push("args", msg.Append(kit.MDB_TEXT)) - } else { - if m.Warn(kit.Time() > kit.Time(msg.Append(kit.MDB_TIME)), ice.ErrExpire) { - return // 分享超时 - } - m.Log_AUTH( - aaa.USERROLE, m.Option(ice.MSG_USERROLE, msg.Append(aaa.USERROLE)), - aaa.USERNAME, m.Option(ice.MSG_USERNAME, msg.Append(aaa.USERNAME)), - ) - if m.Warn(!m.Right(arg[3:]), ice.ErrNotRight) { - return // 没有授权 - } - - m.Cmdy(cmd, arg[3:]) + break } + + if m.Warn(kit.Time() > kit.Time(msg.Append(kit.MDB_TIME)), ice.ErrExpire) { + break // 分享超时 + } + m.Log_AUTH( + aaa.USERROLE, m.Option(ice.MSG_USERROLE, msg.Append(aaa.USERROLE)), + aaa.USERNAME, m.Option(ice.MSG_USERNAME, msg.Append(aaa.USERNAME)), + ) + if m.Warn(!m.Right(arg[2:]), ice.ErrNotRight) { + break // 没有授权 + } + + if m.Option(ice.MSG_UPLOAD) != "" { + _action_upload(m) // 上传文件 + } + m.Cmdy(arg[2:]) } } @@ -144,7 +148,7 @@ func init() { }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if arg[0] == "_share" { - _action_share(m, cmd, arg...) + _action_share(m, arg...) return }