forked from x/icebergs
add web.proxy
This commit is contained in:
parent
0ed939c9b3
commit
155177ea92
5
base.go
5
base.go
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -135,14 +136,15 @@ func Run(arg ...string) string {
|
||||
arg = os.Args[1:]
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
// arg = append(arg, WEB_SERVE)
|
||||
arg = append(arg, WEB_SPACE, "connect", "self")
|
||||
}
|
||||
|
||||
frame := &Frame{}
|
||||
Index.server = frame
|
||||
Pulse.Option("cache.limit", "30")
|
||||
Pulse.Option("begin_time", Pulse.Time())
|
||||
|
||||
runtime.GOMAXPROCS(1)
|
||||
if frame.Begin(Pulse.Spawns(), arg...).Start(Pulse, arg...) {
|
||||
frame.Close(Pulse.Spawns(), arg...)
|
||||
}
|
||||
@ -151,7 +153,6 @@ func Run(arg ...string) string {
|
||||
Pulse.Table()
|
||||
}
|
||||
fmt.Printf(Pulse.Result())
|
||||
// time.Sleep(time.Second)
|
||||
os.Exit(frame.code)
|
||||
return ""
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
ice.CLI_RUNTIME: {Name: "runtime", Help: "运行环境", Value: kit.Dict()},
|
||||
ice.CLI_SYSTEM: {Name: "system", Help: "系统命令", Value: kit.Data()},
|
||||
"python": {Name: "python", Help: "系统命令", Value: kit.Data("python", "python", "pip", "pip")},
|
||||
"daemon": {Name: "daemon", Help: "守护进程", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -94,15 +95,25 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
case "daemon":
|
||||
// 守护进程
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("PATH=%s", os.Getenv("PATH")))
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
if e := cmd.Start(); e != nil {
|
||||
m.Warn(e != nil, "%v start: %s", arg, e)
|
||||
} else if e := cmd.Wait(); e != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.Rich("daemon", nil, kit.Dict(kit.MDB_NAME, cmd.Process.Pid, "status", "running"))
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
|
||||
m.Gos(m, func(m *ice.Message) {
|
||||
if e := cmd.Wait(); e != nil {
|
||||
m.Warn(e != nil, "%v wait: %s", arg, e)
|
||||
} else {
|
||||
m.Cost("%v exit: %v", arg, cmd.ProcessState.ExitCode())
|
||||
m.Rich("daemon", nil, func(key string, value map[string]interface{}) {
|
||||
value["status"] = "exited"
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
default:
|
||||
// 系统命令
|
||||
out := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
@ -118,6 +129,11 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
m.Echo(out.String())
|
||||
}
|
||||
}},
|
||||
"daemon": {Name: "daemon", Help: "守护进程", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "exit":
|
||||
}
|
||||
}},
|
||||
"python": {Name: "python", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{ice.CLI_SYSTEM, m.Conf("python", "meta.python")}
|
||||
switch arg[0] {
|
||||
|
@ -8,12 +8,14 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
ice.CTX_CONFIG: {Name: "config", Help: "配置", Value: kit.Data("path", "var/conf")},
|
||||
"demo": {Name: "demo", Help: "配置", Value: kit.Data("path", "var/conf")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_CONTEXT: {Name: "context [all]", Help: "模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -169,8 +171,12 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
|
||||
}
|
||||
default:
|
||||
if len(arg) > 2 {
|
||||
// 修改配置
|
||||
msg.Conf(arg[0], arg[1], arg[2])
|
||||
if strings.HasPrefix(arg[2], "@") {
|
||||
msg.Conf(arg[0], arg[1], msg.Cmdx("nfs.cat", arg[2][1:]))
|
||||
} else {
|
||||
msg.Conf(arg[0], arg[1], kit.Parse(nil, "", arg[2:]...))
|
||||
}
|
||||
|
||||
}
|
||||
if len(arg) > 1 {
|
||||
// 读取配置
|
||||
|
@ -30,7 +30,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
m.Log(ice.LOG_SIGNAL, "%v: %v", s, m.Confv(ice.GDB_SIGNAL, kit.Keys(kit.MDB_HASH, s)))
|
||||
m.Cmd(m.Confv(ice.GDB_SIGNAL, kit.Keys(kit.MDB_HASH, s)))
|
||||
m.Cmd(m.Confv(ice.GDB_SIGNAL, kit.Keys(kit.MDB_HASH, s)), kit.Keys(s))
|
||||
|
||||
case t, ok := <-f.t:
|
||||
if !ok {
|
||||
@ -73,9 +73,10 @@ var Index = &ice.Context{Name: "gdb", Help: "事件模块",
|
||||
kit.MDB_META, kit.Dict("pid", "var/run/ice.pid"),
|
||||
kit.MDB_LIST, kit.List(),
|
||||
kit.MDB_HASH, kit.Dict(
|
||||
"2", []interface{}{"exit"},
|
||||
"2", []interface{}{"exit", "0"},
|
||||
"3", []interface{}{"exit", "1"},
|
||||
"15", []interface{}{"exit"},
|
||||
"15", []interface{}{"exit", "1"},
|
||||
"20", []interface{}{"cli.daemon", "exit"},
|
||||
"30", []interface{}{"exit"},
|
||||
"31", []interface{}{"exit", "1"},
|
||||
"28", "WINCH",
|
||||
|
@ -52,7 +52,7 @@ func (f *Frame) printf(m *ice.Message, res string, arg ...interface{}) *Frame {
|
||||
return f
|
||||
}
|
||||
func (f *Frame) parse(m *ice.Message, line string) *Frame {
|
||||
for _, one := range kit.Split(line, ";") {
|
||||
for _, one := range kit.Split(line, ";", ";", ";") {
|
||||
ls := kit.Split(one)
|
||||
m.Log(ice.LOG_IMPORT, "stdin: %d %v", len(ls), ls)
|
||||
|
||||
|
@ -19,3 +19,35 @@ var share_template = kit.Dict(
|
||||
</body>
|
||||
`,
|
||||
)
|
||||
var favor_template = kit.Dict(
|
||||
"shell", `<div class="code">{{$msg := .}}{{range $index, $_ := .Appendv "_index"}}{{$name := $msg.Appendv "name"}}{{$text := $msg.Appendv "text"}}
|
||||
# {{index $name $index}}
|
||||
{{index $text $index}}
|
||||
{{end}}
|
||||
</div>`,
|
||||
"vimrc", `<div class="code">{{$msg := .}}{{range $index, $_ := .Appendv "_index"}}{{$name := $msg.Appendv "name"}}{{$id := $msg.Appendv "id"}}
|
||||
{{$res := index $id $index|$msg.Prefile ""}}
|
||||
# {{index $name $index}} {{index $res "extra.buf"}}:{{index $res "extra.row"}}
|
||||
{{index $res "content"}}
|
||||
{{end}}
|
||||
</div>`,
|
||||
"field", `{{$msg := .}}
|
||||
{{range $index, $_ := .Appendv "_index"}}
|
||||
{{$type := $msg.Appendv "type"}}{{$name := $msg.Appendv "name"}}{{$text := $msg.Appendv "text"}}
|
||||
<fieldset class="story {{index $name $index}}" data-type="{{index $type $index}}" data-name="{{index $name $index}}" data-text="{{index $text $index}}" data-meta='{{index $text $index|$msg.Preview}}'>
|
||||
<legend>{{index $name $index}}</legend>
|
||||
<form class="option"></form>
|
||||
<div class="action"></div>
|
||||
<div class="output"></div>
|
||||
<div class="status"></div>
|
||||
</fieldset>
|
||||
{{end}}
|
||||
`,
|
||||
"spide", `<ul>{{$msg := .}}
|
||||
{{range $index, $_ := .Appendv "_index"}}
|
||||
{{$name := $msg.Appendv "name"}}
|
||||
{{$text := $msg.Appendv "text"}}
|
||||
<li>{{index $name $index}}: <a href="{{index $text $index}}" target="_blank">{{index $text $index}}</a></li>
|
||||
{{end}}
|
||||
</ul>`,
|
||||
)
|
||||
|
@ -443,7 +443,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
"cmd", []interface{}{ice.CLI_SYSTEM, "ice.bin", ice.WEB_SPACE, "connect"},
|
||||
)},
|
||||
|
||||
ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||
ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, "template", favor_template,
|
||||
)},
|
||||
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",
|
||||
)},
|
||||
@ -472,8 +474,13 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
if m.Richs(ice.WEB_SPIDE, nil, "shy", nil) == nil {
|
||||
m.Cmd(ice.WEB_SPIDE, "add", "shy", kit.Select("https://shylinux.com:443", m.Conf(ice.CLI_RUNTIME, "conf.ctx_shy")))
|
||||
}
|
||||
m.Rich(ice.WEB_SPACE, nil, kit.Dict(
|
||||
kit.MDB_TYPE, ice.WEB_BETTER, kit.MDB_NAME, "tmux",
|
||||
kit.MDB_TEXT, m.Conf(ice.CLI_RUNTIME, "boot.username"),
|
||||
))
|
||||
m.Watch(ice.SYSTEM_INIT, "web.code.git.repos", "volcanos", m.Conf(ice.WEB_SERVE, "meta.volcanos.path"),
|
||||
m.Conf(ice.WEB_SERVE, "meta.volcanos.repos"), m.Conf(ice.WEB_SERVE, "meta.volcanos.branch"))
|
||||
m.Conf(ice.WEB_FAVOR, "meta.template", favor_template)
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
p := m.Conf(ice.WEB_CACHE, "meta.store")
|
||||
@ -753,9 +760,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
// 节点列表
|
||||
// 空间列表
|
||||
m.Richs(ice.WEB_SPACE, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value, []string{"time", "type", "name", "user"})
|
||||
m.Push(key, value, []string{"time", "type", "name", "text"})
|
||||
})
|
||||
m.Sort("name")
|
||||
return
|
||||
@ -804,7 +811,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
|
||||
// 连接成功
|
||||
msg.Rich(ice.WEB_SPACE, nil, kit.Dict(
|
||||
kit.MDB_TYPE, ice.WEB_MASTER, kit.MDB_NAME, dev, "user", kit.Value(value, "client.hostname"),
|
||||
kit.MDB_TYPE, ice.WEB_MASTER, kit.MDB_NAME, dev, kit.MDB_TEXT, kit.Value(value, "client.hostname"),
|
||||
"socket", s,
|
||||
))
|
||||
msg.Log(ice.LOG_CMDS, "%d conn %s success %s", i, dev, u)
|
||||
@ -826,6 +833,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
|
||||
default:
|
||||
if len(arg) == 1 {
|
||||
// 空间空间
|
||||
list := []string{}
|
||||
m.Cmdy(ice.WEB_SPACE, arg[0], "space").Table(func(index int, value map[string]string, head []string) {
|
||||
list = append(list, arg[0]+"."+value["name"])
|
||||
@ -833,7 +841,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Append("name", list)
|
||||
break
|
||||
|
||||
// 节点详情
|
||||
// 空间详情
|
||||
m.Richs(ice.WEB_SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
m.Push("detail", value)
|
||||
})
|
||||
@ -849,16 +857,24 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
target := strings.Split(arg[0], ".")
|
||||
m.Warn(m.Richs(ice.WEB_SPACE, nil, target[0], func(key string, value map[string]interface{}) {
|
||||
if socket, ok := value["socket"].(*websocket.Conn); ok {
|
||||
// 构造路由
|
||||
id := kit.Format(c.ID())
|
||||
m.Optionv(ice.MSG_SOURCE, []string{id})
|
||||
m.Optionv(ice.MSG_TARGET, target[1:])
|
||||
for _, k := range []string{"top", "hot", ice.MSG_USERNAME} {
|
||||
// 复制选项
|
||||
for _, k := range kit.Simple(m.Optionv("_option")) {
|
||||
if m.Options(k) {
|
||||
switch k {
|
||||
case "detail", "cmds":
|
||||
default:
|
||||
if m.Option(k) != "" {
|
||||
m.Option(k, m.Option(k))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 构造路由
|
||||
id := kit.Format(c.ID())
|
||||
m.Set(ice.MSG_DETAIL, arg[1:]...)
|
||||
m.Optionv(ice.MSG_TARGET, target[1:])
|
||||
m.Optionv(ice.MSG_SOURCE, []string{id})
|
||||
m.Info("send %s %s", id, m.Format("meta"))
|
||||
|
||||
// 下发命令
|
||||
@ -949,13 +965,27 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
|
||||
ice.WEB_FAVOR: {Name: "favor [path [type name [text [key value]....]]", Help: "收藏夹", Meta: kit.Dict(
|
||||
"remote", "pod", "exports", []string{"hot", "favor"},
|
||||
"detail", []string{"编辑", "收录", "导出", "删除"},
|
||||
"detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
||||
), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "favor", "action", "auto",
|
||||
kit.MDB_INPUT, "text", "name", "id", "action", "auto",
|
||||
kit.MDB_INPUT, "button", "value", "查看", "action", "auto",
|
||||
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
|
||||
kit.MDB_INPUT, "button", "value", "渲染",
|
||||
kit.MDB_INPUT, "button", "value", "回放",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch m.Option("_action") {
|
||||
case "渲染":
|
||||
m.Option("render", "spide")
|
||||
m.Richs(ice.WEB_FAVOR, nil, kit.Select(m.Option("favor"), arg, 0), func(key string, value map[string]interface{}) {
|
||||
m.Option("render", kit.Select("spide", kit.Value(value, "meta.render")))
|
||||
})
|
||||
defer m.Render(m.Conf(ice.WEB_FAVOR, kit.Keys("meta.template", m.Option("render"))))
|
||||
|
||||
case "回放":
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) > 1 && arg[0] == "action" {
|
||||
favor, id := m.Option("favor"), m.Option("id")
|
||||
switch arg[2] {
|
||||
@ -968,6 +998,12 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
switch arg[1] {
|
||||
case "modify", "编辑":
|
||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
||||
if id == "" {
|
||||
m.Log(ice.LOG_MODIFY, "favor: %s value: %v->%v", key, kit.Value(value, kit.Keys("meta", arg[2])), arg[3])
|
||||
m.Echo("%s->%s", kit.Value(value, kit.Keys("meta", arg[2])), arg[3])
|
||||
kit.Value(value, kit.Keys("meta", arg[2]), arg[3])
|
||||
return
|
||||
}
|
||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", id, func(index int, value map[string]interface{}) {
|
||||
m.Log(ice.LOG_MODIFY, "favor: %s index: %d value: %v->%v", key, index, value[arg[2]], arg[3])
|
||||
m.Echo("%s->%s", value[arg[2]], arg[3])
|
||||
@ -1010,12 +1046,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
// 收藏门类
|
||||
m.Richs(ice.WEB_FAVOR, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value["meta"], []string{"time", "count"})
|
||||
m.Push("render", kit.Select("spide", kit.Value(value, "meta.render")))
|
||||
m.Push("favor", kit.Value(value, "meta.name"))
|
||||
})
|
||||
m.Sort("favor")
|
||||
return
|
||||
}
|
||||
|
||||
m.Option("favor", arg[0])
|
||||
fields := []string{kit.MDB_TIME, kit.MDB_ID, kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}
|
||||
if len(arg) > 1 && arg[1] == "extra" {
|
||||
fields, arg = append(fields, arg[2:]...), arg[:1]
|
||||
@ -1580,13 +1618,37 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
}},
|
||||
|
||||
ice.WEB_ROUTE: {Name: "route", Help: "路由", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(ice.WEB_SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
switch value[kit.MDB_TYPE] {
|
||||
case ice.WEB_MASTER:
|
||||
case ice.WEB_SERVER:
|
||||
case ice.WEB_WORKER:
|
||||
}
|
||||
})
|
||||
m.Cmdy(ice.WEB_SPACE, arg[0], arg[1:])
|
||||
}},
|
||||
ice.WEB_PROXY: {Name: "proxy", Help: "代理", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(ice.WEB_SPACE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
if value[kit.MDB_TYPE] == ice.WEB_BETTER {
|
||||
switch value[kit.MDB_NAME] {
|
||||
case "tmux":
|
||||
m.Cmd("web.code.tmux.session").Table(func(index int, value map[string]string, head []string) {
|
||||
if value["tag"] == "1" {
|
||||
m.Log(ice.LOG_SELECT, "space: %s", value["session"])
|
||||
arg[0] = value["session"]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
m.Cmdy(ice.WEB_ROUTE, arg[0], arg[1:])
|
||||
}},
|
||||
ice.WEB_GROUP: {Name: "group", Help: "分组", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(ice.WEB_PROXY, arg[0], arg[1:])
|
||||
}},
|
||||
ice.WEB_LABEL: {Name: "label", Help: "标签", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(ice.WEB_GROUP, arg[0], arg[1:])
|
||||
}},
|
||||
|
||||
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -1796,7 +1858,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
h := m.Rich(ice.WEB_SPACE, nil, kit.Dict(
|
||||
kit.MDB_TYPE, m.Option("node"),
|
||||
kit.MDB_NAME, m.Option("name"),
|
||||
kit.MDB_USER, m.Option("user"),
|
||||
kit.MDB_TEXT, m.Option("user"),
|
||||
"sessid", m.Option("sessid"),
|
||||
"share", share, "socket", s,
|
||||
))
|
||||
|
1
conf.go
1
conf.go
@ -78,6 +78,7 @@ const ( // WEB
|
||||
|
||||
WEB_MASTER = "master"
|
||||
WEB_MYSELF = "myself"
|
||||
WEB_BETTER = "better"
|
||||
WEB_SERVER = "server"
|
||||
WEB_WORKER = "worker"
|
||||
)
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
_ "github.com/shylinux/icebergs/base"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
@ -31,7 +29,6 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
[]interface{}{"field", "draw", "web.wiki"},
|
||||
[]interface{}{"field", "data", "web.wiki"},
|
||||
[]interface{}{"field", "word", "web.wiki"},
|
||||
[]interface{}{"field", "mind", "web.wiki"},
|
||||
[]interface{}{"field", "walk", "web.wiki"},
|
||||
[]interface{}{"field", "feel", "web.wiki"},
|
||||
|
||||
@ -445,12 +442,31 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
// 命令补全
|
||||
if len(arg) > 3 && arg[3] == "action" {
|
||||
switch arg[4] {
|
||||
case "input":
|
||||
switch arg[5] {
|
||||
case "location":
|
||||
// 查询位置
|
||||
m.Copy(m.Cmd("aaa.location"), "append", "name")
|
||||
return
|
||||
}
|
||||
|
||||
case "favor":
|
||||
m.Cmdy(ice.WEB_FAVOR, arg[5:])
|
||||
return
|
||||
case "location":
|
||||
// 记录位置
|
||||
m.Cmdy("aaa.location", arg[5:])
|
||||
return
|
||||
case "upload":
|
||||
m.Cmdy(ice.WEB_STORY, "upload")
|
||||
return
|
||||
|
||||
case "story":
|
||||
// cmds := kit.Split(arg[7])
|
||||
// if m.Right(cmds, arg[8:]) {
|
||||
// m.Cmdy(cmds, arg[8:])
|
||||
// }
|
||||
// return
|
||||
|
||||
case "share":
|
||||
list := []string{}
|
||||
@ -460,13 +476,6 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
// 共享命令
|
||||
m.Cmdy(ice.WEB_SHARE, "add", "action", arg[5], arg[6], list)
|
||||
return
|
||||
case "input":
|
||||
switch arg[5] {
|
||||
case "location":
|
||||
// 查询位置
|
||||
m.Copy(m.Cmd("aaa.location"), "append", "name")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,19 +485,30 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
||||
})
|
||||
|
||||
if len(cmds) == 0 {
|
||||
// 没有命令
|
||||
m.Push("_output", "status")
|
||||
m.Set("result").Echo("404")
|
||||
return
|
||||
}
|
||||
|
||||
if !m.Right(cmd, arg[2]) {
|
||||
if !m.Right(cmds) {
|
||||
// 没有权限
|
||||
m.Push("_output", "status")
|
||||
m.Set("result").Echo("403")
|
||||
return
|
||||
}
|
||||
|
||||
m.Cmd(ice.WEB_FAVOR, "cmd.history", "cmd", m.Option(ice.MSG_SESSID)[:6], strings.Join(cmds, " "))
|
||||
// 代理命令
|
||||
proxy := []string{}
|
||||
m.Search(cmds[0], func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if remote := kit.Format(kit.Value(cmd.Meta, "remote")); m.Option(remote) != "" {
|
||||
proxy = append(proxy, ice.WEB_PROXY, m.Option(remote))
|
||||
}
|
||||
})
|
||||
|
||||
// 执行命令
|
||||
m.Cmdy(cmds).Option("cmds", cmds)
|
||||
m.Cmdy(proxy, cmds).Option("cmds", cmds)
|
||||
// m.Cmd(ice.WEB_FAVOR, "cmd.history", "cmd", m.Option(ice.MSG_SESSID)[:6], strings.Join(cmds, " "))
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
@ -246,7 +246,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
data := kit.Dict()
|
||||
cmds := kit.Split(arg[1])
|
||||
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
data["feature"], data["inputs"] = cmd.Meta, cmd.List
|
||||
if data["feature"], data["inputs"] = cmd.Meta, cmd.List; len(cmd.List) == 0 {
|
||||
data["inputs"] = m.Confv("field", "meta.some.simple.inputs")
|
||||
}
|
||||
})
|
||||
|
||||
for i := 2; i < len(arg)-1; i += 2 {
|
||||
@ -413,6 +415,16 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
switch arg[1] {
|
||||
case "story":
|
||||
cmds := kit.Split(arg[4])
|
||||
if len(arg) > 6 {
|
||||
switch arg[5] {
|
||||
case "action":
|
||||
switch arg[6] {
|
||||
case "favor":
|
||||
m.Cmdy(ice.WEB_FAVOR, arg[7:])
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Right(cmds, arg[5:]) {
|
||||
m.Cmdy(cmds, arg[5:])
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
|
||||
// 添加收藏
|
||||
cmds := []string{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_SPACE, m.Option("you"), cmds)
|
||||
m.Cmdy(ice.WEB_PROXY, m.Option("you"), cmds)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
"docker": {Name: "docker", Help: "虚拟机", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
"docker": {Name: "docker", Help: "虚拟机", Value: kit.Data(kit.MDB_SHORT, "name", "build", []interface{}{})},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -31,10 +31,18 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
kit.Fetch(m.Confv("docker", "meta.build"), func(index int, value string) {
|
||||
switch value {
|
||||
case "home":
|
||||
args = append(args, "-w", "/root")
|
||||
case "mount":
|
||||
args = append(args, "--mount", kit.Format("type=bind,source=%s,target=/root", kit.Path(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0])))
|
||||
}
|
||||
})
|
||||
|
||||
// 创建容器
|
||||
pid := m.Cmdx(prefix, "run", "-dt", "-w", "/root", "--name", arg[0],
|
||||
// "--mount", kit.Format("type=bind,source=%s,target=/root", kit.Path(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0])),
|
||||
"alpine")
|
||||
pid := m.Cmdx(prefix, "run", "-dt", args, "--name", arg[0], "alpine")
|
||||
m.Log(ice.LOG_CREATE, "%s: %s", arg[0], pid)
|
||||
|
||||
m.Cmd(ice.WEB_FAVOR, kit.Select("alpine.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) {
|
||||
|
@ -18,7 +18,7 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
"input": {Name: "input", Help: "输入法", Value: kit.Data(
|
||||
"store", "var/input/", "fsize", "200000", "limit", "5000", "least", "1000",
|
||||
"store", "var/data/input", "fsize", "200000", "limit", "5000", "least", "1000",
|
||||
"repos", "wubi-dict", "local", "some",
|
||||
)},
|
||||
},
|
||||
@ -45,13 +45,14 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
|
||||
// 清空数据
|
||||
lib := kit.Select(path.Base(arg[0]), arg, 1)
|
||||
m.Assert(os.RemoveAll(m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), lib))))
|
||||
m.Assert(os.RemoveAll(path.Join(m.Conf("input", "meta.store"), lib)))
|
||||
m.Conf("input", lib, "")
|
||||
|
||||
// 缓存配置
|
||||
m.Option("cache.least", m.Conf("input", "meta.least"))
|
||||
m.Option("cache.limit", m.Conf("input", "meta.limit"))
|
||||
m.Option("cache.fsize", m.Conf("input", "meta.fsize"))
|
||||
m.Conf("input", kit.Keys(lib, "meta.store"), path.Join(m.Conf("input", "meta.store"), lib))
|
||||
m.Conf("input", kit.Keys(lib, "meta.fsize"), m.Conf("input", "meta.fsize"))
|
||||
m.Conf("input", kit.Keys(lib, "meta.limit"), m.Conf("input", "meta.limit"))
|
||||
m.Conf("input", kit.Keys(lib, "meta.least"), m.Conf("input", "meta.least"))
|
||||
|
||||
// 加载词库
|
||||
for bio.Scan() {
|
||||
@ -65,17 +66,16 @@ var Index = &ice.Context{Name: "input", Help: "输入法",
|
||||
m.Grow("input", lib, kit.Dict("text", line[0], "code", line[1], "weight", line[2]))
|
||||
}
|
||||
// 保存词库
|
||||
m.Option("cache.least", 0)
|
||||
m.Option("cache.limit", 0)
|
||||
m.Conf("input", kit.Keys(lib, "meta.limit"), 0)
|
||||
m.Conf("input", kit.Keys(lib, "meta.least"), 0)
|
||||
m.Echo("%s: %d", lib, m.Grow("input", lib, kit.Dict("text", "成功", "code", "z", "weight", "0")))
|
||||
}
|
||||
}},
|
||||
"push": {Name: "push lib text code [weight]", Help: "添加词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option("cache.least", 0)
|
||||
m.Option("cache.limit", 0)
|
||||
m.Option("cache.store", path.Join(m.Conf("input", "meta.store"), arg[0]))
|
||||
m.Conf("input", kit.Keys(arg[0], "meta.limit"), 0)
|
||||
m.Conf("input", kit.Keys(arg[0], "meta.least"), 0)
|
||||
m.Echo("%s: %d", arg[0], m.Grow("input", arg[0], kit.Dict(
|
||||
"text", arg[1], "code", arg[2], "weight", kit.Select("9091929394", arg, 3))))
|
||||
"text", arg[1], "code", arg[2], "weight", kit.Select("90919495", arg, 3))))
|
||||
}},
|
||||
"list": {Name: "list [lib [offend [limit]]]", Help: "查看词汇", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
|
@ -283,6 +283,7 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
|
||||
"local": {Name: "local which target", Help: "虚拟机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
m.Cmd("web.code.docker.auto", arg[1])
|
||||
m.Cmdy(prefix, "send-keys", "-t", arg[1], "docker exec -it ", arg[1], " bash", "Enter")
|
||||
}},
|
||||
"relay": {Name: "relay which target", Help: "跳板机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -93,13 +93,16 @@ highlight Comment ctermfg=cyan ctermbg=darkblue
|
||||
" 收藏列表
|
||||
call ShyDefine("g:favor_tab", "")
|
||||
call ShyDefine("g:favor_note", "")
|
||||
let shyList=["启动流程", "请求响应", "服务集群", "数据结构", "系统架构", "编译原理"]
|
||||
fun! ShyFavor()
|
||||
let g:favor_tab = input("tab: ", g:favor_tab)
|
||||
" let g:favor_tab = input("tab: ", g:favor_tab)
|
||||
let g:favor_tab = g:shyList[inputlist(g:shyList)-1]
|
||||
let g:favor_note = input("note: ", g:favor_note)
|
||||
call ShySend("favor", {"tab": g:favor_tab, "note": g:favor_note, "arg": getline("."), "row": getpos(".")[1], "col": getpos(".")[2]})
|
||||
endfun
|
||||
fun! ShyFavors()
|
||||
let res = split(ShySend("favor", {"tab": input("tab: ", g:favor_tab)}), "\n")
|
||||
" let res = split(ShySend("favor", {"tab": input("tab: ", g:favor_tab)}), "\n")
|
||||
let res = split(ShySend("favor", {"tab": g:shyList[inputlist(g:shyList)-1]}), "\n")
|
||||
let page = "" | let note = ""
|
||||
for i in range(0, len(res)-1, 2)
|
||||
if res[i] != page
|
||||
@ -108,7 +111,21 @@ fun! ShyFavors()
|
||||
endif
|
||||
let page = res[i] | let note .= res[i+1] . "\n"
|
||||
endfor
|
||||
if note != "" | lexpr note | lopen | let note = "" | endif
|
||||
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
|
||||
fun! ShyCheck(target)
|
||||
if a:target == "cache"
|
||||
|
@ -63,7 +63,7 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
||||
}},
|
||||
"/input": {Name: "/input", Help: "补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if strings.HasPrefix(strings.TrimSpace(arg[0]), "ice ") {
|
||||
list := kit.Split(strings.TrimSpace(arg[0]), "ice ")
|
||||
list := kit.Split(strings.TrimSpace(arg[0]))
|
||||
switch list[1] {
|
||||
case "add":
|
||||
// 添加词汇
|
||||
|
86
type.go
86
type.go
@ -428,6 +428,12 @@ func (m *Message) Echo(str string, arg ...interface{}) *Message {
|
||||
return m
|
||||
}
|
||||
func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||
if m == msg {
|
||||
return m
|
||||
}
|
||||
if m == nil {
|
||||
return m
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
// 精确复制
|
||||
for _, k := range arg[1:] {
|
||||
@ -959,6 +965,24 @@ func (m *Message) Watch(key string, arg ...string) *Message {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Message) Preview(arg string) (res string) {
|
||||
list := kit.Split(arg)
|
||||
m.Search(list[0], func(p *Context, s *Context, key string, cmd *Command) {
|
||||
res = kit.Format(kit.Dict("feature", cmd.Meta, "inputs", cmd.List))
|
||||
})
|
||||
return res
|
||||
}
|
||||
func (m *Message) Prefile(favor string, id string) map[string]string {
|
||||
res := map[string]string{}
|
||||
m.Option("render", "")
|
||||
m.Option("_action", "")
|
||||
m.Cmd(WEB_FAVOR, kit.Select(m.Option("favor"), favor), id).Table(func(index int, value map[string]string, head []string) {
|
||||
res[value["key"]] = value["value"]
|
||||
})
|
||||
|
||||
res["content"] = m.Cmdx(CLI_SYSTEM, "sed", "-n", kit.Format("%d,%dp", kit.Int(res["extra.row"]), kit.Int(res["extra.row"])+3), res["extra.buf"])
|
||||
return res
|
||||
}
|
||||
func (m *Message) Prefix(arg ...string) string {
|
||||
return kit.Keys(m.Cap(CTX_FOLLOW), arg)
|
||||
}
|
||||
@ -1226,16 +1250,24 @@ func (m *Message) Grow(key string, chain interface{}, data interface{}) int {
|
||||
meta["count"] = id
|
||||
|
||||
// 保存数据
|
||||
if len(list) >= kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.limit"), kit.Select(kit.Format(meta["limit"]), m.Option("cache.limit")))) {
|
||||
least := kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.least"), kit.Select(kit.Format(meta["least"]), m.Option("cache.least"))))
|
||||
if len(list) >= kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.limit"), kit.Format(meta["limit"]))) {
|
||||
least := kit.Int(kit.Select(m.Conf(WEB_CACHE, "meta.least"), kit.Format(meta["least"])))
|
||||
|
||||
// 创建文件
|
||||
name := path.Join(kit.Select(m.Conf(WEB_CACHE, "meta.store"), kit.Select(kit.Format(meta["store"]), m.Option("cache.store"))), kit.Keys(key, chain, "csv"))
|
||||
record, _ := meta["record"].([]interface{})
|
||||
|
||||
// 文件命名
|
||||
prefix := path.Join(kit.Select(m.Conf(WEB_CACHE, "meta.store"), kit.Format(meta["store"])), key)
|
||||
name := path.Join(prefix, kit.Keys(kit.Select("list", chain), "csv"))
|
||||
if len(record) > 0 {
|
||||
name = kit.Format(kit.Value(record, kit.Keys(len(record)-1, "file")))
|
||||
if s, e := os.Stat(name); e == nil {
|
||||
if s.Size() > kit.Int64(kit.Select(m.Conf(WEB_CACHE, "meta.fsize"), kit.Select(kit.Format(meta["fsize"]), m.Option("cache.fsize")))) {
|
||||
name = strings.Replace(name, ".csv", fmt.Sprintf("_%d.csv", kit.Int(meta["offset"])), -1)
|
||||
if s.Size() > kit.Int64(kit.Select(m.Conf(WEB_CACHE, "meta.fsize"), kit.Format(meta["fsize"]))) {
|
||||
name = fmt.Sprintf("%s/%s_%d.csv", prefix, kit.Select("list", chain), kit.Int(meta["offset"]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 打开文件
|
||||
f, e := os.OpenFile(name, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
|
||||
if e != nil {
|
||||
f, _, e = kit.Create(name)
|
||||
@ -1256,28 +1288,22 @@ func (m *Message) Grow(key string, chain interface{}, data interface{}) int {
|
||||
}
|
||||
sort.Strings(keys)
|
||||
w.Write(keys)
|
||||
m.Info("write head: %v", keys)
|
||||
w.Flush()
|
||||
s, e = f.Stat()
|
||||
} else {
|
||||
r := csv.NewReader(f)
|
||||
keys, e = r.Read()
|
||||
m.Info("read head: %v", keys)
|
||||
}
|
||||
|
||||
// 保存记录
|
||||
// 创建索引
|
||||
count := len(list) - least
|
||||
offset := kit.Int(meta["offset"])
|
||||
record, _ := meta["record"].([]interface{})
|
||||
if len(record) > 0 && kit.Format(kit.Value(record, kit.Keys(len(record)-1, "file"))) == name && count < 10 {
|
||||
kit.Value(record, kit.Keys(len(record)-1, "count"), kit.Int(kit.Value(record, kit.Keys(len(record)-1, "count")))+count)
|
||||
} else {
|
||||
meta["record"] = append(record, map[string]interface{}{
|
||||
"time": m.Time(),
|
||||
"offset": offset,
|
||||
"position": s.Size(),
|
||||
"count": count,
|
||||
"file": name,
|
||||
"time": m.Time(), "offset": offset, "count": count,
|
||||
"file": name, "position": s.Size(),
|
||||
})
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
for i, v := range list {
|
||||
@ -1300,7 +1326,7 @@ func (m *Message) Grow(key string, chain interface{}, data interface{}) int {
|
||||
|
||||
m.Log(LOG_INFO, "%s.%v save %s offset %v+%v", key, chain, name, offset, count)
|
||||
meta["offset"] = offset + count
|
||||
list = list[:least]
|
||||
list = list[count:]
|
||||
cache[kit.MDB_LIST] = list
|
||||
w.Flush()
|
||||
}
|
||||
@ -1453,16 +1479,22 @@ func (m *Message) Cmd(arg ...interface{}) *Message {
|
||||
|
||||
m.Search(list[0], func(p *Context, c *Context, key string, cmd *Command) {
|
||||
m.TryCatch(m.Spawns(c), true, func(msg *Message) {
|
||||
msg.meta[MSG_DETAIL] = list
|
||||
m.Hand, msg.Hand, m = true, true, msg
|
||||
if you := m.Option(kit.Format(kit.Value(cmd.Meta, "remote"))); you != "" {
|
||||
// 远程命令
|
||||
msg.Copy(msg.Spawns(c).Cmd(WEB_SPACE, you, list[0], list[1:]))
|
||||
} else {
|
||||
// 本地命令
|
||||
p.Run(msg, cmd, key, list[1:]...)
|
||||
}
|
||||
m.Hand, msg.Hand = true, true
|
||||
msg.meta[MSG_DETAIL] = list
|
||||
|
||||
// _key := kit.Format(kit.Value(cmd.Meta, "remote"))
|
||||
// if you := m.Option(_key); you != "" {
|
||||
// // 远程命令
|
||||
// msg.Option(_key, "")
|
||||
// msg.Option("_option", m.Optionv("option"))
|
||||
// msg.Copy(msg.Spawns(c).Cmd(WEB_LABEL, you, list[0], list[1:]))
|
||||
// } else {
|
||||
// // 本地命令
|
||||
// p.Run(msg, cmd, key, list[1:]...)
|
||||
// }
|
||||
|
||||
p.Run(msg, cmd, key, list[1:]...)
|
||||
m.Hand, msg.Hand, m = true, true, msg
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user