mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 18:22:02 +08:00
opt website
This commit is contained in:
parent
25628004a4
commit
5562c45a26
@ -151,7 +151,7 @@ func init() {
|
|||||||
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
||||||
"md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
|
"md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
|
||||||
"conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
|
"conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
|
||||||
"py", ice.TRUE,
|
"py", ice.TRUE, "txt", ice.TRUE,
|
||||||
),
|
),
|
||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
|
@ -76,7 +76,7 @@ func _share_local(m *ice.Message, arg ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 上传文件
|
// 上传文件
|
||||||
m.Cmdy(SPACE, m.Option(ice.POD), SPIDE, ice.DEV, SPIDE_RAW, m.MergeURL2(SHARE_PROXY),
|
m.Cmdy(SPACE, m.Option(ice.POD), SPIDE, ice.DEV, SPIDE_RAW, m.MergeURL2(SHARE_PROXY, nfs.PATH, ""),
|
||||||
SPIDE_PART, m.OptionSimple(ice.POD), nfs.PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p)
|
SPIDE_PART, m.OptionSimple(ice.POD), nfs.PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p)
|
||||||
|
|
||||||
if s, e := os.Stat(pp); e == nil && !s.IsDir() {
|
if s, e := os.Stat(pp); e == nil && !s.IsDir() {
|
||||||
|
@ -2,6 +2,7 @@ package chat
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
@ -45,49 +46,65 @@ func _website_parse(m *ice.Message, text string) map[string]interface{} {
|
|||||||
})
|
})
|
||||||
return river
|
return river
|
||||||
}
|
}
|
||||||
|
func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kind, text string) bool {
|
||||||
|
msg := m.Spawn(w, r)
|
||||||
|
switch kind {
|
||||||
|
case "svg":
|
||||||
|
msg.RenderResult(`<body style="background-color:cadetblue">%s</body>`, msg.Cmdx(nfs.CAT, text))
|
||||||
|
case "shy":
|
||||||
|
if r.Method == http.MethodGet {
|
||||||
|
msg.RenderCmd(msg.Prefix(DIV), text)
|
||||||
|
} else {
|
||||||
|
r.URL.Path = "/chat/cmd/web.chat.div"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
case "txt":
|
||||||
|
res := _website_parse(msg, text)
|
||||||
|
msg.RenderResult(_website_template2, kit.Format(res))
|
||||||
|
case "json":
|
||||||
|
msg.RenderResult(_website_template2, kit.Format(kit.UnMarshal(text)))
|
||||||
|
case "js":
|
||||||
|
msg.RenderResult(_website_template, text)
|
||||||
|
case "html":
|
||||||
|
msg.RenderResult(text)
|
||||||
|
default:
|
||||||
|
msg.RenderDownload(text)
|
||||||
|
}
|
||||||
|
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
const WEBSITE = "website"
|
const WEBSITE = "website"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
WEBSITE: {Name: "website", Help: "网站", Value: kit.Data(
|
WEBSITE: {Name: "website", Help: "网站", Value: kit.Data(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path,type,name,text")},
|
||||||
mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path,type,name,text",
|
|
||||||
)},
|
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
WEBSITE: {Name: "website path auto create import", Help: "网站", Action: ice.MergeAction(map[string]*ice.Action{
|
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) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmd(mdb.RENDER, mdb.CREATE, "txt", m.PrefixKey())
|
||||||
|
m.Cmd(mdb.ENGINE, mdb.CREATE, "txt", m.PrefixKey())
|
||||||
|
|
||||||
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||||
if ok := true; 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)
|
value = kit.GetMeta(value)
|
||||||
switch text := kit.Format(value[mdb.TEXT]); value[mdb.TYPE] {
|
ok = _website_render(m, w, r, kit.Format(value[mdb.TYPE]), kit.Format(value[mdb.TEXT]))
|
||||||
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[mdb.TEXT]))
|
|
||||||
msg.RenderResult(_website_template2, kit.Format(res))
|
|
||||||
case "json":
|
|
||||||
msg.RenderResult(_website_template2, kit.Format(kit.UnMarshal(text)))
|
|
||||||
case "js":
|
|
||||||
msg.RenderResult(_website_template, text)
|
|
||||||
case "html":
|
|
||||||
msg.RenderResult(text)
|
|
||||||
default:
|
|
||||||
msg.RenderDownload(text)
|
|
||||||
}
|
|
||||||
web.Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
|
||||||
}) != nil && ok {
|
}) != nil && ok {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(r.URL.Path, "/chat/website/") {
|
||||||
|
_website_render(m, w, r, kit.Ext(r.URL.Path), m.Cmdx(nfs.CAT, strings.Replace(r.URL.Path, "/chat/website/", "src/website/", 1)))
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
|
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.EchoIFrame(path.Join("/chat/website/", strings.TrimPrefix(path.Join(arg[2], arg[1]), "src/website/")))
|
||||||
|
}},
|
||||||
|
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Echo(kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/chat/website/", strings.TrimPrefix(path.Join(arg[2], arg[1]), "src/website/"))))
|
||||||
|
}},
|
||||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||||
switch m.Option(ctx.ACTION) {
|
switch m.Option(ctx.ACTION) {
|
||||||
case mdb.CREATE:
|
case mdb.CREATE:
|
||||||
@ -100,7 +117,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
mdb.CREATE: {Name: "create path type=txt,json,js,html 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) {
|
mdb.IMPORT: {Name: "import path=src/website/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
|
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
|
||||||
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) {
|
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) {
|
||||||
case "html", "js", "json", "txt":
|
case "html", "js", "json", "txt":
|
||||||
@ -116,7 +133,13 @@ func init() {
|
|||||||
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
||||||
m.PushAnchor(m.MergeURL2(value[nfs.PATH]))
|
m.PushAnchor(m.MergeURL2(value[nfs.PATH]))
|
||||||
})
|
})
|
||||||
if m.Sort(nfs.PATH); m.FieldsIsDetail() {
|
if m.Length() == 0 {
|
||||||
|
m.Push(mdb.TEXT, m.Cmdx(nfs.CAT, path.Join("src/website", path.Join(arg...))))
|
||||||
|
m.Push(nfs.PATH, path.Join("/chat/website/", path.Join(arg...)))
|
||||||
|
} else {
|
||||||
|
m.Sort(nfs.PATH)
|
||||||
|
}
|
||||||
|
if m.FieldsIsDetail() {
|
||||||
m.PushQRCode(mdb.SCAN, m.MergeURL2(m.Append(nfs.PATH)))
|
m.PushQRCode(mdb.SCAN, m.MergeURL2(m.Append(nfs.PATH)))
|
||||||
m.EchoIFrame(m.Append(nfs.PATH))
|
m.EchoIFrame(m.Append(nfs.PATH))
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
arg[1] = strings.Split(arg[1], ice.FS)[0]
|
arg[1] = strings.Split(arg[1], ice.FS)[0]
|
||||||
m.Option("exts", "inner/search.js?a=1,inner/favor.js,inner/template.js")
|
m.Option("exts", "inner/search.js?a=1,inner/favor.js,inner/template.js")
|
||||||
|
m.Option("plug", "web.chat.website,web.dream")
|
||||||
if _inner_list(m, kit.Ext(arg[1]), arg[1], arg[0]); m.IsErrNotFound() {
|
if _inner_list(m, kit.Ext(arg[1]), arg[1], arg[0]); m.IsErrNotFound() {
|
||||||
m.SetResult("")
|
m.SetResult("")
|
||||||
}
|
}
|
||||||
|
1
type.go
1
type.go
@ -132,6 +132,7 @@ func (c *Context) Merge(s *Context) *Context {
|
|||||||
for k, a := range cmd.Action {
|
for k, a := range cmd.Action {
|
||||||
// if p, ok := c.Commands[k]; ok && s != c {
|
// if p, ok := c.Commands[k]; ok && s != c {
|
||||||
if p, ok := c.Commands[k]; ok {
|
if p, ok := c.Commands[k]; ok {
|
||||||
|
key := key
|
||||||
switch last, next := p.Hand, a.Hand; k {
|
switch last, next := p.Hand, a.Hand; k {
|
||||||
case CTX_INIT:
|
case CTX_INIT:
|
||||||
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
|
p.Hand = func(m *Message, c *Context, _key string, arg ...string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user