1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-07-10 12:48:30 +08:00
parent 44a6325559
commit f2766ce969
19 changed files with 65 additions and 41 deletions

View File

@ -32,7 +32,6 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
m.OptionSimple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT, mdb.CACHE_CLEAR_ONEXIT),
)
if e := cmd.Start(); m.Warn(e, ice.ErrNotStart, cmd.Args, err.String()) {
m.Debug("what %v", e)
mdb.HashModify(m, h, STATUS, ERROR, ERROR, e)
return
}
@ -44,7 +43,6 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
m.Cost(CODE, "0", ctx.ARGS, cmd.Args)
} else {
mdb.HashSelectUpdate(m, h, func(value ice.Map) { value[STATUS], value[ERROR] = ERROR, e })
m.Debug("what %v", e)
}
switch status := mdb.HashSelectField(m.Sleep300ms(), h, STATUS); cb := m.OptionCB("").(type) {
case func(string) bool:

View File

@ -39,7 +39,9 @@ func EventsAction(arg ...string) ice.Actions {
list := kit.DictList(arg...)
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
for sub := range m.Target().Commands[m.CommandKey()].Actions {
kit.If(list[sub] == ice.TRUE, func() { Watch(m, sub) })
kit.If(list[sub] == ice.TRUE, func() {
Watch(m, sub)
})
}
}}}
}

View File

@ -19,7 +19,7 @@ func init() {
h := mdb.HashCreate(m, m.OptionSimple(mdb.NAME, ice.CMD), mdb.STATUS, START)
defer func() {
if e := recover(); e == nil {
mdb.HashModify(m, mdb.HASH, h, mdb.STATUS, STOP)
mdb.HashRemove(m, mdb.HASH, h)
} else {
mdb.HashModify(m, mdb.HASH, h, mdb.STATUS, ERROR, ERROR, e)
}

View File

@ -175,11 +175,11 @@ func DreamAction() ice.Actions {
func DreamProcess(m *ice.Message, args ice.Any, arg ...string) {
if kit.HasPrefixList(arg, ice.RUN) {
ctx.ProcessField(m, m.PrefixKey(), args, kit.Slice(arg, 1)...)
} else if kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
} else if kit.HasPrefixList(arg, ctx.ACTION, m.PrefixKey()) || kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
if arg = kit.Slice(arg, 2); kit.HasPrefixList(arg, DREAM) {
m.Cmdy(SPACE, m.Option(ice.MSG_USERPOD, arg[1]), m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg[2:])
} else if dream := m.Option(mdb.NAME); dream != "" {
m.Cmdy(SPACE, dream, m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg).Optionv(ice.FIELD_PREFIX, kit.Simple(ctx.ACTION, m.CommandKey(), DREAM, dream, ice.RUN))
m.Cmdy(SPACE, dream, m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg).Optionv(ice.FIELD_PREFIX, kit.Simple(ctx.ACTION, m.PrefixKey(), DREAM, dream, ice.RUN))
}
}
}

View File

@ -10,7 +10,6 @@ import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/log"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
@ -137,10 +136,10 @@ func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) {
}
func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) }
func renderVersion(m *ice.Message) string {
if m.R != nil && strings.Contains(m.R.URL.RawQuery, "debug=true") || m.Option(log.DEBUG) == ice.TRUE {
return kit.Format("?_v=%v&_t=%d", ice.Info.Make.Version, time.Now().Unix())
if ice.Info.Make.Hash == "" {
return ""
}
return ""
return kit.Format("?_v=%s&_h=%s", ice.Info.Make.Version, ice.Info.Make.Hash[:8])
}
const (

View File

@ -11,6 +11,7 @@ import (
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
@ -73,7 +74,13 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
return true
}
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
_log := func(level string, arg ...ice.Any) *ice.Message { return m.Logs(strings.Title(level), arg...) }
debug := strings.Contains(r.URL.String(), "debug=true") || strings.Contains(r.Header.Get(Referer), "debug=true")
_log := func(level string, arg ...ice.Any) *ice.Message {
if debug || arg[0] == "cmds" {
return m.Logs(strings.Title(level), arg...)
}
return m
}
if u, e := url.Parse(r.Header.Get(Referer)); e == nil {
add := func(k, v string) { _log(nfs.PATH, k, m.Option(k, v)) }
switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] {
@ -171,6 +178,7 @@ func init() {
SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
cli.NodeInfo(m, ice.Info.Pathname, WORKER)
gdb.Watch(m, SERVE_START)
aaa.White(m, nfs.REQUIRE)
}},
DOMAIN: {Hand: func(m *ice.Message, arg ...string) {
@ -184,12 +192,6 @@ func init() {
m.Go(func() {
cli.Opens(m, mdb.Config(m, cli.OPEN))
ssh.PrintQRCode(m, tcp.PublishLocalhost(m, _serve_address(m)))
return
opened := false
for i := 0; i < 3 && !opened; i++ {
m.Sleep("1s").Cmd(SPACE, func(value ice.Maps) { kit.If(value[mdb.TYPE] == CHROME, func() { opened = true }) })
}
kit.If(!opened, func() { cli.Opens(m, _serve_address(m)) })
})
}},
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port"), mdb.ClearOnExitHashAction())},
@ -198,7 +200,13 @@ func init() {
if strings.HasPrefix(sub, nfs.PS) {
kit.If(action.Hand == nil, func() { action.Hand = cmd.Hand })
sub = kit.Select(P(key, sub), PP(key, sub), strings.HasSuffix(sub, nfs.PS))
c.Commands[sub] = &ice.Command{Name: kit.Select(cmd.Name, action.Name), Actions: ice.MergeActions(cmd.Actions, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
actions := ice.Actions{}
for k, v := range cmd.Actions {
if !kit.IsIn(k, ice.CTX_INIT, ice.CTX_EXIT) {
actions[k] = v
}
}
c.Commands[sub] = &ice.Command{Name: kit.Select(cmd.Name, action.Name), Actions: ice.MergeActions(actions, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
msg := m.Spawn(c, key, cmd)
defer m.Copy(msg)
action.Hand(msg, arg...)

View File

@ -16,6 +16,8 @@ func init() {
mdb.IsSearchPreview(m, arg, func() []string { return []string{web.LINK, PORTAL, m.MergePodCmd("", "") + nfs.PS} })
}},
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { web.RenderMain(m) }},
}), Hand: func(m *ice.Message, arg ...string) {}},
}), Hand: func(m *ice.Message, arg ...string) {
web.RenderMain(m)
}},
})
}

