1
0
forked from x/icebergs

opt dream

This commit is contained in:
shaoying 2020-09-14 21:08:18 +08:00
parent 45fef97be9
commit 9bd2783912
19 changed files with 584 additions and 362 deletions

View File

@ -128,6 +128,7 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
return
}
}
m.Push(key, val)
_hash_delete(m, prefix, chain, kit.MDB_HASH, key)
})
}

View File

@ -83,21 +83,20 @@ func init() {
"ctx_log", "bin/boot.log", "ctx_mod", "ctx,log,gdb,ssh",
),
"miss", `#!/bin/bash
git &>/dev/null || apk add git || yum install -y git
[ -f ~/.ish/plug.sh ] || [ -f ./.ish/plug.sh ] || git clone https://github.com/shylinux/intshell ./.ish
[ -f ~/.ish/plug.sh ] || [ -f ./.ish/plug.sh ] || git clone ${ISH_CONF_HUB_PROXY:="https://"}github.com/shylinux/intshell ./.ish
[ "$ISH_CONF_PRE" != "" ] || source ./.ish/plug.sh || source ~/.ish/plug.sh
# declare -f ish_help_repos &>/dev/null || require conf.sh
require show.sh
require help.sh
require miss.sh
# ish_miss_prepare_compile
# ish_miss_prepare_install
`,
)},
},
Commands: map[string]*ice.Command{
DREAM: {Name: "dream [name [cmd...]] auto", Help: "梦想家", Meta: kit.Dict("detail", []interface{}{"启动", "停止"}), Action: map[string]*ice.Action{
gdb.START: {Name: "start type name", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
m.Option(kit.MDB_NAME, kit.Select(path.Base(m.Option(kit.MDB_REPOS)), m.Option(kit.MDB_NAME)))
_dream_show(m, m.Option(kit.MDB_NAME))
}},
gdb.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {

View File

@ -55,7 +55,7 @@ func init() {
switch arg[0] {
case "cmd":
m.Cmdy(SPACE, m.Option("route"), "command")
default:
case "name":
m.Cmdy(SPACE, m.Option("route"), "dream")
}
}},

View File

@ -215,7 +215,7 @@ func init() {
)},
},
Commands: map[string]*ice.Command{
SPACE: {Name: "space [name [cmd...]] auto", Help: "空间站", Action: map[string]*ice.Action{
SPACE: {Name: "space name cmd auto", Help: "空间站", Action: map[string]*ice.Action{
"connect": {Name: "connect [dev [name]]", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
_space_dial(m, kit.Select("dev", arg, 0), kit.Select(cli.NodeName, arg, 2))
}},

View File

@ -63,6 +63,10 @@ func (m *Message) AddCmd(cmd *Command) string {
}
func (m *Message) PushRender(key, view, name string, arg ...string) *Message {
if strings.Contains(m.Option(MSG_USERUA), "curl") {
return m
}
switch view {
case "button":
list := []string{}

133
misc/chrome/cache.go Normal file
View File

@ -0,0 +1,133 @@
package crx
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"encoding/csv"
"io/ioutil"
"os"
"path"
"sort"
)
const CACHED = "cached"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
CACHED: {Name: "spided", Help: "网页爬虫", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_LINK, kit.MDB_PATH, "usr/spide",
)},
},
Commands: map[string]*ice.Command{
CACHED: {Name: "cached hash=auto auto 清理:button 导出:button", Help: "网页爬虫", Action: map[string]*ice.Action{
"download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
m.Optionv("progress", func(size int, total int) {
value["progress"], value["size"], value["total"] = size*100/total, size, total
m.Log_IMPORT(kit.MDB_FILE, m.Option("name"), "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
})
})
msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option("link"))
p := path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))
m.Cmdy(nfs.LINK, p, msg.Append("file"))
// 完成
if file, e := avutil.Open(p); m.Assert(e) {
defer file.Close()
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
if vstream.Width() > vstream.Height() {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "横屏", m.Option("name")), p)
} else {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "竖屏", m.Option("name")), p)
}
}
}
}
}
}},
"prune": {Name: "prune", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
m.Richs(CACHED, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
if kit.Int(value["progress"]) == 100 {
dir := path.Join("var/data", m.Prefix(CACHED), "")
name := path.Join(dir, kit.Keys(key, "json"))
if f, p, e := kit.Create(name); e == nil {
defer f.Close()
// 保存数据
if n, e := f.WriteString(kit.Format(value)); e == nil {
m.Log_EXPORT("file", p, kit.MDB_SIZE, n)
}
}
m.Conf(CACHED, kit.Keys(kit.MDB_HASH, key), "")
}
})
}},
"export": {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
f, p, e := kit.Create(path.Join("usr/export", m.Prefix(CACHED), "list.csv"))
m.Assert(e)
defer f.Close()
w := csv.NewWriter(f)
defer w.Flush()
count := 0
head := []string{}
m.Cmd(nfs.DIR, path.Join("var/data", m.Prefix(CACHED))+"/").Table(func(index int, v map[string]string, h []string) {
f, e := os.Open(v["path"])
m.Assert(e)
defer f.Close()
b, e := ioutil.ReadAll(f)
m.Assert(e)
value, ok := kit.UnMarshal(string(b)).(map[string]interface{})
if !ok {
return
}
if index == 0 {
// 输出表头
for k := range value {
head = append(head, k)
}
sort.Strings(head)
w.Write(head)
}
// 输出数据
data := []string{}
for _, k := range head {
data = append(data, kit.Format(value[k]))
}
w.Write(data)
count++
})
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count)
m.Echo(p)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cache.limit", 100)
m.Option("fields", "time,hash,type,progress,size,total,name,text,link")
m.Cmdy(mdb.SELECT, m.Prefix(CACHED), "", mdb.HASH)
m.Sort("time", "time_r")
m.PushAction("下载")
m.Appendv(ice.MSG_APPEND, "time", "type", "name", "text",
"action", "progress", "size", "total", "hash", "link")
}},
},
}, nil)
}

