From fb3b82249683dc9f6fee654aad372a2179d8163b Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 10 Jan 2024 14:41:09 +0800 Subject: [PATCH] add some --- base/nfs/dir.go | 51 ++++++++++++++++++++++++-------------------- base/web/serve.go | 4 ++-- conf.go | 50 +++++++++++++++++++------------------------ core/chat/icon.go | 2 +- core/code/vimer.go | 12 +++++------ core/code/webpack.go | 8 +++---- type.go | 3 +-- 7 files changed, 64 insertions(+), 66 deletions(-) diff --git a/base/nfs/dir.go b/base/nfs/dir.go index d8ba6333..3a6a8a07 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -103,7 +103,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di m.PushDownload(mdb.LINK, p) } case mdb.SHOW: - switch p := m.MergeLink(ice.SHARE_LOCAL+p, ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(s.Name()) { + switch p := m.MergeLink(SHARE_LOCAL+p, ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(s.Name()) { case PNG, JPG: m.PushImages(field, p) case MP4: @@ -136,26 +136,31 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di } const ( - PWD = "./" - SRC = "src/" - ETC = "etc/" - BIN = "bin/" - VAR = "var/" - USR = "usr/" - USR_PORTAL = ice.USR_PORTAL - USR_PUBLISH = ice.USR_PUBLISH - USR_ICEBERGS = ice.USR_ICEBERGS - USR_LOCAL_WORK = ice.USR_LOCAL_WORK - USR_LOCAL = ice.USR_LOCAL - SRC_DOCUMENT = ice.SRC_DOCUMENT - SRC_TEMPLATE = ice.SRC_TEMPLATE - REQUIRE_SRC = "/require/src/" - REQUIRE_USR = "/require/usr/" - REQUIRE = "/require/" - VOLCANOS = "/volcanos/" - INTSHELL = "/intshell/" - PATHNAME = "pathname" - FILENAME = "filename" + PWD = "./" + SRC = "src/" + ETC = "etc/" + BIN = "bin/" + VAR = "var/" + USR = "usr/" + + USR_PORTAL = ice.USR_PORTAL + USR_PUBLISH = ice.USR_PUBLISH + USR_ICEBERGS = ice.USR_ICEBERGS + USR_LOCAL_WORK = ice.USR_LOCAL_WORK + USR_LOCAL = ice.USR_LOCAL + SRC_DOCUMENT = ice.SRC_DOCUMENT + SRC_TEMPLATE = ice.SRC_TEMPLATE + USR_PACKAGE = "usr/package.json" + USR_MODULES = "usr/node_modules/" + SHARE_LOCAL = "/share/local/" + REQUIRE_MODULES = "/require/modules/" + REQUIRE_SRC = "/require/src/" + REQUIRE_USR = "/require/usr/" + REQUIRE = "/require/" + VOLCANOS = "/volcanos/" + INTSHELL = "/intshell/" + PATHNAME = "pathname" + FILENAME = "filename" USR_ICONS_AVATAR = "usr/icons/avatar.jpg" USR_ICONS_CONTEXTS = "usr/icons/contexts.png" @@ -230,7 +235,7 @@ func Relative(m *ice.Message, p string) string { } } func SplitPath(m *ice.Message, p string) []string { - if kit.HasPrefix(p, ice.REQUIRE_SRC, ice.REQUIRE_USR) { + if kit.HasPrefix(p, REQUIRE_SRC, REQUIRE_USR) { p = strings.TrimPrefix(p, REQUIRE) } else if kit.HasPrefix(p, REQUIRE) { ls := kit.Split(p, PS) @@ -262,7 +267,7 @@ func DirDeepAll(m *ice.Message, root, dir string, cb func(ice.Maps), arg ...stri } } func Show(m *ice.Message, file string) bool { - p := ice.SHARE_LOCAL + file + p := SHARE_LOCAL + file kit.If(m.Option(ice.MSG_USERPOD), func(pod string) { p += "?" + kit.JoinKV("=", "&", ice.POD, pod) }) diff --git a/base/web/serve.go b/base/web/serve.go index 028b9e3e..26e2a756 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -84,10 +84,10 @@ func _serve_static(msg *ice.Message, w http.ResponseWriter, r *http.Request) boo return Render(msg, ice.RENDER_DOWNLOAD, p) } else if p = path.Join(nfs.USR, r.URL.Path); kit.HasPrefix(r.URL.Path, nfs.VOLCANOS, nfs.INTSHELL) && nfs.Exists(msg, p) { return Render(msg, ice.RENDER_DOWNLOAD, p) - } else if p = strings.TrimPrefix(r.URL.Path, nfs.REQUIRE); kit.HasPrefix(r.URL.Path, ice.REQUIRE_SRC, nfs.REQUIRE+ice.USR_ICONS, nfs.REQUIRE+ice.USR_ICEBERGS) && nfs.Exists(msg, p) { + } else if p = strings.TrimPrefix(r.URL.Path, nfs.REQUIRE); kit.HasPrefix(r.URL.Path, nfs.REQUIRE_SRC, nfs.REQUIRE+ice.USR_ICONS, nfs.REQUIRE+ice.USR_ICEBERGS) && nfs.Exists(msg, p) { ispod := kit.Contains(r.URL.String(), CHAT_POD, "pod=") || kit.Contains(r.Header.Get(html.Referer), CHAT_POD, "pod=") return !ispod && Render(msg, ice.RENDER_DOWNLOAD, p) - } else if p = path.Join(ice.USR_MODULES, strings.TrimPrefix(r.URL.Path, ice.REQUIRE_MODULES)); kit.HasPrefix(r.URL.Path, ice.REQUIRE_MODULES) && nfs.Exists(msg, p) { + } else if p = path.Join(nfs.USR_MODULES, strings.TrimPrefix(r.URL.Path, nfs.REQUIRE_MODULES)); kit.HasPrefix(r.URL.Path, nfs.REQUIRE_MODULES) && nfs.Exists(msg, p) { return Render(msg, ice.RENDER_DOWNLOAD, p) } else { return false diff --git a/conf.go b/conf.go index 4ee5d6ae..18283606 100644 --- a/conf.go +++ b/conf.go @@ -24,6 +24,8 @@ const ( HTTPS = "https" HTTP = "http" + MAIL = "mail" + DEMO = "demo" HELP = "help" MAIN = "main" AUTO = "auto" @@ -34,15 +36,13 @@ const ( CORE = "core" MISC = "misc" - SHY = "shy" - DEV = "dev" - OPS = "ops" - DEMO = "demo" - MAIL = "mail" + SHY = "shy" + DEV = "dev" + OPS = "ops" - APP = "app" ICE = "ice" CAN = "can" + APP = "app" POD = "pod" CMD = "cmd" @@ -54,14 +54,14 @@ const ( ) const ( // REPOS CONTEXTS = "contexts" - LEARNING = "learning" - RELEASE = "release" - ICONS = "icons" - VOLCANOS = "volcanos" INTSHELL = "intshell" - ICEBERGS = "icebergs" + VOLCANOS = "volcanos" + LEARNING = "learning" TOOLKITS = "toolkits" + ICEBERGS = "icebergs" + RELEASE = "release" MATRIX = "matrix" + ICONS = "icons" INSTALL = "install" REQUIRE = "require" @@ -107,32 +107,26 @@ const ( // DIR FRAME_JS = "frame.js" INDEX_SH = "index.sh" - FAVICON_ICO = "/favicon.ico" PLUGIN_INPUT = "/plugin/input/" PLUGIN_LOCAL = "/plugin/local/" PLUGIN_STORY = "/plugin/story/" PLUGIN_TABLE_JS = "/plugin/table.js" - REQUIRE_MODULES = "/require/modules/" - REQUIRE_USR = "/require/usr/" - REQUIRE_SRC = "/require/src/" - SHARE_LOCAL = "/share/local/" - ISH_PLUGED = ".ish/pluged/" - USR_PACKAGE = "usr/package.json" - USR_MODULES = "usr/node_modules/" - USR_GEOAREA = "usr/geoarea/" - USR_RELEASE = "usr/release/" - USR_LEARNING = "usr/learning/" - USR_VOLCANOS = "usr/volcanos/" - USR_INTSHELL = "usr/intshell/" - USR_ICEBERGS = "usr/icebergs/" - USR_TOOLKITS = "usr/toolkits/" + ISH_PLUGED = ".ish/pluged/" + + USR_LOCAL = "usr/local/" + USR_PORTAL = "usr/portal/" USR_INSTALL = "usr/install/" USR_REQUIRE = "usr/require/" USR_PUBLISH = "usr/publish/" + USR_RELEASE = "usr/release/" + USR_ICEBERGS = "usr/icebergs/" + USR_TOOLKITS = "usr/toolkits/" + USR_VOLCANOS = "usr/volcanos/" + USR_LEARNING = "usr/learning/" + USR_INTSHELL = "usr/intshell/" USR_PROGRAM = "usr/program/" - USR_PORTAL = "usr/portal/" - USR_LOCAL = "usr/local/" + USR_GEOAREA = "usr/geoarea/" USR_ICONS = "usr/icons/" USR_LOCAL_GO = "usr/local/go/" diff --git a/core/chat/icon.go b/core/chat/icon.go index 9d6563a8..a283dcf3 100644 --- a/core/chat/icon.go +++ b/core/chat/icon.go @@ -16,7 +16,7 @@ const ICON = "icon" func init() { Index.MergeCommands(ice.Commands{ ICON: {Help: "图标", Actions: ctx.ConfAction(nfs.PATH, "bootstrap-icons/font/bootstrap-icons.css"), Hand: func(m *ice.Message, arg ...string) { - m.Cmd(lex.SPLIT, ice.USR_MODULES+mdb.Config(m, nfs.PATH), kit.Dict(lex.SPLIT_SPACE, " {:;}"), func(text string, ls []string) { + m.Cmd(lex.SPLIT, nfs.USR_MODULES+mdb.Config(m, nfs.PATH), kit.Dict(lex.SPLIT_SPACE, " {:;}"), func(text string, ls []string) { if len(ls) > 2 && ls[2] == nfs.CONTENT { name := "bi " + strings.TrimPrefix(ls[0], nfs.PT) m.Push(mdb.NAME, name).Push(mdb.ICON, kit.Format(``, name)) diff --git a/core/code/vimer.go b/core/code/vimer.go index f0a320f1..a7d83db1 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -58,14 +58,14 @@ const VIMER = "vimer" func init() { web.Index.MergeCommands(ice.Commands{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, nfs.REQUIRE) }}, - ice.REQUIRE_SRC: {Hand: func(m *ice.Message, arg ...string) { web.ShareLocalFile(m, ice.SRC, path.Join(arg...)) }}, - ice.REQUIRE_USR: {Hand: func(m *ice.Message, arg ...string) { web.ShareLocalFile(m, ice.USR, path.Join(arg...)) }}, - ice.REQUIRE_MODULES: {Hand: func(m *ice.Message, arg ...string) { - p := path.Join(ice.USR_MODULES, path.Join(arg...)) + nfs.REQUIRE_SRC: {Hand: func(m *ice.Message, arg ...string) { web.ShareLocalFile(m, ice.SRC, path.Join(arg...)) }}, + nfs.REQUIRE_USR: {Hand: func(m *ice.Message, arg ...string) { web.ShareLocalFile(m, ice.USR, path.Join(arg...)) }}, + nfs.REQUIRE_MODULES: {Hand: func(m *ice.Message, arg ...string) { + p := path.Join(nfs.USR_MODULES, path.Join(arg...)) kit.If(!nfs.Exists(m, p), func() { if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.TECH, aaa.ROOT) { - kit.If(!nfs.Exists(m, ice.USR_PACKAGE), func() { - m.Cmd(nfs.SAVE, ice.USR_PACKAGE, kit.Formats(kit.Dict(mdb.NAME, "usr", nfs.VERSION, "0.0.1"))) + kit.If(!nfs.Exists(m, nfs.USR_PACKAGE), func() { + m.Cmd(nfs.SAVE, nfs.USR_PACKAGE, kit.Formats(kit.Dict(mdb.NAME, "usr", nfs.VERSION, "0.0.1"))) }) m.Cmd(cli.SYSTEM, "npm", INSTALL, arg[0], kit.Dict(cli.CMD_DIR, ice.USR)) } diff --git a/core/code/webpack.go b/core/code/webpack.go index 59bef5cd..80bd59f7 100644 --- a/core/code/webpack.go +++ b/core/code/webpack.go @@ -19,8 +19,8 @@ import ( func _volcanos(m *ice.Message, p ...string) string { return ice.USR_VOLCANOS + path.Join(p...) } func _publish(m *ice.Message, p ...string) string { return ice.USR_PUBLISH + path.Join(p...) } func _require(m *ice.Message, p string) string { - if kit.HasPrefix(p, ice.USR_MODULES) { - return path.Join("/require/modules/", strings.TrimPrefix(p, ice.USR_MODULES)) + if kit.HasPrefix(p, nfs.USR_MODULES) { + return path.Join("/require/modules/", strings.TrimPrefix(p, nfs.USR_MODULES)) } else if kit.HasPrefix(p, ice.USR_VOLCANOS) { return path.Join("/volcanos/", strings.TrimPrefix(p, ice.USR_VOLCANOS)) } else if kit.HasPrefix(p, nfs.SRC, nfs.USR) { @@ -83,10 +83,10 @@ func _webpack_cache(m *ice.Message, dir string, write bool) { mdb.HashSelects(m).Sort(nfs.PATH).Table(func(value ice.Maps) { defer fmt.Fprintln(js, "") if p := value[nfs.PATH]; kit.Ext(p) == nfs.CSS { - _webpack_css(m, css, js, path.Join(ice.USR_MODULES, p)) + _webpack_css(m, css, js, path.Join(nfs.USR_MODULES, p)) } else { p = kit.Select(path.Join(p, LIB, kit.Keys(p, JS)), p, kit.Ext(p) == nfs.JS) - _webpack_node(m, js, path.Join(ice.USR_MODULES, p)) + _webpack_node(m, js, path.Join(nfs.USR_MODULES, p)) } }) } diff --git a/type.go b/type.go index 7a18218b..8927fc25 100644 --- a/type.go +++ b/type.go @@ -90,8 +90,7 @@ func (c *Context) ID() int32 { return atomic.AddInt32(&c.id, 1) } func (c *Context) Register(s *Context, x Server, cmd ...string) *Context { kit.For(cmd, func(cmd string) { if s, ok := Info.Index[cmd].(*Context); ok { - println(kit.Format("%s %s registed by %v", ErrWarn, cmd, s.Name)) - // panic(kit.Format("%s %s registed by %v", ErrWarn, cmd, s.Name)) + panic(kit.Format("%s %s registed by %v", ErrWarn, cmd, s.Name)) } Info.Index[cmd] = s })