1
0
forked from x/icebergs

add favor proxy

This commit is contained in:
shaoying 2020-03-25 13:45:31 +08:00
parent 9af43bc745
commit d0dd35e626
8 changed files with 40 additions and 40 deletions

View File

@ -312,6 +312,7 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) {
// msg.Render("status", 401, "not login") // msg.Render("status", 401, "not login")
return return
} }
msg.Option("_option", msg.Optionv(ice.MSG_OPTION))
// 执行命令 // 执行命令
msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), cmds...) msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), cmds...)
@ -464,6 +465,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data( ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_NAME, "template", favor_template, kit.MDB_SHORT, kit.MDB_NAME, "template", favor_template,
"proxy", "",
)}, )},
ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Value: kit.Data( ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Value: kit.Data(
kit.MDB_SHORT, "text", "path", "var/file", "store", "var/data", "fsize", "100000", "limit", "50", "least", "30", kit.MDB_SHORT, "text", "path", "var/file", "store", "var/data", "fsize", "100000", "limit", "50", "least", "30",
@ -841,14 +843,10 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
if socket, ok := value["socket"].(*websocket.Conn); !m.Warn(!ok, "socket err") { if socket, ok := value["socket"].(*websocket.Conn); !m.Warn(!ok, "socket err") {
// 复制选项 // 复制选项
for _, k := range kit.Simple(m.Optionv("_option")) { for _, k := range kit.Simple(m.Optionv("_option")) {
if m.Options(k) {
switch k { switch k {
case "detail", "cmds": case "detail", "cmds":
default: default:
if m.Option(k) == "" { m.Optionv(k, m.Optionv(k))
m.Option(k, m.Option(k))
}
}
} }
} }
@ -1042,6 +1040,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
m.Option("cache.limit", -2) m.Option("cache.limit", -2)
for _, favor := range arg[2:] { for _, favor := range arg[2:] {
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, val map[string]interface{}) { m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, val map[string]interface{}) {
if m.Conf(ice.WEB_FAVOR, kit.Keys("meta.skip", kit.Value(val, "meta.name"))) == "true" {
return
}
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
w.Write(kit.Simple(kit.Value(val, "meta.name"), value["type"], value["name"], value["text"], kit.Format(value["extra"]))) w.Write(kit.Simple(kit.Value(val, "meta.name"), value["type"], value["name"], value["text"], kit.Format(value["extra"])))
n++ n++
@ -1050,6 +1051,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
} }
w.Flush() w.Flush()
m.Echo("%s: %d", p, n) m.Echo("%s: %d", p, n)
return
case "load": case "load":
f, e := os.Open(arg[1]) f, e := os.Open(arg[1])
@ -1068,6 +1070,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
} }
m.Cmd(ice.WEB_FAVOR, line) m.Cmd(ice.WEB_FAVOR, line)
} }
return
case "sync": case "sync":
m.Richs(ice.WEB_FAVOR, nil, arg[1], func(key string, val map[string]interface{}) { m.Richs(ice.WEB_FAVOR, nil, arg[1], func(key string, val map[string]interface{}) {
@ -1131,8 +1134,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
arg = append(arg, "") arg = append(arg, "")
} }
m.Info("what %v", arg[4:])
m.Info("what %v", kit.Dict(arg[4:]))
// 添加收藏 // 添加收藏
index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict( index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict(
kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3],
@ -1143,6 +1144,12 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
}) })
m.Log(ice.LOG_INSERT, "favor: %s index: %d name: %s text: %s", favor, index, arg[2], arg[3]) m.Log(ice.LOG_INSERT, "favor: %s index: %d name: %s text: %s", favor, index, arg[2], arg[3])
m.Echo("%d", index) m.Echo("%d", index)
// 分发数据
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" {
m.Option("you", "")
m.Cmdy(ice.WEB_PROXY, p, ice.WEB_FAVOR, arg)
}
}}, }},
ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {

View File

@ -1,14 +1,16 @@
package alpha package alpha
import ( import (
"bytes"
"encoding/csv"
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/core/wiki" "github.com/shylinux/icebergs/core/wiki"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"bytes"
"encoding/csv"
"math/rand" "math/rand"
"os" "os"
"path" "path"
"strings"
) )
var Index = &ice.Context{Name: "alpha", Help: "英汉词典", var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
@ -98,11 +100,8 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典",
} }
// 搜索方法 // 搜索方法
method := "word" method := kit.Select("word", arg, 1)
if len(arg) > 1 { switch arg[0] = strings.TrimSpace(arg[0]); method {
method = arg[1]
}
switch method {
case "line": case "line":
case "word": case "word":
arg[0] = "," + arg[0] + "$" arg[0] = "," + arg[0] + "$"

View File

@ -99,16 +99,12 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 { if len(arg) > 0 {
// 添加收藏 // 添加收藏
cmds := []string{ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0]} m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0])
if m.Cmdy(cmds); m.Option("you") != "" {
m.Cmdy(ice.WEB_PROXY, m.Option("you"), cmds)
}
return return
} }
}}, }},
"/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Info("what %v", m.Option("sid"))
switch arg[0] { switch arg[0] {
case "login": case "login":
m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid")) m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid"))

