From 40838d0045f0cf613fac6e51acee5402ea35313c Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 23 Jun 2020 09:31:06 +0800 Subject: [PATCH] opt feel --- base/web/favor.go | 8 +++--- base/web/render.go | 4 +++ base/web/share.go | 2 +- base/web/space.go | 2 +- base/web/spide.go | 4 +-- core/code/pprof.go | 2 +- core/wiki/feel.go | 10 ++++--- core/wiki/wiki.go | 8 ++---- misc/chrome/chrome.go | 65 +++++++++++++------------------------------ 9 files changed, 41 insertions(+), 64 deletions(-) diff --git a/base/web/favor.go b/base/web/favor.go index 43a0f7cd..75fbba8d 100644 --- a/base/web/favor.go +++ b/base/web/favor.go @@ -264,11 +264,10 @@ const ( ) const FAVOR = "favor" -const ( // TYPE - TYPE_SPIDE = "spide" - TYPE_SPACE = "space" - TYPE_STORY = "story" +const PLUGIN = "plugin" + +const ( // TYPE TYPE_RIVER = "river" TYPE_STORM = "storm" TYPE_ACTION = "action" @@ -303,6 +302,7 @@ func init() { _favor_create(m, arg[0]) }}, mdb.INSERT: {Name: "insert zone type name text", Help: "插入", Hand: func(m *ice.Message, arg ...string) { + _favor_create(m, arg[0]) _favor_insert(m, arg[0], arg[1], arg[2], kit.Select("", arg, 3)) }}, mdb.MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/web/render.go b/base/web/render.go index 808f7e9b..29989206 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" + "os" "path" "time" ) @@ -55,6 +56,9 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) { case ice.RENDER_DOWNLOAD: msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(arg[0]), arg, 2))) msg.W.Header().Set("Content-Type", kit.Select("text/html", arg, 1)) + if _, e := os.Stat(arg[0]); e != nil { + arg[0] = "/" + arg[0] + } http.ServeFile(msg.W, msg.R, arg[0]) case ice.RENDER_RESULT: diff --git a/base/web/share.go b/base/web/share.go index 0bedc550..dc85c8fc 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -260,7 +260,7 @@ func init() { } switch value[kit.MDB_TYPE] { - case TYPE_STORY: + case STORY: value = _share_story(m, value, arg...) } diff --git a/base/web/space.go b/base/web/space.go index 211812e4..24b7c392 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -221,7 +221,7 @@ func init() { _space_send(m, arg[0], arg[1:]...) }}, - "/space/": {Name: "/space/", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "/space/": {Name: "/space/ type name", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if s, e := websocket.Upgrade(m.W, m.R, nil, m.Confi(SPACE, "meta.buffer.r"), m.Confi(SPACE, "meta.buffer.w")); m.Assert(e) { name := m.Option(kit.MDB_NAME, strings.Replace(kit.Select(m.Option(ice.MSG_USERADDR), m.Option(kit.MDB_NAME)), ".", "_", -1)) kind := kit.Select(WORKER, m.Option(kit.MDB_TYPE)) diff --git a/base/web/spide.go b/base/web/spide.go index eef0cde1..99589baa 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -47,7 +47,7 @@ func _spide_login(m *ice.Message, name string) { } if msg.Result() != "" { kit.Value(value, "client.login", msg.Result()) - kit.Value(value, "client.share", m.Cmdx(SHARE, TYPE_SPIDE, name, + kit.Value(value, "client.share", m.Cmdx(SHARE, SPIDE, name, kit.Format("%s?sessid=%s", kit.Value(value, "client.url"), kit.Value(value, "cookie.sessid")))) } m.Render(ice.RENDER_QRCODE, kit.Dict( @@ -70,7 +70,7 @@ func _spide_create(m *ice.Message, name, address string, arg ...string) { dir, file := path.Split(uri.EscapedPath()) m.Rich(SPIDE, nil, kit.Dict( "cookie", kit.Dict(), "header", kit.Dict(), "client", kit.Dict( - "share", ShareCreate(m.Spawn(), TYPE_SPIDE, name, address), + "share", ShareCreate(m.Spawn(), SPIDE, name, address), "name", name, "url", address, "method", "POST", "protocol", uri.Scheme, "hostname", uri.Host, "path", dir, "file", file, "query", uri.RawQuery, diff --git a/core/code/pprof.go b/core/code/pprof.go index dd3374bb..af3d93c5 100644 --- a/core/code/pprof.go +++ b/core/code/pprof.go @@ -91,7 +91,7 @@ func _pprof_show(m *ice.Message, zone string, id string) { m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT)) url := "http://" + p + "/ui/top" - m.Cmd(web.FAVOR, favor, web.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT)) + m.Cmd(web.FAVOR, favor, web.SPIDE, url, msg.Append(kit.MDB_TEXT)) m.Set(ice.MSG_RESULT).Echo(url).Echo(" \n").Echo("\n") m.Echo(strings.Join(list, "\n")).Echo("\n") diff --git a/core/wiki/feel.go b/core/wiki/feel.go index 60ceb719..cf425bab 100644 --- a/core/wiki/feel.go +++ b/core/wiki/feel.go @@ -15,20 +15,19 @@ func _feel_show(m *ice.Message, name string, arg ...string) { } const FEEL = "feel" -const ( - FeelPlugin = "/plugin/local/wiki/feel.js" -) +const FeelPlugin = "/plugin/local/wiki/feel.js" func init() { Index.Merge(&ice.Context{Name: "feel", Help: "影音媒体", Configs: map[string]*ice.Config{ FEEL: {Name: "feel", Help: "影音媒体", Value: kit.Data( kit.MDB_SHORT, "name", "path", "", "regs", ".*.(qrc|png|jpg|JPG|MOV|m4v)", + "height", "600", "page.limit", "3", )}, }, Commands: map[string]*ice.Command{ FEEL: {Name: "feel path=auto auto", Help: "影音媒体", Meta: kit.Dict( - mdb.PLUGIN, FeelPlugin, "detail", []string{"标签", "删除"}, + web.PLUGIN, FeelPlugin, "detail", []string{"标签", "删除"}, ), Action: map[string]*ice.Action{ mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) { m.Conf(FEEL, kit.Keys(path.Base(arg[2]), "-2"), arg[3]) @@ -44,6 +43,9 @@ func init() { _wiki_upload(m, FEEL) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("prefix", m.Conf(FEEL, "meta.path")) + m.Option("height", m.Conf(FEEL, "meta.height")) + m.Option("limit", m.Conf(FEEL, "meta.page.limit")) if !_wiki_list(m, FEEL, kit.Select("./", arg, 0)) { _feel_show(m, arg[0]) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 8e767016..fc4324b7 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -16,13 +16,11 @@ func _wiki_list(m *ice.Message, cmd, name string, arg ...string) bool { if strings.HasSuffix(name, "/") { m.Option(nfs.DIR_ROOT, m.Conf(cmd, "meta.path")) m.Option(nfs.DIR_TYPE, nfs.TYPE_DIR) - m.Cmdy(nfs.DIR, name) + m.Cmdy(nfs.DIR, name, "time size path") m.Option(nfs.DIR_TYPE, nfs.TYPE_FILE) m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs")) - m.Cmdy(nfs.DIR, name) - - m.Option("_display", "table") + m.Cmdy(nfs.DIR, name, "time size path") return true } return false @@ -64,10 +62,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", }, Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Load() }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save("feel") }}, "walk": {Name: "walk path=@province auto", Help: "走遍世界", Meta: kit.Dict("display", "local/wiki/walk"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index 21a49a28..aa0e336a 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -2,19 +2,36 @@ package crx import ( "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/code" "github.com/shylinux/toolkits" ) +const CHROME = "chrome" + var Index = &ice.Context{Name: "chrome", Help: "浏览器", - Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "chrome": {Name: "chrome", Help: "chrome", Value: kit.Data(kit.MDB_SHORT, "name", "history", "url.history")}, + CHROME: {Name: "chrome", Help: "浏览器", Value: kit.Data( + kit.MDB_SHORT, "name", web.FAVOR, "url.history", + )}, }, Commands: map[string]*ice.Command{ + "/crx": {Name: "/crx", Help: "/crx", Action: map[string]*ice.Action{ + "history": {Name: "history", Help: "历史记录", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", "insert", "name", arg[1], "note", arg[2], + "tab", m.Conf(CHROME, "meta.favor"), "sid", m.Option("sid")) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + "/favor": {Name: "/favor", Help: "收藏", Action: map[string]*ice.Action{ + mdb.INSERT: {Name: "insert", Help: "插入", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(web.FAVOR, mdb.INSERT, m.Option("tab"), web.SPIDE, m.Option("name"), m.Option("note")) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, - "chrome": {Name: "chrome", Help: "浏览器", List: kit.List( + CHROME: {Name: "chrome", Help: "浏览器", List: kit.List( kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "text", "name", "wid", "action", "auto", kit.MDB_INPUT, "text", "name", "url", @@ -76,48 +93,6 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器", // 下发命令 m.Cmdy(web.SPACE, arg[0], "bookmark", arg[1:]) }}, - - web.LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Option("you", "") - m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) { - // 查找空间 - m.Option("you", value["you"]) - }) - - m.Info("%s %s cmd: %v sub: %v", m.Option("you"), m.Option(ice.MSG_USERURL), m.Optionv("cmds"), m.Optionv("sub")) - }}, - "/help": {Name: "/help", Help: "帮助", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("help") - }}, - "/login": {Name: "/login", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("login", "init", c.Name) - }}, - "/logout": {Name: "/logout", Help: "登出", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmdy("login", "exit") - }}, - - "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 { - // 添加收藏 - web.FavorInsert(m, m.Option("tab"), web.TYPE_SPIDE, m.Option("note"), arg[0]) - return - } - }}, - - "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - switch arg[0] { - case "login": - m.Cmdy(web.SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid")) - - case "bookmark": - m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3], - "tab", kit.Select(m.Conf("chrome", "meta.history"), arg, 4), "sid", m.Option("sid"), "type", "spide") - - case "history": - m.Cmdy(web.SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3], - "tab", m.Conf("chrome", "meta.history"), "sid", m.Option("sid")) - } - }}, }, }