View File

@ -1,253 +1,30 @@
package crx
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/icebergs/core/code"
"github.com/shylinux/toolkits"
"encoding/csv"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"io/ioutil"
"os"
"path"
"sort"
kit "github.com/shylinux/toolkits"
)
const CHROME = "chrome"
const (
SPIDED = "spided"
CACHED = "cached"
)
var Index = &ice.Context{Name: "chrome", Help: "浏览器",
Configs: map[string]*ice.Config{
CHROME: {Name: "chrome", Help: "浏览器", Value: kit.Data(
kit.MDB_SHORT, "name", "history", "url.history",
)},
SPIDED: {Name: "spided", Help: "网页爬虫", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_LINK, kit.MDB_PATH, "usr/spide",
)},
CACHED: {Name: "spided", Help: "网页爬虫", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_LINK, kit.MDB_PATH, "usr/spide",
)},
},
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(SPIDED, CACHED)
}},
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() }},
CHROME: {Name: "chrome wid=auto url auto 编译:button 下载:button", Help: "浏览器", Action: map[string]*ice.Action{
"compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(web.SPACE, CHROME, CHROME, arg)
}},
SPIDED: {Name: "spided wid=auto tid=auto cmd auto", Help: "网页爬虫", Action: map[string]*ice.Action{
"download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
if m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
if _, e := os.Stat(path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))); e == nil {
m.Push(key, value)
}
}) != nil && len(m.Appendv("name")) > 0 {
return
}
m.Cmd(mdb.INSERT, m.Prefix(CACHED), "", mdb.HASH,
kit.MDB_LINK, m.Option("link"),
kit.MDB_TYPE, m.Option("type"),
kit.MDB_NAME, m.Option("name"),
kit.MDB_TEXT, m.Option("text"),
)
// 进度
m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
m.Optionv("progress", func(size int, total int) {
p := size * 100 / total
if p != value["progress"] {
m.Log_IMPORT(kit.MDB_FILE, m.Option("name"), "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
}
value["progress"], value["size"], value["total"] = p, size, total
})
})
// 下载
msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option("link"))
p := path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))
m.Cmdy(nfs.LINK, p, msg.Append("file"))
if file, e := avutil.Open(p); m.Assert(e) {
defer file.Close()
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
if vstream.Width() > vstream.Height() {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "横屏", m.Option("name")), p)
} else {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "竖屏", m.Option("name")), p)
}
}
}
}
}
}},
"compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Cmd(web.SPACE, CHROME, CHROME, arg)
switch kit.Select("spide", arg, 2) {
case "cache":
m.Option("fields", "time,type,progress,size,total,name,text,link")
m.Cmdy(mdb.SELECT, m.Prefix(SPIDED), "", mdb.HASH)
case "spide":
if len(arg) > 1 {
msg.PushAction("下载")
msg.Table(func(index int, value map[string]string, head []string) {
m.Push("time", value["time"])
m.Push("type", value["type"])
m.Push("action", value["action"])
m.Push("name", value["name"])
switch value["type"] {
case "img":
m.Push("text", m.Cmdx(mdb.RENDER, web.RENDER.IMG, value["text"]))
case "video":
m.Push("text", m.Cmdx(mdb.RENDER, web.RENDER.Video, value["text"]))
default:
m.Push("text", value["text"])
}
m.Push("link", value["link"])
})
break
}
fallthrough
default:
m.Copy(msg)
}
}},
CACHED: {Name: "cached hash=auto auto 清理:button 导出:button", Help: "网页爬虫", Action: map[string]*ice.Action{
"download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
m.Optionv("progress", func(size int, total int) {
value["progress"], value["size"], value["total"] = size*100/total, size, total
m.Log_IMPORT(kit.MDB_FILE, m.Option("name"), "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
})
})
msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option("link"))
p := path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))
m.Cmdy(nfs.LINK, p, msg.Append("file"))
// 完成
if file, e := avutil.Open(p); m.Assert(e) {
defer file.Close()
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
if vstream.Width() > vstream.Height() {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "横屏", m.Option("name")), p)
} else {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "竖屏", m.Option("name")), p)
}
}
}
}
}
}},
"prune": {Name: "prune", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
m.Richs(CACHED, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
if kit.Int(value["progress"]) == 100 {
dir := path.Join("var/data", m.Prefix(CACHED), "")
name := path.Join(dir, kit.Keys(key, "json"))
if f, p, e := kit.Create(name); e == nil {
defer f.Close()
// 保存数据
if n, e := f.WriteString(kit.Format(value)); e == nil {
m.Log_EXPORT("file", p, kit.MDB_SIZE, n)
}
}
m.Conf(CACHED, kit.Keys(kit.MDB_HASH, key), "")
}
})
}},
"export": {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
f, p, e := kit.Create(path.Join("usr/export", m.Prefix(CACHED), "list.csv"))
m.Assert(e)
defer f.Close()
w := csv.NewWriter(f)
defer w.Flush()
count := 0
head := []string{}
m.Cmd(nfs.DIR, path.Join("var/data", m.Prefix(CACHED))+"/").Table(func(index int, v map[string]string, h []string) {
f, e := os.Open(v["path"])
m.Assert(e)
defer f.Close()
b, e := ioutil.ReadAll(f)
m.Assert(e)
value, ok := kit.UnMarshal(string(b)).(map[string]interface{})
if !ok {
return
}
if index == 0 {
// 输出表头
for k := range value {
head = append(head, k)
}
sort.Strings(head)
w.Write(head)
}
// 输出数据
data := []string{}
for _, k := range head {
data = append(data, kit.Format(value[k]))
}
w.Write(data)
count++
})
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count)
m.Echo(p)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("cache.limit", 100)
m.Option("fields", "time,hash,type,progress,size,total,name,text,link")
m.Cmdy(mdb.SELECT, m.Prefix(CACHED), "", mdb.HASH)
m.Sort("time", "time_r")
m.PushAction("下载")
m.Appendv(ice.MSG_APPEND, "time", "type", "name", "text",
"action", "progress", "size", "total", "hash", "link")
}},
"/crx": {Name: "/crx", Help: "插件", Action: map[string]*ice.Action{
web.HISTORY: {Name: "history", Help: "历史记录", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.SPIDE, web.SPIDE_DEV, "/code/chrome/favor", "cmds", mdb.INSERT, "sid", m.Option("sid"),
"tab", m.Conf(CHROME, "meta.history"), "name", arg[1], "note", arg[2])
}},
}, 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) {
}},
},
}

