From d8a1434ba0c848db18f3e2c2a7253afe53a059e5 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sat, 9 Mar 2019 13:18:55 +0800 Subject: [PATCH] add note_view Change-Id: Ie516fe41861bd2fc0ca3277e2478542319a3a5d9 --- etc/dotsfile/.tmux.conf | 16 +- etc/dotsfile/.vimrc | 9 +- etc/dotsfile/shy.vim | 2 + src/contexts/cli/cli.go | 4 +- src/contexts/ctx/ctx_init.go | 26 +-- src/contexts/mdb/mdb.go | 409 +++++++++++++++++++---------------- src/contexts/nfs/nfs.go | 4 + src/contexts/web/web.go | 43 ++-- src/toolkit/kit.go | 15 ++ 9 files changed, 296 insertions(+), 232 deletions(-) diff --git a/etc/dotsfile/.tmux.conf b/etc/dotsfile/.tmux.conf index c890bddc..2ce97cf5 100644 --- a/etc/dotsfile/.tmux.conf +++ b/etc/dotsfile/.tmux.conf @@ -42,14 +42,14 @@ bind i display-panes bind x confirm-before -p "kill-pane #P? (y/n)" kill-pane bind b break-pane -bind u split-window -bind v split-window -h -bind C-u split-window -f -bind C-v split-window -f -h -# bind u split-window -c "#{pane_current_path}" -# bind v split-window -h -c "#{pane_current_path}" -# bind C-u split-window -f -c "#{pane_current_path}" -# bind C-v split-window -f -h -c "#{pane_current_path}" +# bind u split-window +# bind v split-window -h +# bind C-u split-window -f +# bind C-v split-window -f -h +bind u split-window -c "#{pane_current_path}" +bind v split-window -h -c "#{pane_current_path}" +bind C-u split-window -f -c "#{pane_current_path}" +bind C-v split-window -f -h -c "#{pane_current_path}" bind h select-pane -L bind l select-pane -R diff --git a/etc/dotsfile/.vimrc b/etc/dotsfile/.vimrc index 369c2f58..865d124c 100644 --- a/etc/dotsfile/.vimrc +++ b/etc/dotsfile/.vimrc @@ -78,8 +78,9 @@ let g:syntastic_quiet_messages = { "regex": [ \ ] } Plug 'Valloric/YouCompleteMe' -let g:syntastic_enable_signs = 1 -let g:ycm_confirm_extra_conf=0 +let g:ycm_confirm_extra_conf=1 +let g:syntastic_enable_signs=1 +let g:ycm_python_binary_path='/usr/bin/python' nnoremap gd :YcmCompleter GoToDeclaration nnoremap gD :YcmCompleter GoToReferences @@ -136,6 +137,7 @@ nnoremap j gj nnoremap k gk nnoremap :make +inoremap :makei nnoremap df :FZF inoremap df _ @@ -161,6 +163,8 @@ function! Config(type) set filetype=xml elseif a:type == "css" set filetype=css + elseif a:type == "txt" + set noexpandtab endif endfunction @@ -173,6 +177,7 @@ autocmd BufNewFile,BufReadPost *.json call Config("json") autocmd BufNewFile,BufReadPost *.wxml call Config("xml") autocmd BufNewFile,BufReadPost *.wxss call Config("css") +autocmd BufNewFile,BufReadPost *.txt call Config("txt") command! RR wa | source ~/.vimrc |e command! SS mksession! etc/session.vim diff --git a/etc/dotsfile/shy.vim b/etc/dotsfile/shy.vim index ae769fbe..e5cf04e8 100644 --- a/etc/dotsfile/shy.vim +++ b/etc/dotsfile/shy.vim @@ -7,6 +7,8 @@ syntax match shyCache "\(^\|\t\| \|$(\)cache\>" syntax match shyString "'[^']*'" syntax match shyString "\"[^\"]*\"" syntax match shyNumber "-\=\<\d\+\>#\=" +syntax match shyNumber "false" +syntax match shyNumber "true" syntax match shVariable "\$[_a-zA-Z0-9]\+\>" syntax match shVariable "@[_a-zA-Z0-9]\+\>" diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index caf5e2de..1e4335c0 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -145,7 +145,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Conf("runtime", "host.pid", os.Getpid()) if name, e := os.Hostname(); e == nil { - m.Conf("runtime", "boot.hostname", name) + m.Conf("runtime", "boot.hostname", kit.Select(name, os.Getenv("HOSTNAME"))) } if name, e := os.Getwd(); e == nil { _, file := path.Split(name) @@ -308,8 +308,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.GoFunc(m, func(m *ctx.Message) { if e := cmd.Start(); e != nil { + m.Log("fuck", "%v", e) m.Echo("error: ").Echo("%s\n", e) } else if e := cmd.Wait(); e != nil { + m.Log("fuck", "%v", e) m.Echo("error: ").Echo("%s\n", e) } m.Conf("daemon", []string{h, "finish_time"}, time.Now().Format(m.Conf("time_format"))) diff --git a/src/contexts/ctx/ctx_init.go b/src/contexts/ctx/ctx_init.go index aa921641..51a0a930 100644 --- a/src/contexts/ctx/ctx_init.go +++ b/src/contexts/ctx/ctx_init.go @@ -1178,7 +1178,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, return }}, "select": &Command{Name: "select key value field", - Form: map[string]int{"eq": 2, "parse": 2, "hide": -1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0}, + Form: map[string]int{"eq": 2, "expand": 2, "hide": -1, "fields": -1, "group": 1, "order": 2, "limit": 1, "offset": 1, "format": -1, "trans_map": -1, "vertical": 0}, Help: "选取数据", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) { msg := m.Set("result").Spawn() @@ -1189,11 +1189,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, nrow := len(m.Meta[m.Meta["append"][0]]) keys := []string{} for i := 0; i < nrow; i++ { - for j := 0; j < len(m.Meta["parse"]); j += 2 { + for j := 0; j < len(m.Meta["expand"]); j += 2 { var value interface{} - json.Unmarshal([]byte(m.Meta[m.Meta["parse"][j]][i]), &value) - if m.Meta["parse"][j+1] != "" { - value = kit.Chain(value, m.Meta["parse"][j+1]) + json.Unmarshal([]byte(m.Meta[m.Meta["expand"][j]][i]), &value) + if m.Meta["expand"][j+1] != "" { + value = kit.Chain(value, m.Meta["expand"][j+1]) } switch val := value.(type) { @@ -1202,7 +1202,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, keys = append(keys, k) } default: - keys = append(keys, m.Meta["parse"][j+1]) + keys = append(keys, m.Meta["expand"][j+1]) } } } @@ -1212,11 +1212,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, } } for i := 0; i < nrow; i++ { - for j := 0; j < len(m.Meta["parse"]); j += 2 { + for j := 0; j < len(m.Meta["expand"]); j += 2 { var value interface{} - json.Unmarshal([]byte(m.Meta[m.Meta["parse"][j]][i]), &value) - if m.Meta["parse"][j+1] != "" { - value = kit.Chain(value, m.Meta["parse"][j+1]) + json.Unmarshal([]byte(m.Meta[m.Meta["expand"][j]][i]), &value) + if m.Meta["expand"][j+1] != "" { + value = kit.Chain(value, m.Meta["expand"][j+1]) } switch val := value.(type) { @@ -1233,12 +1233,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, } } case string: - m.Meta[m.Meta["parse"][j+1]][i] = val + m.Meta[m.Meta["expand"][j+1]][i] = val case float64: - m.Meta[m.Meta["parse"][j+1]][i] = fmt.Sprintf("%d", int(val)) + m.Meta[m.Meta["expand"][j+1]][i] = fmt.Sprintf("%d", int(val)) default: b, _ := json.Marshal(val) - m.Meta[m.Meta["parse"][j+1]][i] = string(b) + m.Meta[m.Meta["expand"][j+1]][i] = string(b) } } } diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index 8a3623ad..c221c3ba 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -69,6 +69,11 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", "temp": &ctx.Config{Name: "temp", Value: map[string]interface{}{}, Help: "缓存数据"}, "temp_view": &ctx.Config{Name: "temp_view", Value: map[string]interface{}{}, Help: "缓存数据"}, + "note_view": &ctx.Config{Name: "note_view", Value: map[string]interface{}{ + "default": []interface{}{"key", "create_time", "type", "name", "value"}, + "base": []interface{}{"key", "create_time", "type", "name", "value"}, + "full": []interface{}{"key", "create_time", "access_time", "type", "name", "model", "value", "view", "data", "ship"}, + }, Help: "数据视图"}, "note": &ctx.Config{Name: "note", Value: map[string]interface{}{ "faa01a8fc2fc92dae3fbc02ac1b4ec75": map[string]interface{}{ "create_time": "1990-07-30 07:08:09", "access_time": "2017-11-01 02:03:04", @@ -82,7 +87,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", "prev": map[string]interface{}{"type": "model", "data": ""}, }, }, - }, Help: "缓存数据"}, + }, Help: "数据结构"}, }, Commands: map[string]*ctx.Command{ "temp": &ctx.Command{Name: "temp [type [meta [data]]] [tid [node|ship|data] [chain... [select ...]]]", Form: map[string]int{"select": -1, "limit": 1}, Help: "缓存数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { @@ -482,210 +487,242 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", return }}, - "note": &ctx.Command{Name: "note [model name [type name]...]|[index name data...]|[value name data...]|[name model data...]", Form: map[string]int{"limit": 1}, Help: "记事", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - // 节点列表 - if len(arg) == 0 { - m.CopyFuck(m.Cmd("mdb.config", "note", "format", "table", "fields", "create_time", "access_time", "type", "name", "data", "ship"), "append").Set("result").Table() - return - } + "note": &ctx.Command{Name: "note [model [name [type name]...]]|[index [name data...]]|[value name data...]|[name model data...]", + Form: map[string]int{"offset": 1, "limit": 1}, Help: "记事", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + offset := kit.Int(kit.Select(m.Conf("page_offset"), m.Option("offset"))) + limit := kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit"))) - // 节点详情 - if note := m.Confm("note", arg[0]); note != nil { - m.CopyFuck(m.Cmd("mdb.config", "note", arg[0]), "append").Set("result").Table() - return - } - - // 节点列表 - hm, _ := kit.Hash("type", arg[0], "name", "shy") - if len(arg) == 2 && arg[0] == "value" { - hm, _ = kit.Hash("type", "index", "name", arg[1]) - hm = m.Conf("note", []string{hm, "ship", "value", "data"}) - arg = arg[1:] - } else if len(arg) == 2 && arg[0] == "note" { - hm, _ = kit.Hash("type", "model", "name", arg[1]) - hm = m.Conf("note", []string{hm, "ship", "note", "data"}) - arg = arg[1:] - } - - if len(arg) == 1 { - for i := 0; hm != "" && i < kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit"))); hm, i = m.Conf("note", []string{hm, "ship", "prev", "data"}), i+1 { - model := m.Confm("note", hm) - m.Add("append", "key", hm) - m.Add("append", "create_time", model["create_time"]) - m.Add("append", "access_time", model["access_time"]) - m.Add("append", "type", model["type"]) - m.Add("append", "name", model["name"]) - m.Add("append", "view", kit.Format(model["view"])) - m.Add("append", "data", kit.Format(model["data"])) - m.Add("append", "ship", kit.Format(model["ship"])) + // 节点列表 + if len(arg) == 0 { + m.CopyFuck(m.Cmd("mdb.config", "note", "format", "table", "fields", "create_time", "access_time", "type", "name", "data", "ship"), "append").Set("result").Table() + return } - m.Table() - return - } - switch arg[0] { - case "search": - hv, _ := kit.Hash("type", "value", "name", arg[1], "data", kit.Select(m.Option(arg[1]), arg, 2)) - hn := m.Conf("note", []string{hv, "ship", "note", "data"}) + // 节点详情 + if note := m.Confm("note", arg[0]); note != nil { + m.CopyFuck(m.Cmd("mdb.config", "note", arg[0]), "append").Set("result").Table() + return + } - for i := 0; hn != "" && i < kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit"))); hn, i = m.Conf("note", []string{hn, "ship", hv, "data"}), i+1 { - note := m.Confm("note", hn) - hvs := kit.Trans(note["data"]) - hm := kit.Format(kit.Chain(note, "ship.model.data")) + // 节点列表 + hm, _ := kit.Hash("type", arg[0], "name", "shy") + if len(arg) == 2 && arg[0] == "value" { + hm, _ = kit.Hash("type", "index", "name", arg[1]) + hm = m.Conf("note", []string{hm, "ship", "value", "data"}) + arg = arg[1:] + } else if len(arg) == 2 && arg[0] == "note" { + hm, _ = kit.Hash("type", "model", "name", arg[1]) + hm = m.Conf("note", []string{hm, "ship", "note", "data"}) + arg = arg[1:] + } + if len(arg) == 1 && arg[0] != "show" { + for i := offset; hm != "" && i < limit; hm, i = m.Conf("note", []string{hm, "ship", "prev", "data"}), i+1 { + model := m.Confm("note", hm) + m.Add("append", "key", hm) + m.Add("append", "create_time", model["create_time"]) + m.Add("append", "access_time", model["access_time"]) + m.Add("append", "type", model["type"]) + m.Add("append", "name", model["name"]) + m.Add("append", "view", kit.Format(model["view"])) + m.Add("append", "data", kit.Format(model["data"])) + m.Add("append", "ship", kit.Format(model["ship"])) + } + m.Table() + return + } - value := []interface{}{} - m.Confm("note", []string{hm, "data"}, func(i int, model map[string]interface{}) { - value = append(value, map[string]interface{}{ - "type": model["type"], "name": model["name"], - "value": m.Conf("note", []string{hvs[i], "data"}), + switch arg[0] { + case "show": + if len(arg) == 1 { + m.Cmdy("mdb.note", "index") + break + } + if len(arg) == 2 { + if arg[1] == "model" { + m.Cmdy("mdb.note", "model") + } else { + m.Cmdy("mdb.note", "value", arg[1]) + } + break + } + + fields := kit.View(arg[3:], m.Confm("note_view")) + + hv, _ := kit.Hash("type", "value", "name", arg[1], "data", kit.Select(m.Option(arg[1]), arg, 2)) + hn := m.Conf("note", []string{hv, "ship", "note", "data"}) + if arg[1] == "model" { + hm, _ := kit.Hash("type", "model", "name", arg[2]) + hv, hn = "prev", m.Conf("note", []string{hm, "ship", "note", "data"}) + } + + for i := offset; hn != "" && i < limit; hn, i = m.Conf("note", []string{hn, "ship", hv, "data"}), i+1 { + note := m.Confm("note", hn) + hvs := kit.Trans(note["data"]) + hm := kit.Format(kit.Chain(note, "ship.model.data")) + + for i := 0; i < len(fields); i++ { + switch fields[i] { + case "key": + m.Add("append", "key", hn) + case "create_time", "access_time", "type", "name": + m.Add("append", fields[i], note[fields[i]]) + case "model": + m.Add("append", "model", m.Conf("note", []string{hm, "name"})) + case "view": + m.Add("append", "view", kit.Format(m.Conf("note", []string{hm, "view"}))) + case "value": + value := []interface{}{} + m.Confm("note", []string{hm, "data"}, func(i int, model map[string]interface{}) { + value = append(value, map[string]interface{}{ + "type": model["type"], "name": model["name"], + "value": m.Conf("note", []string{hvs[i], "data"}), + }) + }) + m.Add("append", "value", kit.Format(value)) + case "data", "ship": + m.Add("append", fields[i], kit.Format(note[fields[i]])) + } + } + } + m.Table() + + case "model": + // 模板详情 + hm, _ := kit.Hash("type", arg[0], "name", arg[1]) + if len(arg) == 2 { + m.CopyFuck(m.Cmd("mdb.config", "note", hm), "append").Set("result").Table() + break + } + if arg[2] == "view" { + for i := 4; i < len(arg)-1; i += 2 { + m.Conf("note", []string{hm, "view", arg[3], arg[i]}, arg[i+1]) + } + break + } + + // 操作模板 + data := []interface{}{} + if model := m.Confm("note", hm); model == nil { // 添加模板 + prev := m.Conf("note", []string{"81c5709d091eb04bd31ee751c3f81023", "ship", "prev", "data"}) + m.Confv("note", hm, map[string]interface{}{ + "create_time": m.Time(), "access_time": m.Time(), + "type": "model", "name": arg[1], "data": data, "ship": map[string]interface{}{ + "prev": map[string]interface{}{"type": "model", "data": prev}, + "note": map[string]interface{}{"type": "note", "data": ""}, + }, }) - }) - - m.Add("append", "key", hn) - m.Add("append", "create_time", note["create_time"]) - m.Add("append", "access_time", note["access_time"]) - m.Add("append", "type", note["type"]) - m.Add("append", "name", note["name"]) - m.Add("append", "model", m.Conf("note", []string{hm, "name"})) - m.Add("append", "view", kit.Format(m.Conf("note", []string{hm, "view"}))) - m.Add("append", "value", kit.Format(value)) - m.Add("append", "data", kit.Format(note["data"])) - m.Add("append", "ship", kit.Format(note["ship"])) - } - m.Table() - - case "model": - // 模板详情 - hm, _ := kit.Hash("type", arg[0], "name", arg[1]) - if len(arg) == 2 { - m.CopyFuck(m.Cmd("mdb.config", "note", hm), "append").Set("result").Table() - break - } - if arg[2] == "view" { - for i := 4; i < len(arg)-1; i += 2 { - m.Conf("note", []string{hm, "view", arg[3], arg[i]}, arg[i+1]) + m.Conf("note", []string{"81c5709d091eb04bd31ee751c3f81023", "ship", "prev", "data"}, hm) + } else { // 修改模板 + data = m.Confv("note", []string{hm, "data"}).([]interface{}) + m.Confv("note", []string{hm, "access_time"}, m.Time()) } - break - } - // 操作模板 - data := []interface{}{} - if model := m.Confm("note", hm); model == nil { // 添加模板 - prev := m.Conf("note", []string{"81c5709d091eb04bd31ee751c3f81023", "ship", "prev", "data"}) - m.Confv("note", hm, map[string]interface{}{ - "create_time": m.Time(), "access_time": m.Time(), - "type": "model", "name": arg[1], "data": data, "ship": map[string]interface{}{ - "prev": map[string]interface{}{"type": "model", "data": prev}, - "note": map[string]interface{}{"type": "note", "data": ""}, - }, - }) - m.Conf("note", []string{"81c5709d091eb04bd31ee751c3f81023", "ship", "prev", "data"}, hm) - } else { // 修改模板 - data = m.Confv("note", []string{hm, "data"}).([]interface{}) - m.Confv("note", []string{hm, "access_time"}, m.Time()) - } + if len(data) == 0 { // 操作元素 + for i := 2; i < len(arg)-1; i += 2 { + data = append(data, map[string]interface{}{"name": arg[i], "type": arg[i+1]}) - // 操作元素 - for i := 2; i < len(arg)-1; i += 2 { - data = append(data, map[string]interface{}{"name": arg[i], "type": arg[i+1]}) - - hi, _ := kit.Hash("type", "index", "name", arg[i+1]) - if index := m.Confm("note", hi); index == nil { - m.Cmd("mdb.note", "index", arg[i+1]) + hi, _ := kit.Hash("type", "index", "name", arg[i+1]) + if index := m.Confm("note", hi); index == nil { + m.Cmd("mdb.note", "index", arg[i+1]) + } + } } - } - m.Confv("note", []string{hm, "data"}, data) - m.Echo(hm) - case "index": - // 操作索引 - data := arg[2:] - hi, _ := kit.Hash("type", arg[0], "name", arg[1]) - if index := m.Confm("note", hi); index == nil { // 添加索引 - prev := m.Conf("note", []string{"faa01a8fc2fc92dae3fbc02ac1b4ec75", "ship", "prev", "data"}) - m.Confv("note", hi, map[string]interface{}{ - "create_time": m.Time(), "access_time": m.Time(), - "type": "index", "name": arg[1], "data": data, "ship": map[string]interface{}{ - "prev": map[string]interface{}{"type": "index", "data": prev}, - "value": map[string]interface{}{"type": "value", "data": ""}, - }, + m.Confv("note", []string{hm, "data"}, data) + m.Echo(hm) + + case "index": + // 操作索引 + data := arg[2:] + hi, _ := kit.Hash("type", arg[0], "name", arg[1]) + if index := m.Confm("note", hi); index == nil { // 添加索引 + prev := m.Conf("note", []string{"faa01a8fc2fc92dae3fbc02ac1b4ec75", "ship", "prev", "data"}) + m.Confv("note", hi, map[string]interface{}{ + "create_time": m.Time(), "access_time": m.Time(), + "type": "index", "name": arg[1], "data": data, "ship": map[string]interface{}{ + "prev": map[string]interface{}{"type": "index", "data": prev}, + "value": map[string]interface{}{"type": "value", "data": ""}, + }, + }) + m.Confv("note", []string{"faa01a8fc2fc92dae3fbc02ac1b4ec75", "ship", "prev", "data"}, hi) + } else { // 修改索引 + m.Confv("note", []string{hi, "access_time"}, m.Time()) + data, _ = m.Confv("note", []string{hi, "data"}).([]string) + } + + // 操作元素 + m.Confv("note", []string{hi, "data"}, data) + m.Echo(hi) + + case "value": + hi := m.Cmdx("mdb.note", "index", arg[1]) + hv, _ := kit.Hash("type", arg[0], "name", arg[1], "data", arg[2:]) + if value := m.Confm("note", hv); value == nil { + prev := m.Conf("note", []string{hi, "ship", "value", "data"}) + m.Confv("note", hv, map[string]interface{}{ + "create_time": m.Time(), "access_time": m.Time(), + "type": arg[0], "name": arg[1], "data": arg[2:], "ship": map[string]interface{}{ + "prev": map[string]interface{}{"type": "value", "data": prev}, + "index": map[string]interface{}{"type": "index", "data": hi}, + "note": map[string]interface{}{"type": "note", "data": ""}, + }, + }) + m.Conf("note", []string{hi, "ship", "value", "data"}, hv) + } else { + m.Confv("note", []string{hv, "access_time"}, m.Time()) + } + m.Echo(hv) + + default: + if len(arg) == 2 { + } + + hm, _ := kit.Hash("type", "model", "name", arg[1]) + hn, _ := kit.Hash("type", "note", "name", arg[0], "uniq") + ship := map[string]interface{}{ + "prev": map[string]interface{}{"type": "note", "data": m.Conf("note", []string{hm, "ship", "note", "data"})}, + "model": map[string]interface{}{"type": "model", "data": hm}, + } + + data := []interface{}{} + m.Confm("note", []string{hm, "data"}, func(i int, index map[string]interface{}) { + hv := m.Cmdx("mdb.note", "value", index["type"], kit.Select(m.Option(kit.Format(index["name"])), arg, i+2)) + data = append(data, hv) + + ship[hv] = map[string]interface{}{"type": "note", "data": m.Conf("note", []string{hv, "ship", "note", "data"})} + m.Conf("note", []string{hv, "ship", "note", "data"}, hn) }) - m.Confv("note", []string{"faa01a8fc2fc92dae3fbc02ac1b4ec75", "ship", "prev", "data"}, hi) - } else { // 修改索引 - m.Confv("note", []string{hi, "access_time"}, m.Time()) - data, _ = m.Confv("note", []string{hi, "data"}).([]string) - } - // 操作元素 - m.Confv("note", []string{hi, "data"}, data) - m.Echo(hi) - - case "value": - hi := m.Cmdx("mdb.note", "index", arg[1]) - hv, _ := kit.Hash("type", arg[0], "name", arg[1], "data", arg[2:]) - if value := m.Confm("note", hv); value == nil { - prev := m.Conf("note", []string{hi, "ship", "value", "data"}) - m.Confv("note", hv, map[string]interface{}{ + m.Confv("note", hn, map[string]interface{}{ "create_time": m.Time(), "access_time": m.Time(), - "type": arg[0], "name": arg[1], "data": arg[2:], "ship": map[string]interface{}{ - "prev": map[string]interface{}{"type": "value", "data": prev}, - "index": map[string]interface{}{"type": "index", "data": hi}, - "note": map[string]interface{}{"type": "note", "data": ""}, - }, + "type": "note", "name": arg[0], "data": data, "ship": ship, }) - m.Conf("note", []string{hi, "ship", "value", "data"}, hv) - } else { - m.Confv("note", []string{hv, "access_time"}, m.Time()) + m.Conf("note", []string{hm, "ship", "note", "data"}, hn) + m.Echo(hn) } - m.Echo(hv) + return - default: - hm, _ := kit.Hash("type", "model", "name", arg[1]) - hn, _ := kit.Hash("type", "note", "name", arg[0], "uniq") - ship := map[string]interface{}{ - "prev": map[string]interface{}{"type": "note", "data": m.Conf("note", []string{hm, "ship", "note", "data"})}, - "model": map[string]interface{}{"type": "model", "data": hm}, + sync := len(arg) > 0 && arg[0] == "sync" + if sync { + m.Cmdy("ssh.sh", "sub", "context", "mdb", "note", arg) + m.Set("result").Table() + arg = arg[1:] } - data := []interface{}{} - m.Confm("note", []string{hm, "data"}, func(i int, index map[string]interface{}) { - hv := m.Cmdx("mdb.note", "value", index["type"], kit.Select(m.Option(kit.Format(index["name"])), arg, i+2)) - data = append(data, hv) - - ship[hv] = map[string]interface{}{"type": "note", "data": m.Conf("note", []string{hv, "ship", "note", "data"})} - m.Conf("note", []string{hv, "ship", "note", "data"}, hn) - }) - - m.Confv("note", hn, map[string]interface{}{ - "create_time": m.Time(), "access_time": m.Time(), - "type": "note", "name": arg[0], "data": data, "ship": ship, - }) - m.Conf("note", []string{hm, "ship", "note", "data"}, hn) - m.Echo(hn) - } - return - - sync := len(arg) > 0 && arg[0] == "sync" - if sync { - m.Cmdy("ssh.sh", "sub", "context", "mdb", "note", arg) - m.Set("result").Table() - arg = arg[1:] - } - - h, _ := kit.Hash("uniq") - data := map[string]interface{}{ - "create_time": m.Time(), - "type": arg[0], - "title": arg[1], - "content": arg[2], - } - for i := 3; i < len(arg)-1; i += 2 { - kit.Chain(data, data[arg[i]], arg[i+1]) - } - m.Conf("note", h, data) - m.Echo(h) - return - }}, + h, _ := kit.Hash("uniq") + data := map[string]interface{}{ + "create_time": m.Time(), + "type": arg[0], + "title": arg[1], + "content": arg[2], + } + for i := 3; i < len(arg)-1; i += 2 { + kit.Chain(data, data[arg[i]], arg[i+1]) + } + m.Conf("note", h, data) + m.Echo(h) + return + }}, }, } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 4cd1bfe4..db532cc1 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -1274,6 +1274,10 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", return true }, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) == 0 { + return + } + m.Confm("paths", func(index int, value string) bool { p := path.Join(value, arg[0]) if _, e := os.Stat(p); e == nil { diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index fe03af81..e5d94a8c 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -385,12 +385,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", "site": "", "index": "/code/", }, Help: "服务配置"}, - "login": &ctx.Config{Name: "login", Value: map[string]interface{}{ - "check": true, - "sess_void": false, - "cas_url": "", - "cas_uuid": "email", - }, Help: "认证配置"}, "route": &ctx.Config{Name: "route", Value: map[string]interface{}{ "index": "/render", "template_dir": "usr/template", @@ -400,6 +394,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", "top": 96, "left": 472, "width": 600, "height": 300, }, }, Help: "功能配置"}, + "login": &ctx.Config{Name: "login", Value: map[string]interface{}{ + "check": true, + "sess_void": false, + "cas_url": "", + "cas_uuid": "email", + }, Help: "认证配置"}, "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{ "login": []interface{}{}, "index": []interface{}{ @@ -577,24 +577,27 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", m.Log("warn", "%v", e) return e } - if kit.Right(client["logheaders"]) { - for k, v := range res.Header { - m.Log("info", "%s: %v", k, v) - } - } - for _, v := range res.Cookies() { - m.Conf("spide", []string{which, "cookie", v.Name}, v.Value) - m.Log("info", "get-cookie %s: %v", v.Name, v.Value) - } - if res.StatusCode != http.StatusOK { - return nil - } var result interface{} ct := res.Header.Get("Content-Type") parse := kit.Select(kit.Format(client["parse"]), m.Option("parse")) m.Log("info", "status %s parse: %s content: %s", res.Status, parse, ct) + if kit.Right(client["logheaders"]) { + for k, v := range res.Header { + m.Log("info", "%s: %v", k, v) + } + } + + for _, v := range res.Cookies() { + m.Conf("spide", []string{which, "cookie", v.Name}, v.Value) + m.Log("info", "get-cookie %s: %v", v.Name, v.Value) + } + + if res.StatusCode != http.StatusOK { + return nil + } + switch { case parse == "json" || strings.HasPrefix(ct, "application/json") || strings.HasPrefix(ct, "application/javascript"): if json.NewDecoder(res.Body).Decode(&result); !m.Has("temp") { @@ -871,10 +874,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", return }}, - "/MP_verify_0xp0zkW3fIzIq2Bo.txt": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Echo("0xp0zkW3fIzIq2Bo") - return - }}, "/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { fields := strings.Split(key, "/") m.Cmdy("web.get", "which", fields[2], "method", fields[3], strings.Join(fields, "/")) diff --git a/src/toolkit/kit.go b/src/toolkit/kit.go index 1a1b2f92..30c6e25c 100644 --- a/src/toolkit/kit.go +++ b/src/toolkit/kit.go @@ -475,6 +475,21 @@ func Chain(root interface{}, args ...interface{}) interface{} { return root } +func View(args []string, conf map[string]interface{}) []string { + if len(args) == 0 { + args = append(args, "default") + } + + keys := []string{} + for _, k := range args { + if v, ok := conf[k]; ok { + keys = append(keys, Trans(v)...) + } else { + keys = append(keys, k) + } + } + return keys +} func Link(name string, url string) string { return fmt.Sprintf("%s", url, name)