From 2c13b454f93a2a64a3c0d77509cbcfbf98105ff9 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 23 Feb 2021 18:46:33 +0800 Subject: [PATCH] opt some --- base/web/render.go | 2 +- base/web/serve.go | 9 +++------ core/code/binpack.go | 11 +++++------ core/code/publish.go | 9 +++++++-- misc/git/server.go | 10 +++------- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/base/web/render.go b/base/web/render.go index 4a80fdc5..a76e72d3 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -44,7 +44,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) { case ice.RENDER_DOWNLOAD: // file [type [name]] msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(arg[0]), arg, 2))) if RenderType(msg.W, arg[0], kit.Select("", arg, 1)); !ice.DumpBinPack(msg.W, arg[0], nil) { - http.ServeFile(msg.W, msg.R, arg[0]) + http.ServeFile(msg.W, msg.R, kit.Path(arg[0])) } case ice.RENDER_QRCODE: // text [size] diff --git a/base/web/serve.go b/base/web/serve.go index bbe08eb9..67f44fbc 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -59,15 +59,12 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { if r.Method == "GET" && r.URL.Path == "/" { msg := m.Spawn() if msg.W, msg.R = w, r; strings.Contains(r.Header.Get("User-Agent"), "curl") { - if ice.DumpBinPack(w, "usr/intshell/index.sh", func(name string) { RenderType(w, name, "") }) { - return false - } - Render(msg, ice.RENDER_DOWNLOAD, kit.Path(m.Conf(SERVE, "meta.intshell.path"), m.Conf(SERVE, "meta.intshell.index"))) + Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.intshell.path"), m.Conf(SERVE, "meta.intshell.index"))) } else { if ice.DumpBinPack(w, r.URL.Path, func(name string) { RenderType(w, name, "") }) { return false } - Render(msg, ice.RENDER_DOWNLOAD, kit.Path(m.Conf(SERVE, "meta.volcanos.path"), m.Conf(SERVE, "meta.volcanos.index"))) + Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.volcanos.path"), m.Conf(SERVE, "meta.volcanos.index"))) } return false } @@ -209,7 +206,7 @@ func init() { ), "logheaders", false, "static", kit.Dict("/", "usr/volcanos/"), - "volcanos", kit.Dict("path", "usr/volcanos", "index", "index.html", + "volcanos", kit.Dict("path", "usr/volcanos", "index", "page/index.html", "repos", "https://github.com/shylinux/volcanos", "branch", "master", ), "publish", "usr/publish/", diff --git a/core/code/binpack.go b/core/code/binpack.go index 44829ac3..d16afa48 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -109,12 +109,11 @@ func init() { } }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Option(nfs.DIR_ROOT, path.Join(m.Conf(PUBLISH, kit.META_PATH))) - m.Option(nfs.DIR_TYPE, nfs.FILE) - - m.Cmdy(nfs.DIR, BINPACK).Table(func(index int, value map[string]string, head []string) { - m.PushDownload(value[kit.MDB_PATH]) - }) + for k, v := range ice.BinPack { + m.Push(kit.MDB_NAME, k) + m.Push(kit.MDB_SIZE, len(v)) + } + m.Sort(kit.MDB_NAME) }}, }, }) diff --git a/core/code/publish.go b/core/code/publish.go index f8305b0f..88552f8f 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -49,11 +49,14 @@ func init() { _publish_file(m, m.Option(kit.MDB_FILE)) }}, "can": {Name: "can", Help: "火山架", Hand: func(m *ice.Message, arg ...string) { + defer func() { m.Cmdy(PUBLISH, "contexts", "miss") }() + m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "etc/miss.sh") + m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "go.mod") + m.Option(nfs.DIR_DEEP, true) m.Option(nfs.DIR_REG, `.*\.(html|css|js)$`) m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH)) m.Cmdy(nfs.DIR, "./", "time,size,line,path,link") - m.Cmdy(PUBLISH, "contexts", "miss") }}, "ice": {Name: "ice", Help: "冰山架", Hand: func(m *ice.Message, arg ...string) { defer func() { m.Cmdy(PUBLISH, "contexts", "base") }() @@ -75,11 +78,13 @@ func init() { m.SortTimeR(kit.MDB_TIME) }}, "ish": {Name: "ish", Help: "神农架", Hand: func(m *ice.Message, arg ...string) { + defer func() { m.Cmdy(PUBLISH, "contexts", "tmux") }() + m.Cmd(PUBLISH, mdb.CREATE, kit.MDB_FILE, "etc/miss.sh") + m.Option(nfs.DIR_DEEP, true) m.Option(nfs.DIR_REG, ".*\\.(sh|vim|conf)$") m.Option(nfs.DIR_ROOT, m.Conf(PUBLISH, kit.META_PATH)) m.Cmdy(nfs.DIR, "./", "time,size,line,path,link") - m.Cmdy(PUBLISH, "contexts", "tmux") }}, "contexts": {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) { u := kit.ParseURL(m.Option(ice.MSG_USERWEB)) diff --git a/misc/git/server.go b/misc/git/server.go index 53059418..cab6d0cb 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -16,19 +16,15 @@ func init() { SERVE: {Name: SERVE, Help: "服务", Value: kit.Data( kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,name,branch,commit", "owner", "https://github.com/shylinux", + kit.MDB_PATH, ".ish/pluged", )}, }, Commands: map[string]*ice.Command{ web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Render(ice.RENDER_RESULT) + m.Render(ice.RENDER_VOID) }}, "/github.com/": {Name: "github.com", Help: "github.com", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Render(ice.RENDER_VOID) - p := kit.Path(".ish/pluged") - m.Debug("what %v", p) - git := githttp.New(p) - m.Debug("what %v", p) - git.ServeHTTP(m.W, m.R) + githttp.New(kit.Path(m.Conf(SERVE, kit.META_PATH))).ServeHTTP(m.W, m.R) }}, }, })