View File

@ -10,8 +10,9 @@ chapter "安装"
field chrome web.code.chrome.chrome
chapter "应用"
section "收藏夹"
field favor web.favor args `[ url.history ]`
field "浏览器" web.space
field "收藏夹" web.code.chrome.favor
field "同步流" web.code.chrome.sync
section "命令行"
refer `

86
misc/chrome/favor.go Normal file
View File

@ -0,0 +1,86 @@
package crx
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits"
"strings"
)
const FAVOR = "favor"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
FAVOR: {Name: FAVOR, Help: "收藏夹", Value: kit.Data(
kit.MDB_SHORT, "topic", kit.MDB_FIELD, "time,id,type,name,text",
)},
},
Commands: map[string]*ice.Command{
FAVOR: {Name: "favor topic=auto id=auto auto 创建 导出 导入", Help: "收藏夹", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create topic", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(FAVOR), "", mdb.HASH, arg)
}},
mdb.INSERT: {Name: "insert topic=数据结构 name=hi text=hello", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Richs(m.Prefix(FAVOR), "", m.Option("topic"), func(key string, value map[string]interface{}) {
m.Cmdy(mdb.INSERT, m.Prefix(FAVOR), kit.Keys(kit.MDB_HASH, key), mdb.LIST, arg)
})
}},
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
m.Richs(m.Prefix(FAVOR), "", m.Option("topic"), func(key string, value map[string]interface{}) {
m.Cmdy(mdb.MODIFY, m.Prefix(FAVOR), kit.Keys(kit.MDB_HASH, key), mdb.LIST, kit.MDB_ID, m.Option(kit.MDB_ID), arg)
})
}},
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.DELETE, m.Prefix(FAVOR), "", mdb.HASH, "topic", m.Option("topic"))
}},
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.EXPORT, m.Prefix(FAVOR), "", mdb.HASH)
}},
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.IMPORT, m.Prefix(FAVOR), "", mdb.HASH)
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case "topic":
m.Option(mdb.FIELDS, "time,count,topic")
m.Cmdy(mdb.SELECT, m.Prefix(FAVOR), "", mdb.HASH)
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 {
m.Option(mdb.FIELDS, kit.Select(m.Conf(m.Prefix(FAVOR), kit.META_FIELD), mdb.DETAIL, len(arg) > 1))
m.Richs(m.Prefix(FAVOR), "", arg[0], func(key string, value map[string]interface{}) {
m.Cmdy(mdb.SELECT, m.Prefix(FAVOR), kit.Keys(kit.MDB_HASH, key), mdb.LIST, kit.MDB_ID, arg[1:])
})
return
}
m.Option(mdb.FIELDS, "time,count,topic")
m.Cmdy(mdb.SELECT, m.Prefix(FAVOR), "", mdb.HASH)
m.PushAction("删除")
}},
"/favor": {Name: "/favor", Help: "收藏", Action: map[string]*ice.Action{
"select": {Name: "select", Help: "主题", Hand: func(m *ice.Message, arg ...string) {
list := []string{}
m.Cmd(m.Prefix(FAVOR)).Table(func(index int, value map[string]string, head []string) {
list = append(list, value["topic"])
})
m.Render(ice.RENDER_RESULT, strings.Join(list, "\n"))
}},
"insert": {Name: "insert", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(m.Prefix(FAVOR), mdb.INSERT, "topic", m.Option("tab"),
"name", m.Option("note"), "text", m.Option("arg"), "file", m.Option("buf"), "line", m.Option("row"),
)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Render(ice.RENDER_RESULT)
m.Cmd(m.Prefix(FAVOR), m.Option("tab")).Table(func(index int, value map[string]string, head []string) {
m.Echo("%v\n", m.Option("tab")).Echo("%v:%v:%v:(%v): %v\n",
value["file"], value["line"], "1", value["name"], value["text"])
})
}},
},
}, nil)
}

114
misc/chrome/spide.go Normal file
View File

@ -0,0 +1,114 @@
package crx
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"os"
"path"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
)
const SPIDED = "spided"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
SPIDED: {Name: "spided", Help: "网页爬虫", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_LINK, kit.MDB_PATH, "usr/spide",
)},
},
Commands: map[string]*ice.Command{
SPIDED: {Name: "spided wid=auto tid=auto cmd auto", Help: "网页爬虫", Action: map[string]*ice.Action{
"download": {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
if m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
if _, e := os.Stat(path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))); e == nil {
m.Push(key, value)
}
}) != nil && len(m.Appendv("name")) > 0 {
return
}
m.Cmd(mdb.INSERT, m.Prefix(CACHED), "", mdb.HASH,
kit.MDB_LINK, m.Option("link"),
kit.MDB_TYPE, m.Option("type"),
kit.MDB_NAME, m.Option("name"),
kit.MDB_TEXT, m.Option("text"),
)
// 进度
m.Richs(CACHED, "", m.Option("link"), func(key string, value map[string]interface{}) {
m.Optionv("progress", func(size int, total int) {
p := size * 100 / total
if p != value["progress"] {
m.Log_IMPORT(kit.MDB_FILE, m.Option("name"), "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
}
value["progress"], value["size"], value["total"] = p, size, total
})
})
// 下载
msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option("link"))
p := path.Join(m.Conf(CACHED, kit.META_PATH), m.Option("name"))
m.Cmdy(nfs.LINK, p, msg.Append("file"))
if file, e := avutil.Open(p); m.Assert(e) {
defer file.Close()
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
if vstream.Width() > vstream.Height() {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "横屏", m.Option("name")), p)
} else {
m.Cmdy(nfs.LINK, path.Join(m.Conf(CACHED, kit.META_PATH), "竖屏", m.Option("name")), p)
}
}
}
}
}
}},
"compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Cmd(web.SPACE, CHROME, CHROME, arg)
switch kit.Select("spide", arg, 2) {
case "cache":
m.Option("fields", "time,type,progress,size,total,name,text,link")
m.Cmdy(mdb.SELECT, m.Prefix(SPIDED), "", mdb.HASH)
case "spide":
if len(arg) > 1 {
msg.PushAction("下载")
msg.Table(func(index int, value map[string]string, head []string) {
m.Push("time", value["time"])
m.Push("type", value["type"])
m.Push("action", value["action"])
m.Push("name", value["name"])
switch value["type"] {
case "img":
m.Push("text", m.Cmdx(mdb.RENDER, web.RENDER.IMG, value["text"]))
case "video":
m.Push("text", m.Cmdx(mdb.RENDER, web.RENDER.Video, value["text"]))
default:
m.Push("text", value["text"])
}
m.Push("link", value["link"])
})
break
}
fallthrough
default:
m.Copy(msg)
}
}},
},
}, nil)
}

64
misc/chrome/sync.go Normal file
View File

@ -0,0 +1,64 @@
package crx
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
)
const SYNC = "sync"
const SPIDE = "spide"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
SYNC: {Name: SYNC, Help: "同步流", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,id,type,name,text",
)},
},
Commands: map[string]*ice.Command{
SYNC: {Name: "sync id auto 导出 导入", Help: "同步流", Action: map[string]*ice.Action{
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.EXPORT, m.Prefix(SYNC), "", mdb.LIST)
}},
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.IMPORT, m.Prefix(SYNC), "", mdb.LIST)
}},
FAVOR: {Name: "favor topic name", Help: "收藏", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(m.Prefix(FAVOR), mdb.INSERT, kit.MDB_TOPIC, m.Option(kit.MDB_TOPIC),
kit.MDB_TYPE, SPIDE, kit.MDB_NAME, m.Option(kit.MDB_NAME), kit.MDB_TEXT, m.Option(kit.MDB_TEXT))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case kit.MDB_TOPIC:
m.Cmdy(m.Prefix(FAVOR)).Appendv(ice.MSG_APPEND, kit.MDB_TOPIC, kit.MDB_COUNT, kit.MDB_TIME)
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, kit.Select(m.Conf(SYNC, kit.META_FIELD), mdb.DETAIL, len(arg) > 0))
if len(arg) > 0 {
m.Option("cache.field", kit.MDB_ID)
m.Option("cache.value", arg[0])
} else {
defer m.PushAction("收藏")
if m.Option("_control", "page"); m.Option("cache.limit") == "" {
m.Option("cache.limit", "10")
}
}
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, m.Option("cache.field"), m.Option("cache.value"))
}},
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(SYNC), "", mdb.LIST, kit.MDB_TYPE, SPIDE, kit.MDB_NAME, m.Option("name"), kit.MDB_TEXT, m.Option("note"))
}},
"/crx": {Name: "/crx", Help: "插件", Action: map[string]*ice.Action{
web.HISTORY: {Name: "history", Help: "历史记录", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.SPIDE, web.SPIDE_SELF, "/code/chrome/sync", "name", arg[1], "note", arg[2])
// m.Cmdy(web.SPIDE, web.SPIDE_DEV, "/code/chrome/sync", "name", arg[1], "note", arg[2])
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
},
}, nil)
}

View File

@ -123,10 +123,10 @@ func _input_load(m *ice.Message, file string, libs ...string) {
continue
}
line := kit.Split(bio.Text())
if len(line) < 3 || line[2] == "0" {
if len(line) < 2 || (len(line) > 2 && line[2] == "0") {
continue
}
m.Grow(INPUT, prefix, kit.Dict(TEXT, line[0], CODE, line[1], WEIGHT, line[2]))
m.Grow(INPUT, prefix, kit.Dict(TEXT, line[0], CODE, line[1], WEIGHT, kit.Select("999999", line, 2)))
}
// 保存词库

View File

@ -1,114 +0,0 @@
" 基础函数{{{
" 变量定义
func! ShyDefine(name, value)
if !exists(a:name) | exec "let " . a:name . " = \"" . a:value . "\"" | endif
endfunc
" 后端通信
call ShyDefine("g:ctx_url", (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9020") . "/code/vim/")
fun! ShySend(cmd, arg)
if has_key(a:arg, "sub") && a:arg["sub"] != "" | let temp = tempname()
call writefile(split(a:arg["sub"], "\n"), temp, "b")
let a:arg["sub"] = "@" . temp
endif
let a:arg["pwd"] = getcwd() | let a:arg["buf"] = bufname("%") | let a:arg["row"] = line(".") | let a:arg["col"] = col(".")
let args = "" | for k in sort(keys(a:arg)) | let args = args . " -F '" . k . "=" . a:arg[k] . "' " | endfor
return system("curl -s " . g:ctx_url . a:cmd . args . " 2>/dev/null")
endfun
" }}}
" 功能函数{{{
" 数据同步
fun! ShySync(target)
if bufname("%") == "ControlP" | return | end
if a:target == "read" || a:target == "write"
call ShySend("sync", {"cmds": a:target, "arg": expand("<afile>")})
elseif a:target == "insert"
call ShySend("sync", {"cmds": a:target, "sub": getreg(".")})
elseif a:target == "exec"
call ShySend("sync", {"cmds": a:target, "arg": getcmdline()})
else
let cmd = {"bufs": "buffers", "regs": "registers", "marks": "marks", "tags": "tags", "fixs": "clist"}
call ShySend("sync", {"cmds": a:target, "sub": execute(cmd[a:target])})
endif
endfun
" 输入补全
fun! ShyInput(code)
return split(ShySend("input", {"cmds": a:code, "pre": getline("."), "row": line("."), "col": col(".")}), "\n")
endfun
fun! ShyComplete(firststart, base)
if a:firststart | let line = getline('.') | let start = col('.') - 1
" 命令位置
if match(line, '\s*ice ') >= 0 | return match(line, "ice ") | endif
" 符号位置
if line[start-1] !~ '\a' | return start - 1 | end
" 单词位置
while start > 0 && line[start - 1] =~ '\a' | let start -= 1 | endwhile
return start
endif
" 符号转换
if a:base == "," | return ["", ","] | end
if a:base == "." | return ["。", "."] | end
if a:base == "\\" | return ["、", "\\"] | end
" 单词转换
return ShyInput(a:base)
endfun
set completefunc=ShyComplete
" 收藏列表
call ShyDefine("g:favor_note", "")
fun! ShyFavor()
let tab_list = split(ShySend("favor", {"cmds": "select"}), "\n")
let tab = tab_list[inputlist(tab_list)-1]
let g:favor_note = input("note: ", g:favor_note)
call ShySend("favor", {"cmds": "insert", "tab": tab, "note": g:favor_note, "arg": getline("."), "row": getpos(".")[1], "col": getpos(".")[2]})
endfun
fun! ShyFavors()
let tab_list = split(ShySend("favor", {"cmds": "topic"}), "\n")
let tab = tab_list[inputlist(tab_list)-1]
let res = split(ShySend("favor", {"tab": tab}), "\n")
let page = "" | let note = ""
for i in range(0, len(res)-1, 2)
if res[i] != page
if note != "" | lexpr note | lopen | let note = "" | endif
execute exists(":TabooOpen")? "TabooOpen " . res[i]: "tabnew"
endif
let page = res[i] | let note .= res[i+1] . "\n"
endfor
if note != "" | lexpr note | let note = "" | endif
let view = inputlist(["列表", "默认", "垂直", "水平"])
for i in range(0, len(res)-1, 2) | if i < 5
if l:view == 4 | split | lnext | elseif l:view == 3 | vsplit | lnext | endif
endif | endfor
botright lopen | if l:view == 1 | only | endif
endfun
" 文件搜索
call ShyDefine("g:grep_dir", "./")
fun! ShyGrep(word)
let g:grep_dir = input("dir: ", g:grep_dir, "file")
" execute "grep -rn --exclude tags --exclude '*.tags' '\\<" . a:word . "\\>' " . g:grep_dir
execute "grep -rn '\\<" . a:word . "\\>' " . g:grep_dir
copen
endfun
" }}}
" 事件回调{{{
autocmd! BufReadPost * call ShySync("bufs")
autocmd! BufReadPost * call ShySync("read")
autocmd! BufWritePre * call ShySync("write")
autocmd! InsertLeave * call ShySync("insert")
autocmd! CmdlineLeave * call ShySync("exec")
"}}}
" 按键映射{{{
nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
nnoremap <C-G><C-F> :call ShyFavor()<CR>
nnoremap <C-G>f :call ShyFavors()<CR>
inoremap <C-K> <C-X><C-U>
"}}}

89
misc/vim/sess.go Normal file
View File

@ -0,0 +1,89 @@
package vim
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"fmt"
"io/ioutil"
"strings"
)
const (
SID = "sid"
ARG = "arg"
SUB = "sub"
PWD = "pwd"
PID = "pid"
)
const SESS = "sess"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
SESS: {Name: SESS, Help: "会话流", Value: kit.Data(
kit.MDB_FIELD, "time,hash,status,username,hostname,pid,pwd",
"contexts", `export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -sL $ctx_dev >$ctx_temp; source $ctx_temp`,
)},
},
Commands: map[string]*ice.Command{
SESS: {Name: "sess hash auto 清理", Help: "会话流", Action: map[string]*ice.Action{
"contexts": {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
u := kit.ParseURL(m.Option(ice.MSG_USERWEB))
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1)))
if buf, err := kit.Render(m.Conf(m.Prefix(SESS), "meta.contexts"), m); m.Assert(err) {
m.Cmdy("web.wiki.spark", "shell", string(buf))
}
}},
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.DELETE, m.Prefix(SESS), "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
}},
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.PRUNES, m.Prefix(SESS), "", mdb.HASH, kit.MDB_STATUS, "logout")
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, kit.Select(m.Conf(m.Prefix(SESS), kit.META_FIELD), mdb.DETAIL, len(arg) > 0))
m.Cmdy(mdb.SELECT, m.Prefix(SESS), "", mdb.HASH, kit.MDB_HASH, arg)
m.PushAction("删除")
}},
"/sess": {Name: "/sess", Help: "会话", Action: map[string]*ice.Action{
"logout": {Name: "logout", Help: "退出", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.MODIFY, m.Prefix(SESS), "", mdb.HASH, kit.MDB_HASH, m.Option(SID), kit.MDB_STATUS, "logout")
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Render(ice.RENDER_RESULT)
m.Option(mdb.FIELDS, m.Conf(m.Prefix(SESS), kit.META_FIELD))
if strings.TrimSpace(m.Option(SID)) == "" {
m.Option(SID, m.Cmdx(mdb.INSERT, m.Prefix(SESS), "", mdb.HASH, kit.MDB_STATUS, "login",
aaa.USERNAME, m.Option(aaa.USERNAME), aaa.HOSTNAME, m.Option(aaa.HOSTNAME), PID, m.Option(PID), PWD, m.Option(PWD)))
} else {
m.Cmdy(mdb.MODIFY, m.Prefix(SESS), "", mdb.HASH, kit.MDB_HASH, m.Option(SID), kit.MDB_STATUS, "login")
}
m.Echo(m.Option(SID))
}},
web.LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, _, e := m.R.FormFile(SUB); e == nil {
defer f.Close()
// 文件参数
if b, e := ioutil.ReadAll(f); e == nil {
m.Option(SUB, string(b))
}
}
m.Option(mdb.FIELDS, m.Conf(m.Prefix(SESS), kit.META_FIELD))
if strings.TrimSpace(m.Option(SID)) != "" {
msg := m.Cmd(mdb.SELECT, m.Prefix(SESS), "", mdb.HASH, kit.MDB_HASH, strings.TrimSpace(m.Option(SID)))
if m.Option(SID, msg.Append(kit.MDB_HASH)) != "" {
m.Option(aaa.USERNAME, msg.Append(aaa.USERNAME))
m.Option(aaa.HOSTNAME, msg.Append(aaa.HOSTNAME))
}
}
m.Render(ice.RENDER_RESULT)
}},
},
}, nil)
}

View File

@ -37,7 +37,16 @@ func init() {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, kit.Select(m.Conf(SYNC, kit.META_FIELD), mdb.DETAIL, len(arg) > 0))
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, kit.MDB_ID, arg)
if len(arg) > 0 {
m.Option("cache.field", kit.MDB_ID)
m.Option("cache.value", arg[0])
} else {
if m.Option("_control", "page"); m.Option("cache.limit") == "" {
m.Option("cache.limit", "10")
}
}
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, m.Option("cache.field"), m.Option("cache.value"))
}},
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Render(ice.RENDER_RESULT)

View File

@ -27,10 +27,10 @@ cd ./install
`
chapter "应用"
field "同步流" web.code.vim.sync
field "编辑器" web.code.vim.sess
field "输入法" web.code.vim.input
field "收藏夹" web.code.vim.favor
field "输入法" web.code.input.wubi
field "同步流" web.code.vim.sync
chapter "配置"

