diff --git a/conf.go b/conf.go index f2814a37..9ccc9420 100644 --- a/conf.go +++ b/conf.go @@ -24,6 +24,7 @@ const ( // DIR USR_VOLCANOS = "usr/volcanos" USR_INTSHELL = "usr/intshell" USR_PUBLISH = "usr/publish" + USR_LOCAL = "usr/local" PROTO_JS = "proto.js" FRAME_JS = "frame.js" diff --git a/core/wiki/data.go b/core/wiki/data.go index ba425484..cb736da5 100644 --- a/core/wiki/data.go +++ b/core/wiki/data.go @@ -15,7 +15,7 @@ const DATA = "data" func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - DATA: {Name: DATA, Help: "数据表格", Value: kit.Data(kit.MDB_PATH, "usr/local/export", "regs", ".*\\.csv")}, + DATA: {Name: DATA, Help: "数据表格", Value: kit.Data(kit.MDB_PATH, "usr/local/export", kit.MDB_REGEXP, ".*\\.csv")}, }, Commands: map[string]*ice.Command{ DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict( diff --git a/core/wiki/draw.go b/core/wiki/draw.go index c75aa56e..93c7a5bb 100644 --- a/core/wiki/draw.go +++ b/core/wiki/draw.go @@ -13,7 +13,7 @@ const DRAW = "draw" func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(kit.MDB_PATH, "", "regs", ".*\\.svg")}, + DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.svg")}, }, Commands: map[string]*ice.Command{ DRAW: {Name: "draw path=src/ file=main.svg 刷新:button=auto 编辑 save 项目 参数", Help: "思维导图", Meta: kit.Dict( diff --git a/core/wiki/feel.go b/core/wiki/feel.go index 648dda99..8c37d69a 100644 --- a/core/wiki/feel.go +++ b/core/wiki/feel.go @@ -12,7 +12,7 @@ func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data( - kit.MDB_PATH, "usr/local/image", "regs", ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)", + kit.MDB_PATH, "usr/local/image", kit.MDB_REGEXP, ".*.(png|PNG|jpg|JPG|jpeg|mp4|m4v|MOV)", )}, }, Commands: map[string]*ice.Command{ @@ -23,8 +23,7 @@ func init() { _wiki_upload(m, FEEL, m.Option(kit.MDB_PATH)) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if !_wiki_list(m, FEEL, kit.Select("./", arg, 0)) { - } + _wiki_list(m, FEEL, kit.Select("./", arg, 0)) }}, }, }) diff --git a/core/wiki/image.go b/core/wiki/image.go new file mode 100644 index 00000000..eb9ca2c7 --- /dev/null +++ b/core/wiki/image.go @@ -0,0 +1,49 @@ +package wiki + +import ( + "path" + "strings" + + ice "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/mdb" + kit "github.com/shylinux/toolkits" +) + +var image = `` + +func _image_show(m *ice.Message, name, text string, arg ...string) { + if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { + text = path.Join("/share/local", _wiki_path(m, FEEL, text)) + } + + _option(m, IMAGE, name, text, arg...) + m.Render(ice.RENDER_TEMPLATE, m.Conf(IMAGE, kit.Keym(kit.MDB_TEMPLATE))) +} + +const ( + PNG = "png" + JPG = "jpg" + JPEG = "jpeg" +) +const IMAGE = "image" + +func init() { + Index.Merge(&ice.Context{ + Configs: map[string]*ice.Config{ + IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(kit.MDB_TEMPLATE, image)}, + }, + Commands: map[string]*ice.Command{ + IMAGE: {Name: "image [name] url", Help: "图片", Action: map[string]*ice.Action{ + mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { + _image_show(m, arg[1], path.Join(arg[2], arg[1])) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + arg = _name(m, arg) + _image_show(m, arg[0], arg[1], arg[2:]...) + }}, + }, + }) +} diff --git a/core/wiki/template.go b/core/wiki/template.go index d931f2f9..d0517a70 100644 --- a/core/wiki/template.go +++ b/core/wiki/template.go @@ -41,10 +41,6 @@ var local = `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}` -var image = `` var chart = ` ` var other = `` - -var video = `` diff --git a/core/wiki/video.go b/core/wiki/video.go index 1370aa64..12b5c4b1 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -1,41 +1,49 @@ package wiki import ( + "path" + "strings" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/mdb" kit "github.com/shylinux/toolkits" ) +var video = `` + func _video_show(m *ice.Message, name, text string, arg ...string) { + if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { + text = path.Join("/share/local", _wiki_path(m, FEEL, text)) + } + _option(m, VIDEO, name, text, arg...) m.Render(ice.RENDER_TEMPLATE, m.Conf(VIDEO, kit.Keym(kit.MDB_TEMPLATE))) } -func _video_search(m *ice.Message, kind, name, text string) { - if kit.Contains(kind, "*") || kit.Contains(kind, VIDEO) { - m.PushSearchWeb(VIDEO, name) - } -} + +const ( + mp4 = "mp4" + m4v = "m4v" + MOV = "mov" +) const VIDEO = "video" func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ - VIDEO: {Name: "video", Help: "视频", Value: kit.Data( - kit.MDB_SHORT, kit.MDB_TEXT, kit.MDB_TEMPLATE, video, - )}, + VIDEO: {Name: "video", Help: "视频", Value: kit.Data(kit.MDB_TEMPLATE, video)}, }, Commands: map[string]*ice.Command{ VIDEO: {Name: "video [name] url", Help: "视频", Action: map[string]*ice.Action{ - mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - _video_search(m, arg[0], arg[1], arg[2]) - }}, - mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) { - m.Cmd(mdb.INSERT, m.Prefix(VIDEO), "", mdb.HASH, arg) + mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { + _video_show(m, arg[1], path.Join(arg[2], arg[1])) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { arg = _name(m, arg) - _video_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) + _video_show(m, arg[0], arg[1], arg[2:]...) }}, }}) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index c22c20da..8258c0d2 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -16,7 +16,7 @@ func _wiki_path(m *ice.Message, cmd string, arg ...string) string { } func _wiki_list(m *ice.Message, cmd string, arg ...string) bool { - m.Option("prefix", m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))) + m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd)) if len(arg) == 0 || strings.HasSuffix(arg[0], "/") { if m.Option(nfs.DIR_DEEP) != "true" { // 目录列表 @@ -26,7 +26,6 @@ func _wiki_list(m *ice.Message, cmd string, arg ...string) bool { // 文件列表 m.Option(nfs.DIR_TYPE, nfs.CAT) - m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs")) m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time,size,path") return true } @@ -43,9 +42,12 @@ func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) { func _wiki_upload(m *ice.Message, cmd string, dir string) { up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)) if p := _wiki_path(m, cmd, dir, up[1]); m.Option(ice.MSG_USERPOD) == "" { + // 本机文件 m.Cmdy(web.CACHE, web.WATCH, up[0], p) } else { - m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_SAVE, p, web.SPIDE_GET, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0])) + // 下发文件 + m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_SAVE, p, web.SPIDE_GET, + kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/share/cache", up[0]))) } } @@ -54,10 +56,12 @@ const WIKI = "wiki" 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.Cmd(mdb.RENDER, mdb.CREATE, "png", m.Prefix(IMAGE)) + m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE)) m.Load() }}, - ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() }}, + ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Save() + }}, }, } diff --git a/core/wiki/word.go b/core/wiki/word.go index 2ae6ee79..927e0f43 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -158,18 +158,6 @@ func _local_show(m *ice.Message, name, text string, arg ...string) { m.Render(ice.RENDER_TEMPLATE, m.Conf(LOCAL, kit.Keym(kit.MDB_TEMPLATE))) } -func _image_show(m *ice.Message, name, text string, arg ...string) { - if name == "qrcode" { - m.EchoQRCode(text) - return - } - if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { - text = "/share/local/usr/local/image/" + text - } - - _option(m, IMAGE, name, text, arg...) - m.Render(ice.RENDER_TEMPLATE, m.Conf(IMAGE, kit.Keym(kit.MDB_TEMPLATE))) -} func _chart_show(m *ice.Message, kind, name, text string, arg ...string) { var chart Chart switch kind { @@ -304,7 +292,6 @@ const ( SHELL = "shell" LOCAL = "local" - IMAGE = "image" CHART = "chart" FIELD = "field" OTHER = "other" @@ -335,13 +322,12 @@ func init() { SHELL: {Name: SHELL, Help: "命令", Value: kit.Data(kit.MDB_TEMPLATE, shell)}, LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data(kit.MDB_TEMPLATE, local)}, - IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(kit.MDB_TEMPLATE, image)}, CHART: {Name: CHART, Help: "图表", Value: kit.Data(kit.MDB_TEMPLATE, chart, "suffix", ``)}, FIELD: {Name: FIELD, Help: "插件", Value: kit.Data(kit.MDB_TEMPLATE, field)}, OTHER: {Name: FIELD, Help: "网页", Value: kit.Data(kit.MDB_TEMPLATE, other)}, WORD: {Name: WORD, Help: "语言文字", Value: kit.Data( - kit.MDB_PATH, "", "regs", ".*\\.shy", "alias", map[string]interface{}{ + kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.shy", "alias", map[string]interface{}{ PREMENU: []interface{}{TITLE, PREMENU}, CHAPTER: []interface{}{TITLE, CHAPTER}, SECTION: []interface{}{TITLE, SECTION}, @@ -398,15 +384,6 @@ func init() { _local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) }}, - IMAGE: {Name: "image [name] url", Help: "图片", Action: map[string]*ice.Action{ - mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { - _image_show(m, arg[1], path.Join(arg[2], arg[1])) - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - arg = _name(m, arg) - _image_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) - m.Render("") - }}, CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 2 { arg = []string{arg[0], "", arg[1]} diff --git a/go.sum b/go.sum index 598479b8..043b0fdc 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,11 @@ github.com/AaronO/go-git-http v0.0.0-20161214145340-1d9485b3a98f/go.mod h1:+6Yuq73F9068Na+mSBNXCvyuxvgw4f/g5ii40e3U8Sc= github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII= github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk= +github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= diff --git a/misc.go b/misc.go index 4736ff0f..517f53bd 100644 --- a/misc.go +++ b/misc.go @@ -110,12 +110,15 @@ func (m *Message) PushSearchWeb(cmd string, name string) { }) } -func (m *Message) IsTermUA() bool { - return m.Option(MSG_USERUA) == "" || strings.Contains(m.Option(MSG_USERUA), "curl") +func (m *Message) IsCliUA() bool { + if m.Option(MSG_USERUA) == "" || !strings.HasPrefix(m.Option(MSG_USERUA), "Mozilla/5.0") { + return true + } + return false } func Render(m *Message, cmd string, args ...interface{}) string { - if m.IsTermUA() { + if m.IsCliUA() { switch arg := kit.Simple(args...); cmd { case RENDER_QRCODE: // text [size] return m.Cmdx("cli.qrcode", arg[0]) @@ -186,13 +189,13 @@ func (m *Message) PushDownload(key string, arg ...interface{}) { // [name] file m.Push(key, Render(m, RENDER_DOWNLOAD, arg...)) } func (m *Message) PushAnchor(arg ...interface{}) { // [name] link - if m.IsTermUA() { + if m.IsCliUA() { return } m.Push(kit.MDB_LINK, Render(m, RENDER_ANCHOR, arg...)) } func (m *Message) PushButton(arg ...string) { - if m.IsTermUA() { + if m.IsCliUA() { return } m.Push(kit.MDB_ACTION, Render(m, RENDER_BUTTON, strings.Join(arg, ","))) diff --git a/misc/wx/wx.shy b/misc/wx/wx.shy index d4df6825..3766d0bc 100644 --- a/misc/wx/wx.shy +++ b/misc/wx/wx.shy @@ -1,3 +1,10 @@ +qrcode hi +image `qrcode_for_gh_1c21ed4eb46b_258.jpg` +video `shg_1137499128_1047_36a6fc44db4a4100b7087e98c89bvide_f30.mp4` +field feel + +return + title "微信公众号" refer ` 官网 https://weixin.qq.com/ @@ -5,7 +12,6 @@ refer ` 文档 https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html 源码 https://github.com/shylinux/icebergs/blob/master/misc/wx/wx.go ` -image `qrcode_for_gh_1c21ed4eb46b_258.jpg` chapter "应用" field scan web.chat.scan