From c2cdeef2b179c4ac56f27e935dc7f8772eaa812b Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 2 Oct 2019 09:27:45 +0800 Subject: [PATCH] add love.pics --- src/contexts/aaa/aaa.go | 4 ++-- src/contexts/cli/version.go | 2 +- src/contexts/web/web.go | 44 +++++++++++++++++++++++++++++-------- src/plugin/love/index.css | 5 +++++ src/plugin/love/index.shy | 9 +++++++- src/plugin/love/pics.js | 30 +++++++++++++++++++++++++ usr/librarys/context.js | 5 ++++- usr/librarys/example.js | 13 +++++++++-- usr/librarys/toolkit.js | 2 +- 9 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 src/plugin/love/pics.js diff --git a/src/contexts/aaa/aaa.go b/src/contexts/aaa/aaa.go index 1c5f53c9..df6b3f97 100644 --- a/src/contexts/aaa/aaa.go +++ b/src/contexts/aaa/aaa.go @@ -779,8 +779,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", // 生成证书 template := x509.Certificate{ - SerialNumber: big.NewInt(1), - IsCA: true, + SerialNumber: big.NewInt(1), + IsCA: true, BasicConstraintsValid: true, KeyUsage: x509.KeyUsageCertSign, Subject: pkix.Name{CommonName: kit.Format(common)}, diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 8b344788..8cf281b0 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -7,5 +7,5 @@ var version = struct { self int }{ []string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"}, - `2019-09-30 15:01:56`, `centos`, 622, + `2019-10-01 22:57:21`, `mac`, 631, } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index a11e58cf..2acc0455 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -187,7 +187,12 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) { } // 请求参数 - r.ParseMultipartForm(int64(msg.Confi("serve", "form_size"))) + if r.ParseMultipartForm(int64(msg.Confi("serve", "form_size"))); r.MultipartForm != nil && len(r.MultipartForm.Value) > 0 { + for k, v := range r.MultipartForm.Value { + msg.Log("info", "%s: %v", k, v) + msg.Add("option", k, v) + } + } if r.ParseForm(); len(r.PostForm) > 0 { for k, v := range r.PostForm { msg.Log("info", "%s: %v", k, v) @@ -215,6 +220,8 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) { } } + msg.Short("river") + // 用户登录 if msg.Put("option", "request", r).Put("option", "response", w).Sess("web", msg); web.Login(msg, w, r) { msg.Log("cmd", "%s [] %v", key, msg.Meta["option"]) @@ -945,8 +952,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if f, h, e := r.FormFile("upload"); m.Assert(e) { defer f.Close() - m.Log("info", "waht %v", h.Header) - name := kit.Hashx(f) if o, p, e := kit.Create(path.Join(m.Conf("web.upload", "path"), "list", name)); m.Assert(e) { defer o.Close() @@ -959,18 +964,25 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if o, p, e := kit.Create(path.Join(m.Conf("web.upload", "path"), "meta", code)); m.Assert(e) { defer o.Close() + kind := h.Header.Get("Content-Type") m.Log("upload", "file: %s %d", p, n) fmt.Fprintf(o, "create_time: %s\n", m.Time()) fmt.Fprintf(o, "create_user: %s\n", m.Option("username")) - fmt.Fprintf(o, "type: %s\n", h.Header.Get("Content-Type")) fmt.Fprintf(o, "name: %s\n", h.Filename) + fmt.Fprintf(o, "type: %s\n", kind) fmt.Fprintf(o, "hash: %s\n", name) fmt.Fprintf(o, "size: %d\n", n) m.Append("size", kit.FmtSize(n)) + m.Append("code", code) m.Append("link", fmt.Sprintf(`%s`, code, h.Filename)) - m.Append("type", h.Header.Get("Content-Type")) + m.Append("type", kind) m.Append("hash", name) + + kind = strings.Split(kind, "/")[0] + m.Cmd("nfs.copy", path.Join(m.Conf("web.upload", "path"), kind, code), p) + m.Cmd("ssh.data", "insert", kit.Select(kind, m.Option("table")), + "name", h.Filename, "kind", kind, "hash", name, "size", n) } m.Table() } @@ -982,15 +994,21 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", r := m.Optionv("request").(*http.Request) w := m.Optionv("response").(http.ResponseWriter) + kind := kit.Select("meta", kit.Select(m.Option("meta"), arg, 0)) file := strings.TrimPrefix(key, "/download/") if file == "" { - if fs, e := ioutil.ReadDir(path.Join(m.Conf("web.upload", "path"), "meta")); e == nil { + // 文件列表 + if fs, e := ioutil.ReadDir(path.Join(m.Conf("web.upload", "path"), kind)); e == nil { for _, f := range fs { - meta := kit.Linex(path.Join(m.Conf("web.upload", "path"), "meta", f.Name())) + meta := kit.Linex(path.Join(m.Conf("web.upload", "path"), kind, f.Name())) m.Push("time", meta["create_time"]) m.Push("user", meta["create_user"]) m.Push("size", kit.FmtSize(int64(kit.Int(meta["size"])))) - m.Push("name", fmt.Sprintf(`%s`, f.Name(), meta["name"])) + if kind == "image" { + m.Push("name", f.Name()) + } else { + m.Push("name", fmt.Sprintf(`%s`, f.Name(), meta["name"])) + } m.Push("hash", meta["hash"][:8]) } m.Sort("time", "time_r").Table() @@ -998,7 +1016,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", return } - if p := m.Cmdx("nfs.path", path.Join(m.Conf("web.upload", "path"), "meta", file)); p != "" { + // 直接下载 + if p := m.Cmdx("nfs.path", path.Join(m.Conf("web.upload", "path"), "list", file)); p != "" { + m.Log("info", "download %s direct", p) + http.ServeFile(w, r, p) + return + } + // 下载文件 + if p := m.Cmdx("nfs.path", path.Join(m.Conf("web.upload", "path"), kind, file)); p != "" { meta := kit.Linex(p) if p := m.Cmdx("nfs.path", path.Join(m.Conf("web.upload", "path"), "list", meta["hash"])); p != "" { m.Log("info", "download %s %s", p, m.Cmdx("nfs.hash", meta["hash"])) @@ -1014,6 +1039,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", return } + // 任意文件 if p := m.Cmdx("nfs.path", file); p != "" { m.Log("info", "download %s %s", p, m.Cmdx("nfs.hash", p)) http.ServeFile(w, r, p) diff --git a/src/plugin/love/index.css b/src/plugin/love/index.css index 5552f4b6..ff9a1b1d 100644 --- a/src/plugin/love/index.css +++ b/src/plugin/love/index.css @@ -30,3 +30,8 @@ fieldset.item.love.media table td { text-align:center; min-width:60px; } + +fieldset.item.love.pics img { + border:solid 2px red; + margin:10px; +} diff --git a/src/plugin/love/index.shy b/src/plugin/love/index.shy index 7a3a40f4..274f9bb1 100644 --- a/src/plugin/love/index.shy +++ b/src/plugin/love/index.shy @@ -60,13 +60,20 @@ fun detail "详情" "index.js" protected \ end end -kit note "回忆" "index.js" protected "ssh.data" update _ _ extra \ +kit append "扩展" "index.js" protected "ssh.data" update _ _ extra \ text "love" name table imports plugin_table \ text "1" name index imports plugin_index action auto view tiny \ text "" name field \ text "" name value \ button "添加" +kit pics "图片" "pics.js" "index.css" private "ssh.data" show \ + text "image" name table imports plugin_table \ + upfile "" name upload \ + button "上传" cb upload \ + button "记录" \ + button "展示" cb show + fun delay "以后告诉你" protected \ text "delay" name table imports plugin_table \ text "" name when init date\ diff --git a/src/plugin/love/pics.js b/src/plugin/love/pics.js new file mode 100644 index 00000000..9e47747c --- /dev/null +++ b/src/plugin/love/pics.js @@ -0,0 +1,30 @@ +{init: function(run, field, option, output) { +return { + onexport: {"": function(value, name, line) {var plugin = field.Plugin + kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: output.clientWidth, onclick: function() { + plugin.display("table") + }}}]) + }}, + show: function() {var plugin = field.Plugin + var msg = plugin.msg + var width = output.clientWidth + output.innerHTML = "", kit.List(ctx.Table(msg), function(line) { + kit.Opacity(kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: width, onclick: function(event) { + }}}]).last) + }, 1000, function() { + output.innerHTML = "", kit.List(ctx.Table(msg), function(line) { + kit.Opacity(kit.AppendChild(output, [{img: ["/download/"+line.hash], data: {width: 200, onclick: function(event) { + plugin.ontoast({width: width, height: width*3/5+40, + text: {img: ["/download/"+line.hash], data: {width: width-20, onclick: function(event) { + plugin.ontoast() + }}}, button: ["确定"], cb: function() { + plugin.ontoast() + } + }) + }}}]).last) + }, 500) + }) + + }, +}}} + diff --git a/usr/librarys/context.js b/usr/librarys/context.js index a61fc7f3..78b6c6c6 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -122,9 +122,12 @@ ctx = context = {__proto__: kit, } return ret }, - Upload: function(file, cb, detail) { + Upload: function(form, file, cb, detail) { var data = new FormData() data.append("upload", file) + for (var k in form) { + data.append(k, form[k]) + } var xhr = new XMLHttpRequest() xhr.onload = function(event) { diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 30b4c998..3459e98c 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -190,7 +190,9 @@ function Page(page) { }) if (!args.duration && args.button) {args.duration = -1} - var list = [{text: [args.title||"", "div", "title"]}, {text: [args.text||"", "div", "content"]}] + var main = typeof args.text == "string"? {text: [args.text||"", "div", "content"]}: args.text + + var list = [{text: [args.title||"", "div", "title"]}, main] args.inputs && args.inputs.forEach(function(input) { if (typeof input == "string") { list.push({inner: input, type: "label", style: {"margin-right": "5px"}}) @@ -726,6 +728,7 @@ function Plugin(page, pane, field, runs) { } var plugin = Meta(field, (field.Script && field.Script.init || function() { })(run, field, option, output)||{}, { + ontoast: page.ontoast, Inputs: {}, Appends: function() { var name = "args"+kit.Selector(option, "input.args.temp").length @@ -943,8 +946,14 @@ function Plugin(page, pane, field, runs) { }) }, show_after: function(msg) {}, + Option: function(key, value) { + if (value != undefined) { + option[key] && (option[key].value = value) + } + return option[key]? option[key].value: "" + }, upload: function(event) { - ctx.Upload(option.upload.files[0], function(event, msg) { + ctx.Upload({river: meta.river, table: plugin.Option("table")}, option.upload.files[0], function(event, msg) { kit.OrderTable(kit.AppendTable(kit.AppendChilds(output, "table"), ctx.Table(msg), msg.append)) page.ontoast("上传成功") }, function(event) { diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 804e624f..34734888 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -658,7 +658,7 @@ kit = toolkit = {__proto__: document, } return list }, - Opacity: function(obj, list, interval) { + Opacity: function(obj, interval, list) { kit.List(kit.Value(list, [0, 0.2, 0.4, 0.6, 1.0]), function(value) { obj.style.opacity = value }, kit.Value(interval, 150))