View File

@ -28,6 +28,7 @@ chapter "应用"
web.code.zsh.sess contexts
field "命令行" web.code.zsh.sess
field "回收站" web.code.zsh.trash
field "收藏夹" web.code.zsh.favor
field "同步流" web.code.zsh.sync

View File

@ -39,15 +39,17 @@ func init() {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, kit.Select(m.Conf(SYNC, kit.META_FIELD), mdb.DETAIL, len(arg) > 0))
if m.Option("cache.value") == "" {
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, kit.MDB_ID, arg)
if len(arg) > 0 {
m.Option("cache.field", kit.MDB_ID)
m.Option("cache.value", arg[0])
} else {
defer m.PushAction("收藏")
if m.Option("_control", "page"); m.Option("cache.limit") == "" {
m.Option("cache.limit", "10")
}
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, m.Option("cache.field"), m.Option("cache.value"))
m.PushAction("收藏")
}
m.Cmdy(mdb.SELECT, m.Prefix(SYNC), "", mdb.LIST, m.Option("cache.field"), m.Option("cache.value"))
}},
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {

56
misc/zsh/trash.go Normal file
View File

@ -0,0 +1,56 @@
package zsh
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits"
)
const TRASH = "trash"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
TRASH: {Name: TRASH, Help: "收藏夹", Value: kit.Data(
kit.MDB_FIELD, "time,hash,hostname,size,from,to",
)},
},
Commands: map[string]*ice.Command{
TRASH: {Name: "TRASH hash auto 清理", Help: "收藏夹", Action: map[string]*ice.Action{
mdb.INSERT: {Name: "insert from= to=", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(TRASH), "", mdb.HASH, "from", m.Option("from"), "to", m.Option("to"))
}},
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, "rm", "-rf", m.Option("to"))
m.Cmdy(mdb.DELETE, m.Prefix(TRASH), "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
}},
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
}},
"reback": {Name: "reback", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(cli.SYSTEM, "mv", m.Option("to"), m.Option("from"))
m.Cmdy(mdb.DELETE, m.Prefix(TRASH), "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 {
m.Cmd(mdb.SELECT, m.Prefix(TRASH), "", mdb.HASH, kit.MDB_HASH, arg).Table(func(index int, value map[string]string, head []string) {
m.Cmdy(nfs.DIR, value["to"])
})
return
}
m.Option(mdb.FIELDS, kit.Select(m.Conf(m.Prefix(TRASH), kit.META_FIELD), mdb.DETAIL, len(arg) > 0))
m.Cmdy(mdb.SELECT, m.Prefix(TRASH), "", mdb.HASH, kit.MDB_HASH, arg)
m.PushAction("恢复", "删除")
}},
"/trash": {Name: "/trash", Help: "回收", Action: map[string]*ice.Action{
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(TRASH), "", mdb.HASH, "hostname", m.Option("hostname"),
"size", m.Option("size"), "from", m.Option("from"), "to", m.Option("to"))
}},
},
}, nil)
}