View File

@ -57,7 +57,9 @@ func _binpack_all(m *ice.Message) {
for _, p := range []string{ice.USR_VOLCANOS, ice.USR_INTSHELL, ice.SRC} {
_binpack_dir(m, w, p)
}
for _, p := range []string{ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_LOCAL_SHY, ice.ETC_EXIT_SHY, ice.ETC_PATH, ice.README_MD, ice.MAKEFILE, ice.LICENSE} {
for _, p := range []string{ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_LOCAL_SHY, ice.ETC_EXIT_SHY, ice.ETC_PATH,
ice.README_MD, ice.MAKEFILE, ice.LICENSE, ice.GO_MOD, ice.GO_SUM,
} {
_binpack_file(m, w, p)
}
list, cache := map[string]string{}, GoCache(m)

View File

@ -86,10 +86,14 @@ func init() {
nfs.BINARY: {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, nfs.BINARY) }},
"manual": {Hand: func(m *ice.Message, arg ...string) {
host := web.UserHost(m)
args := ""
if m.Option(ice.MSG_USERPOD) != "" {
args = "?pod=" + m.Option(ice.MSG_USERPOD)
}
m.Cmdy("web.wiki.spark", "shell",
cli.LINUX, kit.Format(`curl -fSL -O %s/publish/ice.linux.amd64`, host),
cli.DARWIN, kit.Format(`curl -fSL -O %s/publish/ice.darwin.amd64`, host),
cli.WINDOWS, kit.Format(`curl -fSL -O %s/publish/ice.windows.amd64`, host),
cli.LINUX, kit.Format(`curl -fSL -O "%s/publish/ice.linux.amd64%s"`, host, args),
cli.DARWIN, kit.Format(`curl -fSL -O "%s/publish/ice.darwin.amd64%s"`, host, args),
cli.WINDOWS, kit.Format(`curl -fSL -O "%s/publish/ice.windows.amd64%s"`, host, args),
)
}},
"wget": {Hand: func(m *ice.Message, arg ...string) { _publish_contexts(m, "wget") }},

View File

@ -60,9 +60,6 @@ func _xterm_get(m *ice.Message, h string) xterm.XTerm {
}
func _xterm_echo(m *ice.Message, h string, str string) {
m.Options(ice.MSG_DAEMON, mdb.HashSelectField(m, h, cli.DAEMON))
// m.Option(ice.LOG_DISABLE, ice.TRUE)
// m.Debug("what ---%o--- ---[%v]---", []byte(str), str)
m.Debug("what ---%o---", []byte(str))
web.PushNoticeGrow(m, h, str)
}
func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) {
@ -120,8 +117,6 @@ func init() {
}},
web.INPUT: {Hand: func(m *ice.Message, arg ...string) {
if b, e := base64.StdEncoding.DecodeString(strings.Join(arg, "")); !m.Warn(e) {
// m.Debug("what ---%o--- ---[%v]---", b, string(b))
m.Debug("what ---%o---", b)
_xterm_get(m, "").Write(b)
}
}},

