From 2af0963fd2ebe3cbe76a67ad1d547a38897412b5 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 2 Jul 2019 17:10:19 +0800 Subject: [PATCH] fix nfs.Send len --- src/contexts/cli/cli.go | 14 +++++++++++++- src/contexts/cli/version.go | 2 +- src/contexts/ctx/ctx.go | 3 +++ src/contexts/nfs/nfs.go | 18 +++++++++++++++++- src/contexts/ssh/ssh.go | 6 +++--- src/contexts/web/web.go | 1 - usr/librarys/chat.js | 2 +- usr/librarys/context.js | 2 +- usr/librarys/example.css | 8 ++++++-- usr/librarys/example.js | 12 ++++++------ usr/librarys/toolkit.js | 2 ++ 11 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 62713ee3..ab145891 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -241,7 +241,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", } if name, e := os.Getwd(); e == nil { _, file := path.Split(kit.Select(name, os.Getenv("PWD"))) - m.Conf("runtime", "boot.pathname", file) + ns := strings.Split(file, "\\") + m.Conf("runtime", "boot.pathname", ns[len(ns)-1]) m.Conf("runtime", "boot.ctx_path", name) } return @@ -447,8 +448,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Gos(m, func(m *ctx.Message) { if e := cmd.Start(); e != nil { m.Echo("error: ").Echo("%s\n", e) + m.Log("fuck", "%v", e) } else if e := cmd.Wait(); e != nil { m.Echo("error: ").Echo("%s\n", e) + m.Log("fuck", "%v", e) } m.Conf("daemon", []string{h, "finish_time"}, time.Now().Format(m.Conf("time_format"))) }) @@ -785,6 +788,15 @@ var version = struct { }) } + m.Cmdy("cli.system", path.Join(m.Conf("runtime", "boot.ctx_home"), "bin/node.sh"), "create", arg[0], + "cmd_env", "PATH", os.Getenv("path"), + "cmd_dir", m.Conf("missyou", "path"), + "cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"), + "cmd_env", "ctx_ups", fmt.Sprintf("127.0.0.1%s", m.Conf("runtime", "boot.ssh_port")), + "cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")), + "cmd_daemon", "true", + ) + return m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), "daemon", "cmd_dir", p, "cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"), diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index c2054e39..4f7a09f1 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-07-01 20:57:35", "ZYB-20190522USI", 62, + "2019-07-02 17:07:03", "ZYB-20190522USI", 84, } diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index 2c696590..5d143090 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -1408,6 +1408,9 @@ func Start(args ...string) bool { } kit.DisableLog = true + if len(args) > 0 && args[0] == "start" { + args = args[1:] + } if len(args) > 0 && args[0] == "daemon" { Pulse.Options("cli.modal", "daemon") Pulse.Options("daemon", true) diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index dbdfcf60..aac6db61 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -816,7 +816,23 @@ func (nfs *NFS) Send(meta string, arg ...interface{}) *NFS { line := "\n" if meta != "" { - line = fmt.Sprintf("%s: %s\n", url.QueryEscape(meta), url.QueryEscape(kit.Format(arg[0]))) + if text, ok := arg[0].(string); ok && meta == "result" && len(text) > 1024 { + text := arg[0].(string) + for i := 0; i < len(text); i += 1024 { + j := i + 1024 + if j >= len(text) { + j = len(text) + } + line = fmt.Sprintf("%s: %s\n", url.QueryEscape(meta), url.QueryEscape(kit.Format(text[i:j]))) + n, e := fmt.Fprint(nfs.io, line) + m.Assert(e) + m.Capi("nwrite", n) + m.Log("send", "%d [%s]", len(line), line) + } + return nfs + } else { + line = fmt.Sprintf("%s: %s\n", url.QueryEscape(meta), url.QueryEscape(kit.Format(arg[0]))) + } } n, e := fmt.Fprint(nfs.io, line) diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index 753bf4ab..f449833f 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -177,7 +177,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_args": []interface{}{"$$", "context", "aaa", "clip"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "action": "auto"}, map[string]interface{}{"type": "text", "name": "txt", "view": "long"}, - map[string]interface{}{"type": "button", "value": "存储"}, + map[string]interface{}{"type": "button", "value": "存储", "action": "auto"}, }, }, map[string]interface{}{"componet_name": "qrcode", "componet_help": "二维码", @@ -232,7 +232,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_args": []interface{}{"$$", "context", "$$", "context"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod", "action": "auto"}, - map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"}, + map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx", "action": "auto"}, map[string]interface{}{"type": "button", "value": "查看"}, }, "exports": []interface{}{"ctx", "names"}, @@ -242,7 +242,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_args": []interface{}{"$$", "context", "$$", "command"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"}, + map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"}, map[string]interface{}{"type": "text", "name": "cmd", "value": "pwd"}, map[string]interface{}{"type": "button", "value": "执行"}, }, diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index ff6b2f9a..b67f4223 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -650,7 +650,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", // 发送请求 res, e := web.Client.Do(req) - m.Log("info", "%s %s", req, e) if e != nil { m.Log("warn", "%v", e) return e diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index bb80d8be..ff445fb6 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -486,7 +486,7 @@ page = Page({ init: function(page) { page.onlayout(null, page.conf.layout) page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "办公": "工作") - page.footer.Pane.Order({"site": "", "ip": "", "text": "", ":":""}, kit.isMobile? ["site", "ip", "text"]: ["ip", "text", ":"], function(event, item, value) {}) + page.footer.Pane.Order({"ncmd": "", "text": "", ":":""}, kit.isMobile? ["ncmd", "text"]: ["ncmd", "text", ":"], function(event, item, value) {}) page.header.Pane.Order({"logout": "logout", "user": ""}, ["logout", "user"], function(event, item, value) { switch (item) { case "title": diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 74fbe5f4..36412f57 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -4,7 +4,7 @@ ctx = context = { for (var k in dataset) { option[k] = dataset[k].split(",") } - kit.Log(cmd) + kit.History.add("cmd", option) this.GET("", option, function(msg) { msg[0] && (msg = msg[0]) // msg && (msg.__proto__ = (page || {})) diff --git a/usr/librarys/example.css b/usr/librarys/example.css index 52771c8d..47be0a5e 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -89,14 +89,18 @@ fieldset.toast { fieldset.toast>div.output { padding:0 10px; } -fieldset.toast>div.output pre { +fieldset.toast>div.output>div.title { + font-size:12px; +} +fieldset.toast>div.output>div.content { word-break:break-word; white-space:pre-wrap; text-align:center; margin:0px; + padding:2px; font-size:16px; } -fieldset.toast>div.output div.tick { +fieldset.toast>div.output>div.tick { font-size:12px; } fieldset.dialog { diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 3729fdd2..1580ade6 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -108,14 +108,14 @@ function Page(page) { ontoast: function(text, title, duration) { var args = typeof text == "object"? text: {text: text, title: title, duration: duration} var toast = kit.ModifyView("fieldset.toast", { - display: "block", dialog: [args.width||300, args.height||50], padding: 10, + display: "block", dialog: [args.width||text.length*10+100, args.height||60], padding: 10, }) if (!text) { toast.style.display = "none" return } - var list = [{text: [args.text||""]}] + var list = [{text: [title||"", "div", "title"]}, {text: [args.text||"", "div", "content"]}] args.inputs && args.inputs.forEach(function(input) { if (typeof input == "string") { list.push({inner: input, type: "label", style: {"margin-right": "5px"}}) @@ -145,7 +145,7 @@ function Page(page) { }) list.push({view: ["tick"], name: "tick"}) - kit.ModifyNode(toast.querySelector("legend"), args.title||"tips") + // kit.ModifyNode(toast.querySelector("legend"), args.title||"tips") var ui = kit.AppendChild(kit.ModifyNode(toast.querySelector("div.output"), ""), list) var tick = 1 var begin = kit.time(0,"%H:%M:%S") @@ -547,7 +547,6 @@ function Plugin(page, pane, field) { var output = field.querySelector("div.output") var count = 0 - var wait = false var plugin = field.Script || {}; plugin.__proto__ = { __proto__: pane, Append: function(item, name) { @@ -678,6 +677,7 @@ function Plugin(page, pane, field) { }) }, Runs: function(event, cb) { + page.footer.Pane.State("ncmd", kit.History.get("cmd").length) var args = kit.Selector(option, ".args", function(item, index) { return item.value }) @@ -685,10 +685,10 @@ function Plugin(page, pane, field) { setTimeout(function() { show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1) }, 1000) - wait = true, event.Plugin = plugin, field.Run(event, args, function(msg) { + event.Plugin = plugin, field.Run(event, args, function(msg) { show = false, page.ontoast("") plugin.ondaemon[display.deal||"table"](msg) - wait = false, typeof cb == "function" && cb(msg) + typeof cb == "function" && cb(msg) }) }, Delay: function(time, event, text) { diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 3b3fd248..72685f27 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -28,6 +28,8 @@ kit = toolkit = { console.log(arguments.length == 1? args[0]: args) return args }, + Delay: function(time, cb) { + }, ModifyView: function(which, args) { var height = document.body.clientHeight-4