From 84460c4d4130d9fdc22ceff784160a8a6f8261d5 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sat, 12 Mar 2022 19:10:55 +0800 Subject: [PATCH] opt some --- base/mdb/mdb.go | 2 ++ core/code/binpack.go | 21 +++++++++++++++++++++ info.go | 15 +++------------ option.go | 1 + 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index da138811..628398a2 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -146,6 +146,7 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]* case LIST: _list_insert(m, arg[0], _domain_chain(m, arg[1]), arg[3:]...) } + m.ProcessRefresh3ms() }}, DELETE: {Name: "delete key sub type field value", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[2] { @@ -156,6 +157,7 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]* case LIST: _list_delete(m, arg[0], _domain_chain(m, arg[1]), arg[3], arg[4]) } + m.ProcessRefresh3ms() }}, MODIFY: {Name: "modify key sub type field value arg...", Help: "编辑", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[2] { diff --git a/core/code/binpack.go b/core/code/binpack.go index 199e5e18..421b825d 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -2,6 +2,7 @@ package code import ( "fmt" + "io" "io/ioutil" "net/http" "os" @@ -68,6 +69,25 @@ func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ BINPACK: {Name: "binpack path auto create remove export", Help: "打包", Action: map[string]*ice.Action{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + ice.Dump = func(w io.Writer, name string, cb func(string)) bool { + for _, key := range []string{name, strings.TrimPrefix(name, ice.USR_VOLCANOS)} { + if key == "/page/index.html" && kit.FileExists("src/website/index.txt") { + if s := m.Cmdx("web.chat.website", "show", "index.txt", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" { + fmt.Fprint(w, s) + return true + } + } + + if b, ok := ice.Info.Pack[key]; ok { + if cb != nil { + cb(name) + } + w.Write(b) + return true + } + } + return false + } if kit.FileExists(path.Join(ice.USR_VOLCANOS, ice.PROTO_JS)) { m.Cmd(BINPACK, mdb.REMOVE) } @@ -76,6 +96,7 @@ func init() { ice.Info.Pack["/page/index.html"] = []byte(s) } } + web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { if len(ice.Info.Pack) == 0 { return false diff --git a/info.go b/info.go index dceb0c5e..5e3f50bc 100644 --- a/info.go +++ b/info.go @@ -88,18 +88,9 @@ func AddFileKey(dir, key string) { func GetFileKey(dir string) string { return Info.File[fileKey(dir)] } -func Dump(w io.Writer, name string, cb func(string)) bool { - for _, key := range []string{name, strings.TrimPrefix(name, USR_VOLCANOS)} { - if b, ok := Info.Pack[key]; ok { - if cb != nil { - cb(name) - } - w.Write(b) - return true - } - } - return false -} + +var Dump = func(w io.Writer, name string, cb func(string)) bool { return false } + func name(name string, value interface{}) string { if s, ok := Info.names[name]; ok { last := "" diff --git a/option.go b/option.go index 5c404624..10d6b0a9 100644 --- a/option.go +++ b/option.go @@ -204,6 +204,7 @@ func (m *Message) ProcessRefresh(delay string) { } m.Process(PROCESS_REFRESH) } +func (m *Message) ProcessRefresh3ms() { m.ProcessRefresh("3ms") } func (m *Message) ProcessRefresh30ms() { m.ProcessRefresh("30ms") } func (m *Message) ProcessRefresh300ms() { m.ProcessRefresh("300ms") } func (m *Message) ProcessRefresh3s() { m.ProcessRefresh("3s") }