View File

@ -9,6 +9,7 @@ import (
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
const PORTAL = "portal"
@ -22,18 +23,23 @@ func init() {
Index.MergeCommands(ice.Commands{
PORTAL: {Name: "portal path auto", Help: "网站门户", Actions: ice.MergeActions(ice.Actions{
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
mdb.IsSearchPreview(m, arg, func() []string { return []string{web.LINK, PORTAL, m.MergePodCmd("", "") + nfs.PS} })
mdb.IsSearchPreview(m, arg, func() []string { return []string{web.LINK, PORTAL, m.MergePodCmd("", "")} })
}},
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { web.RenderCmd(m, "", arg) }},
ctx.RUN: {Hand: func(m *ice.Message, arg ...string) {
if p := path.Join(ice.USR_PORTAL, path.Join(arg...)); nfs.ExistsFile(m, p) && !(m.Option(ice.DEBUG) == ice.TRUE && aaa.Right(m.Spawn(), arg)) {
m.Copy(m.Spawn([]byte(m.Cmdx(nfs.CAT, p))))
} else {
if p := path.Join(ice.USR_PORTAL, path.Join(arg...)); (m.Option(ice.DEBUG) == ice.TRUE || !nfs.ExistsFile(m, p)) && aaa.Right(m.Spawn(), arg) {
ctx.Run(m, arg...)
m.Cmd(nfs.SAVE, p, ice.Maps{nfs.CONTENT: m.FormatMeta(), nfs.DIR_ROOT: ""})
} else {
m.Copy(m.Spawn([]byte(m.Cmdx(nfs.CAT, p))))
}
}},
}, aaa.WhiteAction(ctx.COMMAND, ctx.RUN), aaa.RoleAction(ctx.COMMAND, ctx.RUN), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() {
m.PushButton(ice.Maps{PORTAL: "官网"})
})
}},
}, aaa.WhiteAction(ctx.COMMAND, ctx.RUN), aaa.RoleAction(ctx.COMMAND, ctx.RUN), web.DreamAction(), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
if m.Push(HEADER, m.Cmdx(WORD, path.Join(nfs.SRC_DOCUMENT, INDEX_SHY))); len(arg) > 0 {
m.Push(NAV, m.Cmdx(WORD, path.Join(nfs.SRC_DOCUMENT, path.Join(arg...), INDEX_SHY)))
}

View File

