diff --git a/etc/exit.shy b/etc/exit.shy index 032526e8..aa32e704 100644 --- a/etc/exit.shy +++ b/etc/exit.shy @@ -1,4 +1,6 @@ # 应用配置 +~chat + config save var/tmp/share.json share ~wiki config save var/tmp/story.json story ~code diff --git a/etc/init.shy b/etc/init.shy index 0f0a6af1..829e67e8 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -7,7 +7,6 @@ ~ssh config load data/work.json work config load data/flow.json flow - # 服务配置 ~nfs source etc/common.shy @@ -23,9 +22,12 @@ config load tmp/vim/vim.json vim ~wiki config load tmp/story.json story +~chat + config load tmp/share.json share # 终端配置 ~cli -~wiki ~code +~wiki +~chat diff --git a/src/contexts/ctx/misc.go b/src/contexts/ctx/misc.go index a67f1efa..ded070e4 100644 --- a/src/contexts/ctx/misc.go +++ b/src/contexts/ctx/misc.go @@ -506,6 +506,9 @@ func (m *Message) ToHTML(style string) string { func (m *Message) Grow(key string, args interface{}, data interface{}) interface{} { cache := m.Confm(key, args) + if args == nil { + cache = m.Confm(key) + } if cache == nil { cache = map[string]interface{}{} } @@ -579,11 +582,18 @@ func (m *Message) Grow(key string, args interface{}, data interface{}) interface } cache["meta"] = meta cache["list"] = list - m.Conf(key, args, cache) + if args == nil { + m.Conf(key, cache) + } else { + m.Conf(key, args, cache) + } return list } func (m *Message) Grows(key string, args interface{}, cb interface{}) map[string]interface{} { cache := m.Confm(key, args) + if args == nil { + cache = m.Confm(key) + } if cache == nil { return nil } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 23b2a31a..69344be2 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -967,11 +967,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", kind := h.Header.Get("Content-Type") kind = strings.Split(kind, "/")[0] - if m.Options("river") { - prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "insert"} - m.Cmd(prefix, kit.Select(kind, m.Option("table")), "name", h.Filename, "kind", kind, "hash", name, "size", n) - m.Cmd(prefix, "file", "name", h.Filename, "kind", kind, "hash", name, "size", n) - } buf := bytes.NewBuffer(make([]byte, 0, 1024)) fmt.Fprintf(buf, "create_time: %s\n", m.Time("2006-01-02 15:04")) @@ -983,6 +978,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", b := buf.Bytes() code := kit.Hashs(string(b)) + if m.Options("river") { + prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "insert"} + m.Cmd(prefix, kit.Select(kind, m.Option("table")), "name", h.Filename, "kind", kind, "hash", name, "size", n) + m.Cmd(prefix, "file", "name", h.Filename, "kind", kind, "hash", name, "size", n, "code", code) + } + if o, p, e := kit.Create(path.Join(m.Conf("web.upload", "path"), "meta", code)); m.Assert(e) { defer o.Close() diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go index 032a31f4..06f29274 100644 --- a/src/examples/chat/chat.go +++ b/src/examples/chat/chat.go @@ -5,6 +5,7 @@ import ( "contexts/web" "net/http" + "strings" "toolkit" ) @@ -97,6 +98,15 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", }, }, }, Help: "组件列表"}, + "share": &ctx.Config{Name: "share", Value: map[string]interface{}{ + "meta": map[string]interface{}{ + "fields": "id time share type code remote_ip", + "store": "var/tmp/share.csv", + "limit": 30, "least": 10, + }, + "hash": map[string]interface{}{}, + "list": []interface{}{}, + }, Help: "共享链接"}, }, Commands: map[string]*ctx.Command{ "login": &ctx.Command{Name: "login [username password]", Help: "登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { @@ -462,6 +472,49 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心", } return }}, + + "/share/": &ctx.Command{Name: "/share/", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + h := strings.TrimPrefix(key, "/share/") + m.Confm("share", []string{"hash", h}, func(value map[string]interface{}) { + switch kit.Format(value["type"]) { + case "file": + m.Cmdy("/download/" + h) + case "wiki": + m.Cmdy("web.wiki.note", kit.Format(value["code"])) + } + m.Grow("share", nil, map[string]interface{}{ + "time": m.Time(), + "share": h, + "type": value["type"], + "code": value["code"], + "sid": m.Option("sid"), + "agent": m.Option("agent"), + "sessid": m.Option("sessid"), + "username": m.Option("username"), + "remote_ip": m.Option("remote_ip"), + }) + }) + return + }}, + "share": &ctx.Command{Name: "share type code", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) == 0 { + fields := strings.Split(m.Conf("share", "meta.fields"), " ") + m.Grows("share", nil, func(meta map[string]interface{}, index int, value map[string]interface{}) { + m.Push(fields, value) + }) + m.Table() + return + } + h := kit.Hashs("uniq") + m.Confv("share", []string{"hash", h}, map[string]interface{}{ + "from": m.Option("username"), + "time": m.Time(), + "type": arg[0], + "code": arg[1], + }) + m.Echo(h) + return + }}, }, } diff --git a/src/examples/code/code.go b/src/examples/code/code.go index 82556d57..782b1770 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -346,10 +346,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", // 文件列表 m.Cmd("ssh.data", "show", arg[1]).Table(func(index int, value map[string]string) { m.Push("id", value["id"]) + m.Push("time", value["create_time"]) m.Push("kind", value["kind"]) m.Push("name", value["name"]) m.Push("size", kit.FmtSize(int64(kit.Int(value["size"])))) - m.Push("file", fmt.Sprintf(`%s`, value["hash"], value["name"])) + m.Push("file", fmt.Sprintf(`%s`, kit.Select(value["hash"], value["code"]), value["name"])) m.Push("hash", value["hash"]) }) m.Table() diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 9c2e78af..1b26e832 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -64,7 +64,6 @@ var page = Page({ page.action.Action["最大"](event) } - break } else { switch (event.key) { case " ": @@ -75,7 +74,6 @@ var page = Page({ break } } - break }, Action: { diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 0e8e3be1..faf61eac 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -139,7 +139,7 @@ function Page(page) { // Event入口 0 if (page.Event(event, {}) && page.check && !ctx.Cookie("sessid")) { // 用户登录 - document.querySelectorAll("body>fieldset.Login").forEach(function(field) { + kit.Selector(document, "body>fieldset.Login", function(field) { page.Pane(page, field) }), page.login.Pane.Dialog(1, 1) } else { @@ -1479,7 +1479,7 @@ function Output(plugin, type, msg, cb, target, option) { onimport: shy("导入数据", { _table: function(msg, list) { return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), msg.Table(), list), "", output.onexport, function(event, value, name, line, index) { - var td = event.target + var td = event.target; plugin.oncarte(event, shy("菜单列表", { "修改": "modify", "删除": "delete", @@ -1528,7 +1528,7 @@ function Output(plugin, type, msg, cb, target, option) { }) } return true - }), + }) ) }) }, diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index fc2d4614..7a8715af 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -262,7 +262,7 @@ kit = toolkit = (function() {var kit = {__proto__: document, child.list && kit.AppendChild(node, child.list, subs) subs.first || (subs.first = node), subs.last = node name && (subs[name] = node) - parent.append(node) + parent && parent.append && parent.append(node) }) return subs }, diff --git a/usr/template/common.tmpl b/usr/template/common.tmpl index 7a76beba..3799c9fe 100644 --- a/usr/template/common.tmpl +++ b/usr/template/common.tmpl @@ -9,7 +9,7 @@ {{range $index, $lib := option . "styles"}} - + {{end}}
@@ -18,7 +18,7 @@ {{define "fieldset"}}