diff --git a/base/cli/system.go b/base/cli/system.go index 330d239d..f3f45eb2 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -3,7 +3,6 @@ package cli import ( "bytes" "io" - "os" "os/exec" "path" "strings" @@ -80,7 +79,7 @@ func _system_find(m *ice.Message, bin string, dir ...string) string { dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) } for _, p := range dir { - if _, err := os.Stat(path.Join(p, bin)); err == nil { + if kit.FileExists(path.Join(p, bin)) { return kit.Path(path.Join(p, bin)) } } diff --git a/base/nfs/cat.go b/base/nfs/cat.go index fb29f05d..140225c8 100644 --- a/base/nfs/cat.go +++ b/base/nfs/cat.go @@ -141,6 +141,8 @@ const ( SH = ice.SH CSV = ice.CSV JSON = ice.JSON + YML = "yml" + IML = "iml" TXT = "txt" SHY = "shy" SVG = "svg" @@ -162,8 +164,8 @@ func init() { SOURCE, kit.Dict( 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, - "conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE, - "py", ice.TRUE, "txt", ice.TRUE, + "conf", ice.TRUE, YML, ice.TRUE, IML, ice.TRUE, "txt", ice.TRUE, + "py", ice.TRUE, ), )}, }, Commands: map[string]*ice.Command{ diff --git a/base/nfs/save.go b/base/nfs/save.go index 60577af2..528841b2 100644 --- a/base/nfs/save.go +++ b/base/nfs/save.go @@ -11,13 +11,14 @@ import ( ) func _defs_file(m *ice.Message, name string, text ...string) { - if _, e := os.Stat(path.Join(m.Option(DIR_ROOT), name)); os.IsNotExist(e) { - for i, v := range text { - b, _ := kit.Render(v, m) - text[i] = string(b) - } - _save_file(m, name, text...) + if kit.FileExists(path.Join(m.Option(DIR_ROOT), name)) { + return } + for i, v := range text { + b, _ := kit.Render(v, m) + text[i] = string(b) + } + _save_file(m, name, text...) } func _save_file(m *ice.Message, name string, text ...string) { if f, p, e := kit.Create(path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) { @@ -105,7 +106,7 @@ func init() { }}, COPY: {Name: "copy file from...", Help: "复制", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { for _, file := range arg[1:] { - if _, e := os.Stat(file); e == nil { + if kit.FileExists(file) { _copy_file(m, arg[0], arg[1:]...) return } diff --git a/base/tcp/port.go b/base/tcp/port.go index e34b0901..8fd9065b 100644 --- a/base/tcp/port.go +++ b/base/tcp/port.go @@ -2,7 +2,6 @@ package tcp import ( "net" - "os" "path" ice "shylinux.com/x/icebergs" @@ -27,7 +26,7 @@ func _port_right(m *ice.Message, arg ...string) string { continue } p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), kit.Format(i)) - if _, e := os.Stat(p); e == nil { + if kit.FileExists(p) { continue } nfs.MkdirAll(m, p) diff --git a/base/web/share.go b/base/web/share.go index acdc5189..9b7a24fd 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -28,7 +28,7 @@ func _share_repos(m *ice.Message, repos string, arg ...string) { return } prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE))) - if _, e := os.Stat(path.Join(prefix, repos)); e != nil { // 克隆代码 + if !kit.FileExists(path.Join(prefix, repos)) { // 克隆代码 m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos)) } m.RenderDownload(path.Join(prefix, repos, path.Join(arg...))) diff --git a/core/chat/website.go b/core/chat/website.go index a8ce04d5..6c276754 100644 --- a/core/chat/website.go +++ b/core/chat/website.go @@ -26,14 +26,16 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int if text == "" { return nil, false } + m.Option(nfs.CAT_CONTENT, text) river, storm, last := kit.Dict( "Header", kit.Dict("menus", kit.List(), "style", kit.Dict("display", "none")), "River", kit.Dict("menus", kit.List(), "action", kit.List()), "Action", kit.Dict("menus", kit.List(), "action", kit.List(), "legend_event", "onclick"), - "Footer", kit.Dict("style", kit.Dict("display", "none")), - args, + "Footer", kit.Dict("style", kit.Dict("display", "none")), args, ), kit.Dict(), kit.Dict() + prefix := "" + m.Cmd(lex.SPLIT, "", mdb.KEY, mdb.NAME, func(deep int, ls []string, meta map[string]interface{}) []string { data := kit.Dict() switch display := ice.DisplayRequire(1, ls[0])[ctx.DISPLAY]; kit.Ext(ls[0]) { @@ -71,11 +73,27 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int } data[ctx.ARGS] = kit.List(ls[0]) ls[0] = key + case nfs.SHY: + data[ctx.ARGS] = kit.List(ls[0]) + data[mdb.NAME] = kit.TrimExt(ls[0], ".shy") + if data[mdb.NAME] == "main" { + data[mdb.NAME] = strings.TrimSuffix(strings.Split(ls[0], ice.PS)[1], "-story") + } + ls[0] = "web.wiki.word" + case "~": + prefix = ls[1] + ls = ls[1:] + fallthrough + case "-": + for _, v := range ls[1:] { + last[mdb.LIST] = append(last[mdb.LIST].([]interface{}), kit.Dict(mdb.INDEX, kit.Keys(prefix, v), "order", len(last))) + } + return ls } if ls[0] == "" { return ls - } else if len(ls) == 1 && deep == 3 { + } else if len(ls) == 1 && deep > 2 { ls = append(ls, m.Cmd(ctx.COMMAND, ls[0]).Append(mdb.HELP)) } else if len(ls) == 1 { ls = append(ls, ls[0]) @@ -96,16 +114,18 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int data[ls[i]] = ls[i+1] } } + switch deep { case 1: storm = kit.Dict() - river[ls[0]] = kit.Dict(mdb.NAME, ls[1], STORM, storm, data) + river[ls[0]] = kit.Dict(mdb.NAME, ls[1], STORM, storm, data, "order", len(river)) case 2: - last = kit.Dict(mdb.NAME, ls[1], mdb.LIST, kit.List(), data) + last = kit.Dict(mdb.NAME, ls[1], mdb.LIST, kit.List(), data, "order", len(storm)) storm[ls[0]] = last + prefix = "" default: last[mdb.LIST] = append(last[mdb.LIST].([]interface{}), - kit.Dict(mdb.NAME, ls[0], mdb.HELP, ls[1], mdb.INDEX, ls[0], data)) + kit.Dict(mdb.NAME, kit.Select(ls[0], data[mdb.NAME]), mdb.HELP, ls[1], mdb.INDEX, ls[0], "order", len(last), data)) } return ls }) @@ -123,7 +143,7 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin r.URL.Path = "/chat/cmd/web.chat.div" return false } - case nfs.TXT: + case nfs.IML, nfs.TXT: res, _ := _website_parse(msg, text) msg.RenderResult(_website_template2, kit.Format(res)) case nfs.JSON: @@ -151,6 +171,8 @@ func init() { }, Commands: map[string]*ice.Command{ 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) { + m.Cmd(mdb.RENDER, mdb.CREATE, nfs.IML, m.PrefixKey()) + m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.IML, m.PrefixKey()) m.Cmd(mdb.RENDER, mdb.CREATE, nfs.TXT, m.PrefixKey()) m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey()) @@ -191,11 +213,11 @@ func init() { } } }}, - mdb.CREATE: {Name: "create path type=txt,json,js,html name text", Help: "创建"}, + mdb.CREATE: {Name: "create path type=iml,json,js,html name text", Help: "创建"}, 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) { switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) { - case nfs.HTML, nfs.JS, nfs.JSON, nfs.TXT: + case nfs.HTML, nfs.JS, nfs.JSON, nfs.IML, nfs.TXT: m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name, mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, m.Cmdx(nfs.CAT, p)) default: diff --git a/core/code/binpack.go b/core/code/binpack.go index 421b825d..5ffd2de9 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -71,8 +71,8 @@ func init() { 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 != "" { + if key == "/page/index.html" && kit.FileExists("src/website/index.iml") { + if s := m.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" { fmt.Fprint(w, s) return true } @@ -91,8 +91,8 @@ func init() { if kit.FileExists(path.Join(ice.USR_VOLCANOS, ice.PROTO_JS)) { m.Cmd(BINPACK, mdb.REMOVE) } - if kit.FileExists("src/website/index.txt") { - if s := m.Cmdx("web.chat.website", "show", "index.txt", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" { + if kit.FileExists("src/website/index.iml") { + if s := m.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" { ice.Info.Pack["/page/index.html"] = []byte(s) } } diff --git a/core/code/c.go b/core/code/c.go index 7340b3dc..938d17ad 100644 --- a/core/code/c.go +++ b/core/code/c.go @@ -1,7 +1,6 @@ package code import ( - "os" "path" "strings" @@ -13,7 +12,7 @@ import ( ) func _c_tags(m *ice.Message, key string) { - if _, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), TAGS)); e != nil { + if !kit.FileExists(path.Join(m.Option(cli.CMD_DIR), TAGS)) { m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", TAGS, nfs.PWD) } _go_tags(m, key) diff --git a/core/code/publish.go b/core/code/publish.go index 8a8ebcc0..11eb80f2 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -48,7 +48,6 @@ func _publish_bin_list(m *ice.Message, dir string) { m.Push(nfs.SIZE, kit.FmtSize(s.Size())) m.Push(nfs.FILE, file) m.PushDownload(mdb.LINK, file, path.Join(p, file)) - } } } diff --git a/core/code/vimer.go b/core/code/vimer.go index f87962f0..583628a6 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -26,7 +26,7 @@ func init() { m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT))) m.Cmdy(TEMPLATE, nfs.DEFS) }}, - "website": {Name: "script file=hi.txt text=", Help: "网页", Hand: func(m *ice.Message, arg ...string) { + "website": {Name: "script file=hi.iml text=", Help: "网页", Hand: func(m *ice.Message, arg ...string) { m.Option(nfs.FILE, path.Join("website", m.Option(nfs.FILE))) m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT))) m.Cmdy(TEMPLATE, nfs.DEFS) diff --git a/core/team/task.go b/core/team/task.go index 543f6356..f0b2a6a0 100644 --- a/core/team/task.go +++ b/core/team/task.go @@ -78,12 +78,12 @@ func init() { }}, mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) { m.OptionFields(mdb.ZONE, "time,id,type,name,text,level,status,score,begin_time,close_time") - m.Cmdy(mdb.EXPORT, m.PrefixKey(), "", mdb.ZONE) + m.Cmdy(mdb.EXPORT, m.Prefix(TASK), "", mdb.ZONE) m.ProcessRefresh30ms() }}, mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) { m.OptionFields(mdb.ZONE) - m.Cmdy(mdb.IMPORT, m.PrefixKey(), "", mdb.ZONE) + m.Cmdy(mdb.IMPORT, m.Prefix(TASK), "", mdb.ZONE) m.ProcessRefresh30ms() }}, diff --git a/misc.go b/misc.go index c5b01ef2..cc81a63f 100644 --- a/misc.go +++ b/misc.go @@ -16,10 +16,7 @@ func (m *Message) Length() (max int) { max = l } } - if max > 0 { - return max - } - return len(m.Resultv()) + return max } func (m *Message) CSV(text string, head ...string) *Message { bio := bytes.NewBufferString(text) diff --git a/misc/git/server.go b/misc/git/server.go index 624d0414..aa8c5e67 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "net/http" - "os" "path" "regexp" "strconv" @@ -122,13 +121,28 @@ func init() { ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { if p := r.URL.Path; strings.HasPrefix(p, "/x/") { - r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", -1) + if ls := strings.Split(p, ice.PS); m.Cmd(web.DREAM, ls[2]).Length() > 0 { + if m.IsCliUA() { + r.URL.RawQuery += kit.Select("", "&", len(r.URL.RawQuery) > 1) + "pod=" + ls[2] + r.URL.Path = "/share/local/bin/ice.bin" + } else { + r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/chat/pod/", 1) + } + } else { + r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", 1) + } + m.Info("rewrite %v -> %v", p, r.URL.Path) } return false }) }}, }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if !m.IsCliUA() { + p := kit.Split(m.MergeURL2("/x/"+path.Join(arg...)), "?")[0] + m.RenderResult("git clone %v", p) + return + } if m.Option("go-get") == "1" { // 下载地址 p := kit.Split(m.MergeURL2("/x/"+path.Join(arg...)), "?")[0] m.RenderResult(kit.Format(``, "go-import", kit.Format(`%s git %s`, strings.TrimPrefix(p, "https://"), p))) @@ -142,11 +156,14 @@ func init() { web.RenderStatus(m, 401, err.Error()) return // 没有权限 } - if _, e := os.Stat(path.Join(repos)); os.IsNotExist(e) { + if !kit.FileExists(path.Join(repos)) { m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", repos) // 创建仓库 m.Log_CREATE(REPOS, repos) } case "upload-pack": // 下载代码 + if !kit.FileExists(path.Join(repos)) { + + } } if err := _server_repos(m, arg...); err != nil { diff --git a/misc/ssh/connect.go b/misc/ssh/connect.go index b2045298..025409d0 100644 --- a/misc/ssh/connect.go +++ b/misc/ssh/connect.go @@ -45,7 +45,7 @@ func _ssh_open(m *ice.Message, arg ...string) { } func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) { p := path.Join(kit.Env(cli.HOME), ".ssh/", fmt.Sprintf("%s@%s:%s", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT))) - if _, e := os.Stat(p); e == nil { + if kit.FileExists(p) { if c, e := net.Dial("unix", p); e == nil { cb(c) // 会话连接 return diff --git a/option.go b/option.go index 10d6b0a9..bfd354b5 100644 --- a/option.go +++ b/option.go @@ -157,7 +157,7 @@ func (m *Message) PushNotice(arg ...interface{}) { if m.Option(MSG_USERPOD) == "" { m.Cmd(SPACE, m.Option(MSG_DAEMON), arg) } else { - m.Cmd(SPIDE, DEV, m.MergeURL2("/share/toast/"), kit.Format(kit.Dict(POD, m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...)))) + m.Cmd("web.spide", OPS, m.MergeURL2("/share/toast/"), kit.Format(kit.Dict(POD, m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...)))) } } func (m *Message) PushNoticeGrow(arg ...interface{}) {