diff --git a/base/web/cache.go b/base/web/cache.go index 76de0996..cecf6491 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -121,7 +121,7 @@ func init() { }}, DOWNLOAD: {Name: "download type name*", Hand: func(m *ice.Message, arg ...string) { if r, ok := m.Optionv(RESPONSE).(*http.Response); !m.Warn(!ok, ice.ErrNotValid, RESPONSE) { - file, size := _cache_catch(m, _cache_download(m, r, path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ)), nil)) + file, size := _cache_catch(m, _cache_download(m, r, path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ)), m.OptionCB(""))) _cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size) } }}, @@ -188,6 +188,9 @@ func Upload(m *ice.Message) []string { return up } } +func Download(m *ice.Message, link string, cb func(count, total, value int)) *ice.Message { + return m.Cmdy("web.spide", ice.DEV, SPIDE_CACHE, http.MethodGet, link, cb) +} func PushDisplay(m *ice.Message, mime, name, link string) { if strings.HasPrefix(mime, "image/") || kit.ExtIsImage(name) { m.PushImages(nfs.FILE, link) diff --git a/base/web/spide.go b/base/web/spide.go index 643b4cb0..2cf885b3 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -200,7 +200,7 @@ func _spide_save(m *ice.Message, format, file, uri string, res *http.Response) { case SPIDE_SAVE: _cache_download(m, res, file, m.OptionCB(SPIDE)) case SPIDE_CACHE: - m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri, kit.Dict(RESPONSE, res)) + m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri, kit.Dict(RESPONSE, res), m.OptionCB(SPIDE)) m.Echo(m.Append(mdb.HASH)) default: var data ice.Any diff --git a/conf.go b/conf.go index 4c1a6665..630f5ca8 100644 --- a/conf.go +++ b/conf.go @@ -206,6 +206,7 @@ const ( // RENDER RENDER_QRCODE = "_qrcode" RENDER_IMAGES = "_images" RENDER_VIDEOS = "_videos" + RENDER_AUDIOS = "_audios" RENDER_IFRAME = "_iframe" RENDER_SCRIPT = "_script" diff --git a/misc.go b/misc.go index 4287a780..fb6f309a 100644 --- a/misc.go +++ b/misc.go @@ -272,7 +272,8 @@ func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) return c._action(m, cmd, key, arg[1], h, arg[2:]...) } } - if len(arg) > 0 && arg[0] != COMMAND { + // if len(arg) > 0 && arg[0] != COMMAND { + if len(arg) > 0 { if h, ok := cmd.Actions[arg[0]]; ok { return c._action(m, cmd, key, arg[0], h, arg[1:]...) } diff --git a/misc/chrome/cache.go b/misc/chrome/cache.go index e420c4e8..c1b35f5b 100644 --- a/misc/chrome/cache.go +++ b/misc/chrome/cache.go @@ -1,7 +1,6 @@ package chrome import ( - "net/http" "path" "shylinux.com/x/ice" @@ -14,31 +13,30 @@ import ( type cache struct { ice.Hash daemon - short string `data:"link"` field string `data:"show,count,total,value,hash,type,name,link"` - path string `data:"usr/local/image"` + path string `data:"usr/local/image/"` list string `name:"list hash auto prunes" help:"缓存"` } -func (c cache) Create(m *ice.Message, arg ...string) *ice.Message { - if c.Hash.List(m, m.Option(mdb.LINK)); m.Length() > 0 { - return m // 已经下载 +func (s cache) Create(m *ice.Message, arg ...string) *ice.Message { + if s.Hash.List(m, m.Option(mdb.LINK)); m.Length() > 0 { + return m } - // h = c.Hash.Create(m.Spawn(), m.OptionSimple("show,type,name,link")...).Result() - // m.Option(mdb.HASH, h) - msg := m.Cmd("web.spide", ice.DEV, web.SPIDE_CACHE, http.MethodGet, m.Option(mdb.LINK), func(count, total, value int) { - c.Hash.Modify(m, kit.Simple(mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, kit.Format(value))...) + m.Option(mdb.HASH, s.Hash.Create(m.Spawn(), m.OptionSimple("show,type,name,link")...)) + web.Download(m.Message, m.Option(mdb.LINK), func(count, total, value int) { + s.Hash.Modify(m, kit.Simple(mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, value)...) }) - m.Cmdy(nfs.LINK, path.Join(m.Config(nfs.PATH), m.Option(mdb.NAME)), msg.Append(nfs.FILE)) + name := kit.Keys(path.Base(m.Append(nfs.FILE)), path.Base(m.Append(mdb.TYPE))) + m.Cmdy(nfs.LINK, path.Join(m.Config(nfs.PATH), name), m.Append(nfs.FILE)) + s.Hash.Modify(m, mdb.NAME, name) web.ToastSuccess(m.Message) return m } -func (c cache) Prunes(m *ice.Message, arg ...string) { - c.Hash.Prunes(m, mdb.VALUE, "100") +func (s cache) Prunes(m *ice.Message, arg ...string) { + s.Hash.Prunes(m, mdb.VALUE, "100") } -func (c cache) List(m *ice.Message, arg ...string) { - c.Hash.List(m, arg...) +func (s cache) List(m *ice.Message, arg ...string) { + s.Hash.List(m, arg...) } - func init() { ice.CodeCtxCmd(cache{}) } diff --git a/misc/chrome/change.go b/misc/chrome/change.go deleted file mode 100644 index 6c5fe4c8..00000000 --- a/misc/chrome/change.go +++ /dev/null @@ -1,45 +0,0 @@ -package chrome - -import ( - "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/core/wiki" - kit "shylinux.com/x/toolkits" -) - -type change struct { - ice.Hash - daemon - - short string `data:"property"` - list string `name:"list wid tid selector:text@key property:textarea@key auto export import" help:"编辑"` -} - -func (c change) Inputs(m *ice.Message, arg ...string) { - switch arg[0] { - case SELECTOR: - m.Push(arg[0], wiki.VIDEO) - fallthrough - default: - c.Hash.Inputs(m, arg...) - } -} -func (c change) List(m *ice.Message, arg ...string) { - if len(arg) < 2 || arg[2] == "" { - c.send(m, kit.Slice(arg, 0, 2)) - return - } - c.send(m.Spawn(), kit.Slice(arg, 0, 2), m.CommandKey(), kit.Slice(arg, 2)).Tables(func(value ice.Maps) { - m.Push(mdb.TEXT, kit.ReplaceAll(value[mdb.TEXT], "<", "<", ">", ">")) - }) - if len(arg) > 3 { - c.Hash.Create(m, SELECTOR, arg[2], PROPERTY, arg[3]) - } -} - -const ( - SELECTOR = "selector" - PROPERTY = "property" -) - -func init() { ice.CodeCtxCmd(change{}) } diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index b6981262..59801d13 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -1,8 +1,6 @@ package chrome -import ( - "shylinux.com/x/ice" -) +import "shylinux.com/x/ice" type chrome struct { ice.Code @@ -10,8 +8,7 @@ type chrome struct { list string `name:"list path auto order build download" help:"源码"` } -func (c chrome) List(m *ice.Message, arg ...string) { - c.Code.Source(m, "", arg...) +func (s chrome) List(m *ice.Message, arg ...string) { + s.Code.Source(m, "", arg...) } - func init() { ice.CodeCtxCmd(chrome{}) } diff --git a/misc/chrome/chrome.shy b/misc/chrome/chrome.shy index 7d1cc43c..a32c7761 100644 --- a/misc/chrome/chrome.shy +++ b/misc/chrome/chrome.shy @@ -9,7 +9,15 @@ refer ` chapter "安装" field "浏览器" web.code.chrome.chrome -field "操作流" web.code.chrome.operate +field "浏览器" web.code.chrome.daemon +field "蜘蛛侠" web.code.chrome.spide +field "缓存池" web.code.chrome.cache +field "相册簿" web.wiki.feel +return + +field "工具箱" web.code.chrome.field +field "样式表" web.code.chrome.style + field "编辑器" web.code.chrome.change chapter "应用" @@ -17,13 +25,8 @@ field "同步流" web.code.chrome.sync field "收藏夹" web.code.chrome.favor field "定制化" web.code.chrome.page -field "样式表" web.code.chrome.style -field "工具箱" web.code.chrome.field field "播放器" web.code.chrome.video -field "蜘蛛侠" web.code.chrome.spide -field "缓存池" web.code.chrome.cache -field "相册簿" web.wiki.feel chapter "源码" field "源代码" web.code.inner args `usr/icebergs/misc/chrome/ chrome.go` diff --git a/misc/chrome/daemon.go b/misc/chrome/daemon.go index 6180820e..74ac7f52 100644 --- a/misc/chrome/daemon.go +++ b/misc/chrome/daemon.go @@ -2,65 +2,36 @@ package chrome import ( "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/web" - "shylinux.com/x/icebergs/core/wiki" kit "shylinux.com/x/toolkits" ) -type daemon struct { - reload string `name:"reload" help:"刷新"` - list string `name:"list wid tid url auto" help:"操作"` -} - -func (s daemon) send(m *ice.Message, arg ...ice.Any) *ice.Message { - return m.Cmdy(web.SPACE, "chrome", "chrome", arg) -} - -func (s daemon) Inputs(m *ice.Message, arg ...string) { - switch arg[0] { - case mdb.ZONE: - s.send(m.Spawn()).Tables(func(value ice.Maps) { - s.send(m.Spawn(), value[WID]).Tables(func(value ice.Maps) { m.Push(mdb.ZONE, kit.ParseURL(value[URL]).Host) }) - }).Sort(mdb.ZONE) - } -} -func (s daemon) Spide(m *ice.Message, arg ...string) { - if len(arg) < 2 { - s.send(m, arg) - return - } - s.send(m, arg[:2], "spide").Tables(func(value ice.Maps) { - switch value[mdb.TYPE] { - case wiki.VIDEO: - m.PushVideos(mdb.SHOW, value[mdb.LINK]) - case wiki.IMG: - m.PushImages(mdb.SHOW, value[mdb.LINK]) - default: - m.Push(mdb.SHOW, "") - } - }).Cut("show,type,name,link") -} -func (s daemon) Reload(m *ice.Message, arg ...string) { - s.send(m, arg[:2], "user.reload", ice.TRUE).ProcessHold() -} -func (s daemon) List(m *ice.Message, arg ...string) { - switch len(arg) { - case 3: - s.send(m, arg[:2], "user.jumps", arg[2]) - case 2: - s.Spide(m, arg...) - m.Action(s.Reload) - default: - s.send(m, arg) - } - m.StatusTimeCount() -} - const ( WID = "wid" TID = "tid" URL = "url" ) +type daemon struct { + list string `name:"list wid tid url auto" help:"后台"` +} + +func (s daemon) send(m *ice.Message, arg ...ice.Any) *ice.Message { + return m.Cmdy(web.SPACE, "chrome", "chrome", arg) +} +func (s daemon) Inputs(m *ice.Message, arg ...string) { + switch arg[0] { + case web.DOMAIN: + s.send(m.Spawn()).Tables(func(value ice.Maps) { + s.send(m.Spawn(), value[WID]).Tables(func(value ice.Maps) { m.Push(arg[0], kit.ParseURL(value[URL]).Host) }) + }).Sort(arg[0]) + } +} +func (s daemon) List(m *ice.Message, arg ...string) { + if len(arg) < 2 || arg[0] == "" || arg[1] == "" { + s.send(m, arg).StatusTimeCount() + } else { + s.send(m, arg[:2], "user.jumps", arg[2]) + } +} func init() { ice.CodeCtxCmd(daemon{}) } diff --git a/misc/chrome/favor.go b/misc/chrome/favor.go deleted file mode 100644 index 643669bb..00000000 --- a/misc/chrome/favor.go +++ /dev/null @@ -1,20 +0,0 @@ -package chrome - -import ( - "shylinux.com/x/ice" -) - -type favor struct { - ice.Zone - short string `data:"zone"` - field string `data:"time,id,type,name,link"` - insert string `name:"insert zone*=官网文档 type name=hi link=*hello"` - list string `name:"list zone id auto insert" help:"收藏"` -} - -func (f favor) List(m *ice.Message, arg ...string) { - if f.Zone.List(m, arg...); len(arg) == 0 { - m.Action(f.Export, f.Import) - } -} -func init() { ice.CodeCtxCmd(favor{}) } diff --git a/misc/chrome/field.go b/misc/chrome/field.go index a4b3c26b..30e58f8b 100644 --- a/misc/chrome/field.go +++ b/misc/chrome/field.go @@ -4,42 +4,39 @@ import ( "shylinux.com/x/ice" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/tcp" + "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) type field struct { ice.Zone daemon - - short string `data:"zone"` + short string `data:"domain"` field string `data:"time,id,index,args,style,left,top,right,bottom,selection"` - insert string `name:"insert zone=golang.google.cn index=cli.system args=pwd"` - list string `name:"list zone id auto insert" help:"插件"` + insert string `name:"insert domain=golang.google.cn index=cli.system args=pwd"` + list string `name:"list domain id auto insert" help:"插件"` } -func (f field) Inputs(m *ice.Message, arg ...string) { - f.daemon.Inputs(m, arg...) +func (s field) Inputs(m *ice.Message, arg ...string) { + s.daemon.Inputs(m, arg...) } -func (f field) Command(m *ice.Message, arg ...string) { - m.OptionFields("") - f.Zone.List(m.Spawn(), kit.Simple(m.Option(tcp.HOST), arg)...).Table(func(index int, value ice.Maps, head []string) { +func (s field) Command(m *ice.Message, arg ...string) { + s.Zone.List(m.Spawn(), kit.Simple(m.Option(web.DOMAIN), arg)...).Table(func(index int, value ice.Maps, head []string) { if len(arg) == 0 { - m.Option(ice.MSG_OPTS, head) - m.Options(kit.Simple(value)) - f.send(m.Spawn(), "1", m.Option(TID), m.CommandKey(), value[mdb.ID], value[ctx.ARGS]) + m.Options(ice.MSG_OPTS, head, kit.Simple(value)) + s.send(m, "1", m.Option(TID), m.CommandKey(), value[mdb.ID], value[ctx.ARGS]) } else { + m.OptionFields("") m.Cmdy(ctx.COMMAND, value[mdb.INDEX]) } }) } -func (f field) Run(m *ice.Message, arg ...string) { - f.Zone.List(m.Spawn(), m.Option(tcp.HOST), arg[0]).Tables(func(value ice.Maps) { +func (s field) Run(m *ice.Message, arg ...string) { + s.Zone.List(m.Spawn(), m.Option(web.DOMAIN), arg[0]).Tables(func(value ice.Maps) { m.Cmdy(value[mdb.INDEX], arg[1:]) }) } -func (f field) List(m *ice.Message, arg ...string) { - f.Zone.List(m, arg...) +func (s field) List(m *ice.Message, arg ...string) { + s.Zone.List(m, arg...) } - func init() { ice.CodeCtxCmd(field{}) } diff --git a/misc/chrome/page.go b/misc/chrome/page.go index c62d54c0..43fdcdb9 100644 --- a/misc/chrome/page.go +++ b/misc/chrome/page.go @@ -2,26 +2,25 @@ package chrome import ( "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web" ) type page struct { daemon style field - - list string `name:"list zone auto" help:"网页" http:"/page"` + list string `name:"list domain auto" help:"网页" http:"/page"` } -func (p page) Command(m *ice.Message, arg ...string) { - m.Cmdy(p.style.Command, arg) - m.Cmdy(p.field.Command, arg) +func (s page) Command(m *ice.Message, arg ...string) { + if m.Cmdy(s.field, s.field.Command, arg); len(arg) == 0 { + m.Cmd(s.style, s.style.Command, arg) + } } -func (p page) Run(m *ice.Message, arg ...string) { - m.Cmdy(p.field.Run, arg) +func (s page) Run(m *ice.Message, arg ...string) { + m.Cmdy(s.field, s.Run, arg) } -func (p page) List(m *ice.Message, arg ...string) { - p.daemon.Inputs(m, mdb.ZONE) +func (s page) List(m *ice.Message, arg ...string) { + s.daemon.Inputs(m, web.DOMAIN) } - func init() { ice.CodeCtxCmd(page{}) } diff --git a/misc/chrome/spide.go b/misc/chrome/spide.go index 0d431c47..a79e13b7 100644 --- a/misc/chrome/spide.go +++ b/misc/chrome/spide.go @@ -2,22 +2,34 @@ package chrome import ( "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/core/wiki" ) type spide struct { cache - - download string `name:"download" help:"下载"` - list string `name:"list wid tid url auto insert" help:"节点"` + list string `name:"list wid tid url auto insert" help:"节点"` } func (s spide) Download(m *ice.Message, arg ...string) { m.Cmdy(s.cache.Create, arg).ProcessHold() } func (s spide) List(m *ice.Message, arg ...string) { - if s.Spide(m, arg...); len(arg) > 1 { - m.PushAction(s.Download) + if len(arg) < 2 || arg[0] == "" || arg[1] == "" { + s.daemon.List(m, arg...) + return } + s.send(m, arg[:2], "spide").Tables(func(value ice.Maps) { + switch value[mdb.TYPE] { + case wiki.AUDIO: + m.PushAudios(mdb.SHOW, value[mdb.LINK]) + case wiki.VIDEO: + m.PushVideos(mdb.SHOW, value[mdb.LINK]) + case wiki.IMG: + m.PushImages(mdb.SHOW, value[mdb.LINK]) + default: + m.Push(mdb.SHOW, "") + } + }).Cut("show,type,name,link").PushAction(s.Download) } - func init() { ice.CodeCtxCmd(spide{}) } diff --git a/misc/chrome/style.go b/misc/chrome/style.go index 597ec1d4..1807a137 100644 --- a/misc/chrome/style.go +++ b/misc/chrome/style.go @@ -2,29 +2,32 @@ package chrome import ( "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/tcp" + "shylinux.com/x/icebergs/base/web" +) + +const ( + SELECTOR = "selector" + PROPERTY = "property" ) type style struct { ice.Zone daemon - - short string `data:"zone"` + short string `data:"domain"` field string `data:"time,id,selector,property"` - insert string `name:"insert zone=golang.google.cn selector=. property:textarea"` - list string `name:"style zone id auto insert" help:"样式"` + insert string `name:"insert domain=golang.google.cn selector=. property:textarea"` + list string `name:"style domain id auto insert" help:"样式"` } func (s style) Inputs(m *ice.Message, arg ...string) { s.daemon.Inputs(m, arg...) } func (s style) Command(m *ice.Message, arg ...string) { - s.Zone.List(m, m.Option(tcp.HOST)).Tables(func(value ice.Maps) { + s.Zone.List(m, m.Option(web.DOMAIN)).Tables(func(value ice.Maps) { s.send(m, "1", m.Option(TID), m.CommandKey(), value[SELECTOR], value[PROPERTY]) }) } func (s style) List(m *ice.Message, arg ...string) { s.Zone.List(m, arg...) } - func init() { ice.CodeCtxCmd(style{}) } diff --git a/misc/chrome/sync.go b/misc/chrome/sync.go index 15471cd6..eaf6bb1f 100644 --- a/misc/chrome/sync.go +++ b/misc/chrome/sync.go @@ -3,13 +3,10 @@ package chrome import ( "shylinux.com/x/ice" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/web" ) type sync struct { ice.Lists - favor `name:"favor zone=some type name link"` - field string `data:"time,id,type,name,link"` insert string `name:"insert type name link" http:"/sync"` list string `name:"list id auto" help:"同步流"` @@ -18,7 +15,7 @@ type sync struct { func (s sync) Inputs(m *ice.Message, arg ...string) { switch arg[0] { case mdb.ZONE: - m.Cmdy(s.favor.Inputs, arg) + m.Cmdy(arg) default: m.Cmdy(s.Lists.Inputs, arg) } @@ -26,13 +23,7 @@ func (s sync) Inputs(m *ice.Message, arg ...string) { func (s sync) Insert(m *ice.Message, arg ...string) { s.Lists.Insert(m, arg...) } -func (s sync) Favor(m *ice.Message, arg ...string) { - m.Cmdy(s.favor.Insert, m.OptionSimple("zone,type,name,link")) - web.ToastSuccess(m.Message) -} func (s sync) List(m *ice.Message, arg ...string) { s.Lists.List(m, arg...) - m.PushAction(s.Favor) } - func init() { ice.CodeCtxCmd(sync{}) } diff --git a/misc/chrome/video.go b/misc/chrome/video.go deleted file mode 100644 index 6c48cc07..00000000 --- a/misc/chrome/video.go +++ /dev/null @@ -1,21 +0,0 @@ -package chrome - -import ( - "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/ctx" -) - -type video struct { - daemon - - play string `name:"play" help:"播放"` - next string `name:"next" help:"下一集"` - list string `name:"list tags='ul.stui-content__playlist.column10.clearfix li a' rate=1.5 skip=140 next=2520 auto play next" help:"操作"` -} - -func (v video) List(m *ice.Message, arg ...string) { - ctx.DisplayStory(m.Message, "video.js") - m.Echo("hello world") -} - -func init() { ice.CodeCtxCmd(video{}) } diff --git a/render.go b/render.go index 7571198e..1527bcda 100644 --- a/render.go +++ b/render.go @@ -192,6 +192,11 @@ func (m *Message) PushVideos(key, src string) { m.Push(key, Render(m, RENDER_VIDEOS, src)) } } +func (m *Message) PushAudios(key, src string) { + if !m.IsCliUA() { + m.Push(key, Render(m, RENDER_AUDIOS, src)) + } +} func (m *Message) PushIFrame(key, src string) { if !m.IsCliUA() { m.Push(key, Render(m, RENDER_IFRAME, src))