View File

@ -27,7 +27,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")}, "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")},
"total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true"))}, "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"))},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
"init": {Name: "init", Help: "init", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "init": {Name: "init", Help: "init", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -144,8 +144,14 @@ fun! ShyCheck(target)
end end
endfun 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
" 任务列表 " 任务列表
@ -154,11 +160,6 @@ fun! ShyTask()
endfun endfun
" 标签列表 " 标签列表
fun! ShyGrep(word)
if !exists("g:grep_dir") | let g:grep_dir = "./" | endif
let g:grep_dir = input("dir: ", g:grep_dir, "file")
execute "grep -rn --exclude tags --exclude '*.tags' '\<" . a:word . "\>' " . g:grep_dir
endfun
fun! ShyTag(word) fun! ShyTag(word)
execute "tag " . a:word execute "tag " . a:word
endfun endfun
@ -218,7 +219,7 @@ autocmd! InsertLeave * call ShySync("insert")
" 按键映射 " 按键映射
nnoremap <C-G><C-F> :call ShyFavor()<CR> nnoremap <C-G><C-F> :call ShyFavor()<CR>
nnoremap <C-G>f :call ShyFavors()<CR> nnoremap <C-G>f :call ShyFavors()<CR>
" nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR> nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
" nnoremap <C-G><C-R> :call ShyCheck("cache")<CR> " nnoremap <C-G><C-R> :call ShyCheck("cache")<CR>
" nnoremap <C-G><C-T> :call ShyTask()<CR> " nnoremap <C-G><C-T> :call ShyTask()<CR>
nnoremap <C-G><C-K> :call ShyComes("refresh")<CR> nnoremap <C-G><C-K> :call ShyComes("refresh")<CR>

View File

@ -88,11 +88,8 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Options("arg") { if m.Options("arg") {
// 添加收藏 // 添加收藏
cmds := []string{ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"), m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")} "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
if m.Cmdy(cmds); m.Option("you") != "" {
m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds)
}
return return
} }

View File

@ -162,10 +162,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] != "sh" { if len(arg) > 0 && arg[0] != "sh" {
// 添加收藏 // 添加收藏
cmds := []string{ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0]} m.Cmdy(ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0])
if m.Cmdy(cmds); m.Option("you") != "" {
m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds)
}
return return
} }

View File

@ -462,6 +462,9 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
// 复制数据 // 复制数据
for _, k := range msg.meta[MSG_APPEND] { for _, k := range msg.meta[MSG_APPEND] {
if kit.IndexOf(m.meta[MSG_OPTION], k) > -1 && len(m.meta[k]) > 0 {
m.meta[k] = m.meta[k][:0]
}
if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 { if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 {
m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k) m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k)
} }