diff --git a/base/lex/split.go b/base/lex/split.go index c7769487..8f1e5e23 100644 --- a/base/lex/split.go +++ b/base/lex/split.go @@ -25,7 +25,13 @@ func _split_list(m *ice.Message, file string, arg ...string) { const DEEP = "_deep" list := kit.List(kit.Data(DEEP, -1)) m.Cmd(nfs.CAT, file, func(text string) { - if text = kit.Split(text, "#", "#")[0]; strings.TrimSpace(text) == "" { + // if text = kit.Split(text, "#", "#")[0]; strings.TrimSpace(text) == "" { + // return + // } + if strings.HasPrefix(strings.TrimSpace(text), "# ") { + return + } + if strings.TrimSpace(text) == "" { return } @@ -36,6 +42,8 @@ func _split_list(m *ice.Message, file string, arg ...string) { switch cb := m.OptionCB(SPLIT).(type) { case func([]string, map[string]interface{}) []string: ls = cb(ls, data) + case func(int, []string, map[string]interface{}) []string: + ls = cb(deep, ls, data) } for _, k := range arg { diff --git a/base/web/render.go b/base/web/render.go index 65e7e1f0..65d9db8a 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -96,6 +96,12 @@ func RenderType(w http.ResponseWriter, name, mime string) { default: } } +func RenderResult(msg *ice.Message, arg ...interface{}) { + Render(msg, ice.RENDER_RESULT, arg...) +} +func RenderDownload(msg *ice.Message, arg ...interface{}) { + Render(msg, ice.RENDER_DOWNLOAD, arg...) +} type Buffer struct { m *ice.Message diff --git a/base/web/serve.go b/base/web/serve.go index ebf82a54..80788775 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -59,22 +59,20 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { for _, h := range rewriteList { if h(w, r) { - return true + return false } } - // 主页接口 - if r.Method == SPIDE_GET && r.URL.Path == "/" { + if r.Method == SPIDE_GET && r.URL.Path == ice.PS { msg := m.Spawn() msg.W, msg.R = w, r repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get("User-Agent"), "Mozilla/5.0")) Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Config(kit.Keys(repos, kit.MDB_PATH)), m.Config(kit.Keys(repos, kit.MDB_INDEX)))) - return false + return false // 网站主页 } - // 文件接口 if ice.Dump(w, r.URL.Path, func(name string) { RenderType(w, name, "") }) { - return false + return false // 打包文件 } return true } diff --git a/conf.go b/conf.go index 073d2be7..39123e4f 100644 --- a/conf.go +++ b/conf.go @@ -194,6 +194,7 @@ const ( // RENDER RENDER_QRCODE = "_qrcode" RENDER_IMAGES = "_images" RENDER_VIDEOS = "_videos" + RENDER_IFRAME = "_iframe" RENDER_TEMPLATE = "_template" RENDER_REDIRECT = "_redirect" RENDER_DOWNLOAD = "_download" diff --git a/core/chat/div.go b/core/chat/div.go index 5890dd49..efbaa485 100644 --- a/core/chat/div.go +++ b/core/chat/div.go @@ -88,6 +88,7 @@ var _div_template = `
+ + + + + + + +` + var _div_template2 = `
diff --git a/core/chat/header.go b/core/chat/header.go index 43d20b8f..f79b1d46 100644 --- a/core/chat/header.go +++ b/core/chat/header.go @@ -149,6 +149,7 @@ func init() { m.Option(TRANS, kit.Format(kit.Value(c.Commands[cmd].Meta, "_trans"))) m.Option(MENUS, m.Config(MENUS)) m.Echo(m.Config(TITLE)) + m.Cmdy(WEBSITE) }}, HEADER: {Name: "header", Help: "标题栏", Action: map[string]*ice.Action{ GRANT: {Name: "grant space", Help: "授权", Hand: func(m *ice.Message, arg ...string) { diff --git a/core/chat/river.go b/core/chat/river.go index 3246b253..53253a4a 100644 --- a/core/chat/river.go +++ b/core/chat/river.go @@ -54,6 +54,7 @@ const RIVER = "river" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ RIVER: {Name: RIVER, Help: "群组", Value: kit.Data( + kit.MDB_FIELD, "time,hash,type,name,text,template", MENUS, kit.List(RIVER, kit.List("create", "创建群组", "添加应用", "添加工具", "添加设备", "创建空间"), kit.List("share", "共享群组", "共享应用", "共享工具", "共享主机", "访问空间")), )}, }, Commands: map[string]*ice.Command{ diff --git a/core/chat/website.go b/core/chat/website.go new file mode 100644 index 00000000..b16a1159 --- /dev/null +++ b/core/chat/website.go @@ -0,0 +1,128 @@ +package chat + +import ( + "net/http" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/lex" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" + kit "shylinux.com/x/toolkits" +) + +func _website_parse(m *ice.Message, text string) map[string]interface{} { + m.Option(nfs.CAT_CONTENT, text) + river, storm, last := kit.Dict(), kit.Dict(), kit.Dict() + m.Cmd(lex.SPLIT, "", kit.MDB_KEY, kit.MDB_NAME, func(deep int, ls []string, meta map[string]interface{}) []string { + data := kit.Dict() + for i := 2; i < len(ls); i += 2 { + switch ls[i] { + case kit.MDB_ARGS: + data[ls[i]] = kit.UnMarshal(ls[i+1]) + default: + data[ls[i]] = ls[i+1] + } + } + switch deep { + case 0: + storm = kit.Dict() + river[ls[0]] = kit.Dict(kit.MDB_NAME, ls[1], "storm", storm, data) + case 4: + last = kit.Dict(kit.MDB_NAME, ls[1], kit.MDB_LIST, kit.List(), data) + storm[ls[0]] = last + case 8: + last[kit.MDB_LIST] = append(last[kit.MDB_LIST].([]interface{}), + kit.Dict(kit.MDB_NAME, ls[0], kit.MDB_HELP, ls[1], kit.MDB_INDEX, ls[0], data)) + } + return ls + }) + return river +} + +const WEBSITE = "website" + +func init() { + Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ + WEBSITE: {Name: "website", Help: "网站", Value: kit.Data( + kit.MDB_SHORT, nfs.PATH, kit.MDB_FIELD, "time,path,type,name,text", + )}, + }, Commands: map[string]*ice.Command{ + WEBSITE: {Name: "website path auto create import", Help: "网站", Action: ice.MergeAction(map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { + if m.Richs(WEBSITE, nil, r.URL.Path, func(key string, value map[string]interface{}) { + msg, value := m.Spawn(w, r), kit.GetMeta(value) + switch text := kit.Format(value[kit.MDB_TEXT]); value[kit.MDB_TYPE] { + case "txt": + res := _website_parse(msg, kit.Format(value[kit.MDB_TEXT])) + web.RenderResult(msg, _website_template2, kit.Format(res)) + case "json": + web.RenderResult(msg, _website_template2, kit.Format(kit.UnMarshal(text))) + case "js": + web.RenderResult(msg, _website_template, text) + default: + web.RenderResult(msg, text) + } + }) != nil { + return true + } + return false + }) + }}, + mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { + switch arg[0] { + case nfs.PATH: + m.Cmdy(nfs.DIR, arg[1:]).ProcessAgain() + } + }}, + mdb.CREATE: {Name: "create path type=html,js,json name text", Help: "创建"}, + mdb.IMPORT: {Name: "import path=src/", Help: "导入", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) { + switch kit.Ext(p) { + case "html", "js", "json", "txt": + m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+p, + kit.MDB_TYPE, kit.Ext(p), kit.MDB_NAME, p, kit.MDB_TEXT, m.Cmdx(nfs.CAT, p)) + } + }) + }}, + }, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) { + m.PushAnchor(m.MergeURL2(value[nfs.PATH])) + }) + if m.Sort(nfs.PATH); m.FieldsIsDetail() { + m.EchoIFrame(m.Append(nfs.PATH)) + } + }}, + }}) +} + +var _website_template = ` +
+ +
+ + + + +
+` + +var _website_template2 = ` +
+ +
+ + + + +
+` diff --git a/core/code/js.go b/core/code/js.go index 9c6715b6..6de65d9b 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -11,6 +11,7 @@ import ( const JS = "js" const CSS = "css" const HTML = "html" +const JSON = "json" const NODE = "node" const VUE = "vue" @@ -18,6 +19,7 @@ func init() { Index.Register(&ice.Context{Name: JS, Help: "前端", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { + m.Cmd(cmd, mdb.CREATE, JSON, m.Prefix(JS)) m.Cmd(cmd, mdb.CREATE, VUE, m.Prefix(JS)) m.Cmd(cmd, mdb.CREATE, JS, m.Prefix(JS)) } diff --git a/go.sum b/go.sum index e69de29b..77c333e6 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,6 @@ +shylinux.com/x/go-qrcode v0.0.1 h1:/eOGqMj1qtgs9Ymd12zTUa1gcJZs9S92kj2lb0QzKsE= +shylinux.com/x/go-qrcode v0.0.1/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po= +shylinux.com/x/toolkits v0.4.2 h1:6VvlNFmNhHNw/MfK6SlT8BRzk6CWf/oXm/+Nw2Wt850= +shylinux.com/x/toolkits v0.4.2/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA= +shylinux.com/x/websocket v0.0.1 h1:OBc21DxqsGlQ2+Pz76xqLyDNo1LV+PUUqfWi+1PZPDE= +shylinux.com/x/websocket v0.0.1/go.mod h1:AaSpMToOxbMULKQytzczeHPuqb708vK1vrAzCxLo/XE= diff --git a/render.go b/render.go index c7818ae5..b2a4a726 100644 --- a/render.go +++ b/render.go @@ -37,6 +37,8 @@ func Render(m *Message, cmd string, args ...interface{}) string { case RENDER_VIDEOS: // src [size] return kit.Format(`