forked from x/icebergs
opt website
This commit is contained in:
parent
6d807bd5d9
commit
a862a03c31
@ -80,7 +80,7 @@ func init() {
|
||||
m.Push("code", _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
|
||||
if len(arg) > 0 {
|
||||
m.PushQRCode("scan", kit.Format(m.Config(kit.MDB_LINK), value[kit.MDB_NAME], value[SECRET]))
|
||||
m.PushQRCode(kit.MDB_SCAN, kit.Format(m.Config(kit.MDB_LINK), value[kit.MDB_NAME], value[SECRET]))
|
||||
m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD])))
|
||||
}
|
||||
})
|
||||
|
@ -100,6 +100,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
// 环境变量
|
||||
msg.Option(ice.MSG_OUTPUT, "")
|
||||
msg.Option(ice.MSG_SESSID, "")
|
||||
msg.Option(ice.MSG_ARGS, kit.List())
|
||||
for _, v := range r.Cookies() {
|
||||
msg.Option(v.Name, v.Value)
|
||||
}
|
||||
@ -179,8 +180,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
}
|
||||
|
||||
// 输出响应
|
||||
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
|
||||
Render(msg, msg.Option(ice.MSG_OUTPUT), _args...)
|
||||
Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
||||
}
|
||||
func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -16,8 +15,8 @@ import (
|
||||
func _div_parse(m *ice.Message, text string) string {
|
||||
m.Option(nfs.CAT_CONTENT, text)
|
||||
return m.Cmdx(lex.SPLIT, "", "index", "args", func(ls []string, meta map[string]interface{}) []string {
|
||||
if ls[0] == "_span" {
|
||||
ls = append([]string{"", "", "style", kit.Select("span", ls, 1)}, kit.Slice(ls, 2)...)
|
||||
if ls[0] == "div" {
|
||||
ls = append([]string{"", "", "style", kit.Select("div", ls, 1)}, kit.Slice(ls, 2)...)
|
||||
}
|
||||
return ls
|
||||
})
|
||||
@ -41,30 +40,41 @@ func init() {
|
||||
case "js":
|
||||
m.RenderResult(_div_template, m.Cmdx(nfs.CAT, strings.ReplaceAll(p, ".js", ".css")), m.Cmdx(nfs.CAT, p))
|
||||
case "json":
|
||||
var res interface{}
|
||||
err := json.Unmarshal([]byte(m.Cmdx(nfs.CAT, p)), &res)
|
||||
m.Assert(err)
|
||||
m.RenderResult(_div_template2, kit.Format(res))
|
||||
m.RenderResult(_div_template2, kit.Format(kit.UnMarshal(m.Cmdx(nfs.CAT, p))))
|
||||
default:
|
||||
m.RenderCmd(m.PrefixKey(), p)
|
||||
}
|
||||
}},
|
||||
DIV: {Name: "div hash auto", Help: "定制", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
DIV: {Name: "div hash auto import", Help: "定制", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
lex.SPLIT: {Name: "split name=hi text", Help: "生成", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := m.Cmdx(DIV, mdb.CREATE, m.OptionSimple(kit.MDB_NAME), kit.MDB_TEXT, _div_parse(m, m.Option(kit.MDB_TEXT)))
|
||||
m.ProcessRewrite(kit.MDB_HASH, h)
|
||||
}},
|
||||
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 type=page name=hi 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 "shy":
|
||||
m.Cmd(m.PrefixKey(), lex.SPLIT, kit.MDB_NAME, p, kit.MDB_TEXT, m.Cmdx(nfs.CAT, p))
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(), ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch kit.Ext(kit.Select("", arg, 0)) {
|
||||
case "shy":
|
||||
m.Fields(0)
|
||||
m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js")
|
||||
m.Push(kit.MDB_TEXT, _div_parse(m, m.Cmdx(nfs.CAT, arg[0])))
|
||||
m.DisplayLocal("")
|
||||
default:
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
m.Option(ice.MSG_DISPLAY, "/plugin/local/chat/div.js")
|
||||
m.Action("添加", "保存", "预览")
|
||||
m.DisplayLocal("")
|
||||
} else {
|
||||
m.Action(lex.SPLIT, mdb.CREATE)
|
||||
}
|
||||
@ -100,30 +110,6 @@ var _div_template2 = `<!DOCTYPE html>
|
||||
<body>
|
||||
<script src="/proto.js"></script>
|
||||
<script src="/page/cache.js"></script>
|
||||
<script>
|
||||
Volcanos({name: "chat", panels: [
|
||||
{name: "Header", help: "标题栏", pos: chat.HEAD, state: ["time", "usernick", "avatar"]},
|
||||
{name: "River", help: "群聊组", pos: chat.LEFT, action: ["create", "refresh"]},
|
||||
{name: "Action", help: "工作台", pos: chat.MAIN},
|
||||
{name: "Search", help: "搜索框", pos: chat.AUTO},
|
||||
{name: "Footer", help: "状态条", pos: chat.FOOT, state: ["ncmd"]},
|
||||
], main: {name: "Header", list: ["/publish/order.js"]}, plugin: [
|
||||
"/plugin/state.js",
|
||||
"/plugin/input.js",
|
||||
"/plugin/table.js",
|
||||
"/plugin/input/key.js",
|
||||
"/plugin/input/date.js",
|
||||
"/plugin/story/spide.js",
|
||||
"/plugin/story/trend.js",
|
||||
"/plugin/local/code/inner.js",
|
||||
"/plugin/local/code/vimer.js",
|
||||
"/plugin/local/wiki/draw/path.js",
|
||||
"/plugin/local/wiki/draw.js",
|
||||
"/plugin/local/wiki/word.js",
|
||||
"/plugin/local/chat/div.js",
|
||||
"/plugin/local/team/plan.js",
|
||||
"/plugin/input/province.js",
|
||||
], river: JSON.parse('%s')})
|
||||
</script>
|
||||
<script>Volcanos({name: "chat", river: JSON.parse('%s')})</script>
|
||||
</body>
|
||||
`
|
||||
|
@ -2,8 +2,10 @@ package chat
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -15,6 +17,9 @@ 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 {
|
||||
if len(ls) == 1 {
|
||||
ls = append(ls, ls[0])
|
||||
}
|
||||
data := kit.Dict()
|
||||
for i := 2; i < len(ls); i += 2 {
|
||||
switch ls[i] {
|
||||
@ -31,7 +36,7 @@ func _website_parse(m *ice.Message, text string) map[string]interface{} {
|
||||
case 2:
|
||||
last = kit.Dict(kit.MDB_NAME, ls[1], kit.MDB_LIST, kit.List(), data)
|
||||
storm[ls[0]] = last
|
||||
case 3:
|
||||
default:
|
||||
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))
|
||||
}
|
||||
@ -51,39 +56,58 @@ func init() {
|
||||
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{}) {
|
||||
if ok := true; 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 "svg":
|
||||
msg.RenderResult(`<body style="background-color:cadetblue">%s</body>`, m.Cmdx(nfs.CAT, text))
|
||||
case "shy":
|
||||
if r.Method == http.MethodGet {
|
||||
msg.RenderCmd(msg.Prefix(DIV), text)
|
||||
} else {
|
||||
r.URL.Path, ok = "/chat/cmd/web.chat.div", false
|
||||
return
|
||||
}
|
||||
case "txt":
|
||||
res := _website_parse(msg, kit.Format(value[kit.MDB_TEXT]))
|
||||
// web.RenderResult(msg, kit.Format(res))
|
||||
web.RenderResult(msg, _website_template2, kit.Format(res))
|
||||
msg.RenderResult(_website_template2, kit.Format(res))
|
||||
case "json":
|
||||
web.RenderResult(msg, _website_template2, kit.Format(kit.UnMarshal(text)))
|
||||
msg.RenderResult(_website_template2, kit.Format(kit.UnMarshal(text)))
|
||||
case "js":
|
||||
web.RenderResult(msg, _website_template, text)
|
||||
msg.RenderResult(_website_template, text)
|
||||
case "html":
|
||||
msg.RenderResult(text)
|
||||
default:
|
||||
web.RenderResult(msg, text)
|
||||
msg.RenderDownload(text)
|
||||
}
|
||||
}) != nil {
|
||||
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
||||
}) != nil && ok {
|
||||
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()
|
||||
switch m.Option(ctx.ACTION) {
|
||||
case mdb.CREATE:
|
||||
m.Cmdy(mdb.INPUTS, m.PrefixKey(), "", mdb.HASH, arg)
|
||||
default:
|
||||
switch arg[0] {
|
||||
case nfs.PATH:
|
||||
m.Cmdy(nfs.DIR, arg[1:]).ProcessAgain()
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create path type=html,js,json,txt name text", Help: "创建"},
|
||||
mdb.CREATE: {Name: "create path type=txt,json,js,html 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) {
|
||||
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); 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))
|
||||
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
|
||||
kit.MDB_TYPE, kit.Ext(p), kit.MDB_NAME, name, kit.MDB_TEXT, m.Cmdx(nfs.CAT, p))
|
||||
default:
|
||||
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
|
||||
kit.MDB_TYPE, kit.Ext(p), kit.MDB_NAME, name, kit.MDB_TEXT, p)
|
||||
}
|
||||
})
|
||||
}},
|
||||
@ -92,6 +116,7 @@ func init() {
|
||||
m.PushAnchor(m.MergeURL2(value[nfs.PATH]))
|
||||
})
|
||||
if m.Sort(nfs.PATH); m.FieldsIsDetail() {
|
||||
m.PushQRCode(kit.MDB_SCAN, m.MergeURL2(m.Append(nfs.PATH)))
|
||||
m.EchoIFrame(m.Append(nfs.PATH))
|
||||
}
|
||||
}},
|
||||
|
4
misc.go
4
misc.go
@ -84,9 +84,9 @@ func (m *Message) Display(file string, arg ...interface{}) *Message {
|
||||
}
|
||||
func (m *Message) DisplayLocal(file string) *Message {
|
||||
if file == "" {
|
||||
file = path.Join(kit.PathName(2), kit.FileName(2)+".js")
|
||||
file = path.Join(kit.PathName(2), kit.Keys(kit.FileName(2), "js"))
|
||||
}
|
||||
if !strings.HasPrefix(file, "/") {
|
||||
if !strings.HasPrefix(file, PS) {
|
||||
file = path.Join("/plugin/local", file)
|
||||
}
|
||||
m.Option(MSG_DISPLAY, Display0(2, file)["display"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user