1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

add wiki cache

This commit is contained in:
shaoying 2019-12-01 18:07:33 +08:00
parent 2cdc04f9a0
commit 73649582fa
2 changed files with 31 additions and 6 deletions

View File

@ -4,7 +4,11 @@ import (
"contexts/ctx" "contexts/ctx"
"contexts/web" "contexts/web"
"fmt"
"io/ioutil"
"net/http" "net/http"
"os"
"path"
"strings" "strings"
"toolkit" "toolkit"
) )
@ -500,8 +504,27 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
case "file": case "file":
m.Cmdy("/download/" + h) m.Cmdy("/download/" + h)
case "wiki": case "wiki":
p := path.Join(path.Join("var/share", h))
if _, e := os.Stat(p); e == nil {
m.Log("info", "read cache %v", p)
r := m.Optionv("request").(*http.Request)
w := m.Optionv("response").(http.ResponseWriter)
http.ServeFile(w, r, p)
break
}
if b, e := ioutil.ReadFile("usr/template/share.tmpl"); e == nil {
m.Echo(string(b))
}
m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"]) m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"])
if f, _, e := kit.Create(p); e == nil {
defer f.Close()
for _, v := range m.Meta["result"] {
f.WriteString(v)
}
}
} }
m.Grow("share", nil, map[string]interface{}{ m.Grow("share", nil, map[string]interface{}{
"time": m.Time(), "time": m.Time(),
"share": h, "share": h,
@ -517,10 +540,13 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
return return
}}, }},
"share": &ctx.Command{Name: "share type code", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) { "share": &ctx.Command{Name: "share type code", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
if len(arg) == 0 { if len(arg) < 2 {
fields := strings.Split(m.Conf("share", "meta.fields"), " ") m.Confm("share", "hash", func(key string, value map[string]interface{}) {
m.Grows("share", nil, func(meta map[string]interface{}, index int, value map[string]interface{}) { m.Push("key", key)
m.Push(fields, value) m.Push("type", value["type"])
m.Push("code", value["code"])
m.Push("dream", value["dream"])
m.Push("link", fmt.Sprintf("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), key))
}) })
m.Table() m.Table()
return return
@ -531,7 +557,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
"time": m.Time(), "time": m.Time(),
"type": arg[0], "type": arg[0],
"code": arg[1], "code": arg[1],
"dream": kit.Select("", arg, 2), "dream": m.Option("you"),
}) })
m.Echo("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), h) m.Echo("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), h)
return return

View File

@ -1,7 +1,6 @@
kit share "共享" public "web.chat.share" \ kit share "共享" public "web.chat.share" \
select "" name type values "wiki file" \ select "" name type values "wiki file" \
text "miss.md" name story imports plugin_story view long \ text "miss.md" name story imports plugin_story view long \
text "" name dream imports plugin_you \
button "共享" button "共享"
kit note "记事本" public "_:web.wiki.note" "@you" \ kit note "记事本" public "_:web.wiki.note" "@you" \