@ -1,7 +1,11 @@
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { can.require(["/plugin/local/wiki/word.js"]), can.Conf(html.PADDING, 40)
can.db = {nav: {}}, can.sup.onexport.link = function() { return can.db.prefix }
can.db.prefix = location.pathname.indexOf("/chat/cmd/web.wiki.portal/") == 0? "/chat/cmd/web.wiki.portal/": "/wiki/portal/"
can.db.prefix = location.pathname.indexOf("/chat/cmd/web.wiki.portal/") == 0? "/chat/cmd/web.wiki.portal/":
location.pathname.indexOf("/chat/cmd/web.wiki.portal") == 0? "/chat/cmd/web.wiki.portal": "/wiki/portal/"
if (location.pathname.indexOf("/chat/pod/") == 0) { var args = can.misc.ParseURL(can)
can.db.prefix = can.base.trimPrefix(can.misc.MergeURL(can, args)+"/", location.origin)
}
can.db.current = can.isCmdMode()? can.base.trimPrefix(location.pathname, can.db.prefix): can.Option(nfs.PATH)
can.onmotion.clear(can)
can.ui = can.onappend.layout(can, [html.HEADER, [html.NAV, html.MAIN, html.ASIDE]], html.FLOW), can.onimport._scroll(can)
@ -59,7 +63,7 @@ Volcanos(chat.ONACTION, {
if (!internal) { var params = ""; (can.misc.Search(can, log.DEBUG) == ice.TRUE && (params = "?debug=true"))
if (link == nfs.PS) { return can.isCmdMode()? can.user.jumps(can.db.prefix+params): (can.Option(nfs.PATH, ""), can.Update()) }
if (can.base.beginWith(link, web.HTTP, nfs.PS)) { return can.user.opens(link) }
if (link.indexOf(can.db.current) < 0 || link.endsWith(nfs.PS)) { return can.isCmdMode()? can.user.jumps(can.db.prefix+link+params): (can.Option(nfs.PATH, link), can.Update()) }
if (link.indexOf(can.db.current) < 0 || link.endsWith(nfs.PS)) { return can.isCmdMode()? can.user.jumps(can.base.Path(can.db.prefix, link)+params): (can.Option(nfs.PATH, link), can.Update()) }
}
var file = can.base.trimPrefix(link, can.db.current); can.isCmdMode() && can.user.jumps("#"+file)
if (can.onmotion.cache(can, function(cache, key) { cache[key] = can._plugins, can._plugins = cache[file]||[]; return file }, can.ui.main, can.ui.aside)) { return file }

View File

@ -100,6 +100,7 @@ func init() {
if arg[0] == "shell" && len(arg) > 3 && arg[2] == "with" && arg[3] == "echo" {
m.Option("echo", m.Cmdx(cli.SYSTEM, kit.Split(arg[1])))
}
arg[1] = kit.Renders(arg[1], ice.Info)
_spark_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
}
}},

View File

@ -66,12 +66,14 @@ func init() {
TITLE: {Name: "title type=navmenu,premenu,chapter,section,endmenu text", Help: "标题", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case NAVMENU: // navmenu text arg...
arg[1] = kit.Renders(arg[1], ice.Info)
_title_menu(m, arg[0], arg[1], arg[2:]...)
case PREMENU, ENDMENU: // premenu arg...
_title_menu(m, arg[0], "", arg[1:]...)
case CHAPTER, SECTION: // chapter text arg...
_title_show(m, arg[0], arg[1], arg[2:]...)
default: // title text arg...
arg[0] = kit.Renders(arg[0], ice.Info)
_title_show(m, "", arg[0], arg[1:]...)
}
}},

View File

@ -66,7 +66,7 @@ func init() {
web.Index.Register(Index, &web.Frame{},
TITLE, BRIEF, REFER, SPARK, PARSE, FIELD,
ORDER, TABLE, CHART, IMAGE, VIDEO, AUDIO,
WORD, DATA, DRAW, FEEL,
WORD, DATA, DRAW, FEEL, PORTAL,
)
}
func Prefix(arg ...string) string { return web.Prefix(WIKI, kit.Keys(arg)) }

View File

@ -54,9 +54,6 @@ func init() {
ls := kit.Split(m.Option(mdb.TEXT))
kit.If(kit.IsIn(ls[0], IMAGE, VIDEO, AUDIO), func() { m.Cmdy(FEEL).CutTo(nfs.PATH, mdb.NAME) })
}},
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "文档")) })
}},
}, aaa.RoleAction("story.field"), ctx.CmdAction(), WikiAction("", nfs.SHY)), Hand: func(m *ice.Message, arg ...string) {
if m.Option(nfs.DIR_DEEP, ice.TRUE); len(arg) == 0 {
arg = append(arg, nfs.SRC)

View File

@ -29,7 +29,7 @@ type alpha struct {
limit string `data:"50000"`
least string `data:"1000"`
load string `name:"load file*=usr/word-dict/ecdict zone*=ecdict"`
list string `name:"list method=word,line word auto load" help:"词典"`
list string `name:"list method=word,line word auto" help:"词典"`
}
func (s alpha) Load(m *ice.Message, arg ...string) {

View File

@ -13,7 +13,7 @@ type field struct {
daemon
short string `data:"domain"`
field string `data:"time,id,index,args,style,left,top,right,bottom,selection"`
insert string `name:"insert domain=golang.google.cn index=cli.system args=pwd"`
insert string `name:"insert domain*=golang.google.cn index*=web.wiki.alpha.alpha args selection=word"`
list string `name:"list domain id auto insert" help:"插件"`
}

View File

@ -33,6 +33,10 @@ func Render(m *Message, cmd string, args ...Any) string {
break
}
kit.For(kit.Split(k), func(k string) { list = append(list, kit.Format(`<input type="button" name="%s" value="%s">`, k, k)) })
case Maps:
kit.For(k, func(k, v string) {
list = append(list, kit.Format(`<input type="button" name="%s" value="%s">`, k, kit.Select(k, v, m.Option(MSG_LANGUAGE) == "zh")))
})
case Map:
kit.For(k, func(k, v string) {
list = append(list, kit.Format(`<input type="button" name="%s" value="%s">`, k, kit.Select(k, v, m.Option(MSG_LANGUAGE) == "zh")))