1
0
forked from x/icebergs

add island

This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-02-02 17:29:56 +08:00
parent f11eebe099
commit 83fdeae371
13 changed files with 41 additions and 73 deletions

View File

@ -9,49 +9,24 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
const PROCESS = "process"
var _process = map[string]ice.Any{}
func AddProcess(key string, val ice.Any) { _process[key] = val }
func ProcessAction() ice.Actions {
return ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }},
PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }},
}
}
func _process_args(m *ice.Message, args ice.Any) []string { func _process_args(m *ice.Message, args ice.Any) []string {
switch cb := args.(type) { switch cb := args.(type) {
case func():
cb()
return []string{}
case func() string:
return []string{cb()}
case func() []string:
return cb()
case []string: case []string:
return cb return cb
case string: case string:
return []string{cb} return []string{cb}
case func() string:
return []string{cb()}
case func() []string:
return cb()
case func():
cb()
case nil: case nil:
default: default:
m.ErrorNotImplement(args) m.ErrorNotImplement(args)
} }
return nil return nil
} }
func Process(m *ice.Message, key string, args ice.Any, arg ...string) {
switch cb := _process[kit.Select(m.ActionKey(), key)].(type) {
case string:
if !kit.HasPrefixList(arg, ACTION, PROCESS) {
m.Cmdy(cb, PROCESS, _process_args(m, args)).Optionv(ice.FIELD_PREFIX, kit.Simple(m.ActionKey(), m.Optionv(ice.FIELD_PREFIX)))
} else {
m.Cmdy(cb, arg)
}
default:
ProcessField(m, key, args, arg...)
}
}
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message { func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, RUN) { if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, RUN) {
if PodCmd(m, COMMAND, cmd) { if PodCmd(m, COMMAND, cmd) {
@ -59,13 +34,12 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.
} else { } else {
m.Cmdy(COMMAND, cmd) m.Cmdy(COMMAND, cmd)
} }
m.Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()) m.Push(ARGS, kit.Format(_process_args(m, args)))
m.ProcessField(ACTION, m.ActionKey(), RUN)
kit.If(m.IsMetaKey(), func() { m.Push(STYLE, html.FLOAT) }) kit.If(m.IsMetaKey(), func() { m.Push(STYLE, html.FLOAT) })
} else { m.ProcessField(ACTION, m.ActionKey(), RUN)
if !PodCmd(m, cmd, arg[1:]) { m.Options(ice.MSG_INDEX, m.PrefixKey())
kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) }) } else if !PodCmd(m, cmd, arg[1:]) && aaa.Right(m, cmd, arg[1:]) {
} m.Cmdy(cmd, arg[1:])
} }
return m return m
} }

View File

@ -220,6 +220,4 @@ func Temp(m *ice.Message, cb func(p string)) {
cb(p) cb(p)
} }
var ImageResize = func(m *ice.Message, p string, height, width uint) bool { var ImageResize = func(m *ice.Message, p string, height, width uint) bool { return false }
return false
}

View File

@ -58,15 +58,8 @@ func init() {
} }
func AdminCmd(m *ice.Message, cmd string, arg ...string) string { func AdminCmd(m *ice.Message, cmd string, arg ...string) string {
if ice.Info.NodeType == WORKER { if ice.Info.NodeType == WORKER {
return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, path.Join(C(cmd), path.Join(arg...))) return m.Cmdx(SPACE, ice.OPS, cmd, arg)
} else { } else {
return m.Cmdx(cmd, arg) return m.Cmdx(cmd, arg)
} }
} }
func AdminCmdPost(m *ice.Message, cmd string, action string, arg ...string) string {
if ice.Info.NodeType == WORKER {
return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodPost, C(path.Join(cmd, ctx.ACTION, action))+"?debug=true", SPIDE_FORM, arg)
} else {
return m.Cmdx(cmd, cmd, action, arg)
}
}

View File

@ -15,12 +15,7 @@ import (
"shylinux.com/x/toolkits/file" "shylinux.com/x/toolkits/file"
) )
type Message interface { func UserWeb(m ice.IMessage) *url.URL {
Option(key string, arg ...ice.Any) string
PrefixKey() string
}
func UserWeb(m Message) *url.URL {
return kit.ParseURL(m.Option(ice.MSG_USERWEB)) return kit.ParseURL(m.Option(ice.MSG_USERWEB))
} }
func UserHost(m *ice.Message) string { func UserHost(m *ice.Message) string {
@ -32,7 +27,7 @@ func UserHost(m *ice.Message) string {
return m.Option(ice.MSG_USERHOST, u.Scheme+"://"+u.Host) return m.Option(ice.MSG_USERHOST, u.Scheme+"://"+u.Host)
} }
} }
func AgentIs(m Message, arg ...string) bool { func AgentIs(m ice.IMessage, arg ...string) bool {
for _, k := range arg { for _, k := range arg {
if strings.HasPrefix(strings.ToLower(m.Option(ice.MSG_USERUA)), k) { if strings.HasPrefix(strings.ToLower(m.Option(ice.MSG_USERUA)), k) {
return true return true

View File

@ -72,10 +72,9 @@ const SHARE = "share"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
SHARE: {Name: "share hash auto login", Help: "共享链", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{ SHARE: {Name: "share hash auto login", Help: "共享链", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create type name text space", Hand: func(m *ice.Message, arg ...string) {
// kit.If(m.Option(mdb.TYPE) == LOGIN, func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(mdb.TEXT))) })
kit.If(m.Option(mdb.TYPE) == LOGIN && m.Option(mdb.TEXT) == "", func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB))) }) kit.If(m.Option(mdb.TYPE) == LOGIN && m.Option(mdb.TEXT) == "", func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB))) })
mdb.HashCreate(m, m.OptionSimple("type,name,text"), arg, SPACE, m.Option(ice.MSG_USERPOD), aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE)) mdb.HashCreate(m, m.OptionSimple("type,name,text,space"), arg, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
m.Option(mdb.LINK, tcp.PublishLocalhost(m, m.MergeLink(P(SHARE, m.Result())))) m.Option(mdb.LINK, tcp.PublishLocalhost(m, m.MergeLink(P(SHARE, m.Result()))))
Count(m, "", m.Option(mdb.TYPE)) Count(m, "", m.Option(mdb.TYPE))
}}, }},
@ -124,7 +123,7 @@ func init() {
RenderMain(m) RenderMain(m)
} }
}}, }},
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS)), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,space,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS)), Hand: func(m *ice.Message, arg ...string) {
if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.ROOT, aaa.TECH) || len(arg) > 0 && arg[0] != "" { if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.ROOT, aaa.TECH) || len(arg) > 0 && arg[0] != "" {
mdb.HashSelect(m, arg...).PushAction(OPEN, mdb.REMOVE) mdb.HashSelect(m, arg...).PushAction(OPEN, mdb.REMOVE)
} }
@ -203,5 +202,5 @@ func ShareLocal(m *ice.Message, p string) string {
return m.MergeLink(PP(SHARE, LOCAL, p)) return m.MergeLink(PP(SHARE, LOCAL, p))
} }
func ShareField(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message { func ShareField(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message {
return m.EchoQRCode(tcp.PublishLocalhost(m, m.MergeLink("/share/"+AdminCmdPost(m, SHARE, mdb.CREATE, mdb.TYPE, FIELD, mdb.NAME, kit.Select(m.PrefixKey(), cmd), mdb.TEXT, kit.Format(kit.Simple(arg...)), ice.POD, m.Option(ice.MSG_USERPOD))))) return m.EchoQRCode(tcp.PublishLocalhost(m, m.MergeLink("/share/"+AdminCmd(m, SHARE, mdb.CREATE, mdb.TYPE, FIELD, mdb.NAME, kit.Select(m.PrefixKey(), cmd), mdb.TEXT, kit.Format(kit.Simple(arg...)), SPACE, m.Option(ice.MSG_USERPOD)))))
} }

View File

@ -396,7 +396,6 @@ func init() {
return return
} }
defer m.StatusTimeCount(kit.Dict(ice.MAIN, mdb.Config(m, ice.MAIN))) defer m.StatusTimeCount(kit.Dict(ice.MAIN, mdb.Config(m, ice.MAIN)))
// m.Option(ice.MSG_USERWEB, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB)))
kit.If(len(arg) > 0 && arg[0] != "", func() { m.OptionFields(ice.MSG_DETAIL) }) kit.If(len(arg) > 0 && arg[0] != "", func() { m.OptionFields(ice.MSG_DETAIL) })
mdb.HashSelect(m.Spawn(), arg...).Table(func(index int, value ice.Maps, field []string) { mdb.HashSelect(m.Spawn(), arg...).Table(func(index int, value ice.Maps, field []string) {
if m.Push("", value, kit.Split(mdb.Config(m, mdb.FIELD))); len(arg) > 0 && arg[0] != "" { if m.Push("", value, kit.Split(mdb.Config(m, mdb.FIELD))); len(arg) > 0 && arg[0] != "" {

View File

@ -441,8 +441,10 @@ func HostPort(m *ice.Message, host, port string, arg ...string) string {
kit.If(host == "", func() { host = kit.ParseURL(UserHost(m)).Hostname() }) kit.If(host == "", func() { host = kit.ParseURL(UserHost(m)).Hostname() })
if port == tcp.PORT_443 { if port == tcp.PORT_443 {
return kit.Format("https://%s", host) + p return kit.Format("https://%s", host) + p
} else if port == tcp.PORT_80 || port == "" { } else if port == tcp.PORT_80 {
return kit.Format("http://%s", host) + p return kit.Format("http://%s", host) + p
} else if port == "" {
return kit.Format("%s://%s", UserWeb(m).Scheme, host) + p
} else { } else {
return kit.Format("http://%s:%s", host, port) + p return kit.Format("http://%s:%s", host, port) + p
} }

View File

@ -16,12 +16,14 @@ func init() {
mdb.CREATE: {Name: "create zone*=数据结构"}, mdb.CREATE: {Name: "create zone*=数据结构"},
mdb.INSERT: {Name: "insert zone*=数据结构 type=go name*=hi text*=hello path file line"}, mdb.INSERT: {Name: "insert zone*=数据结构 type=go name*=hi text*=hello path file line"},
XTERM: {Help: "命令", Hand: func(m *ice.Message, arg ...string) { XTERM: {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)) ctx.ProcessField(m, "", func() []string {
ctx.Process(m, "", msg.OptionSplit(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...) return mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)).OptionSplit(mdb.TYPE, mdb.NAME, mdb.TEXT)
}, arg...)
}}, }},
INNER: {Help: "源码", Hand: func(m *ice.Message, arg ...string) { INNER: {Help: "源码", Hand: func(m *ice.Message, arg ...string) {
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)) ctx.ProcessField(m, "", func() []string {
ctx.Process(m, "", msg.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...) return mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)).OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE)
}, arg...)
}}, }},
}, mdb.PageZoneAction(mdb.FIELDS, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) { }, mdb.PageZoneAction(mdb.FIELDS, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) {
if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" { if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {

View File

@ -185,7 +185,9 @@ func init() {
cli.START: {Name: "start link* cmd", Hand: func(m *ice.Message, arg ...string) { _install_start(m, arg...) }}, cli.START: {Name: "start link* cmd", Hand: func(m *ice.Message, arg ...string) { _install_start(m, arg...) }},
cli.STOP: {Hand: func(m *ice.Message, arg ...string) { _install_stop(m, arg...) }}, cli.STOP: {Hand: func(m *ice.Message, arg ...string) { _install_stop(m, arg...) }},
cli.CLEAR: {Hand: func(m *ice.Message, arg ...string) { _install_clear(m, arg...) }}, cli.CLEAR: {Hand: func(m *ice.Message, arg ...string) { _install_clear(m, arg...) }},
gdb.DEBUG: {Hand: func(m *ice.Message, arg ...string) { ctx.Process(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...) }}, gdb.DEBUG: {Hand: func(m *ice.Message, arg ...string) {
ctx.ProcessField(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...)
}},
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) }}, nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) }},
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_install_path(m, kit.Select("", arg, 0))) }}, nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_install_path(m, kit.Select("", arg, 0))) }},
nfs.SOURCE: {Name: "source link* path", Hand: func(m *ice.Message, arg ...string) { nfs.SOURCE: {Name: "source link* path", Hand: func(m *ice.Message, arg ...string) {

View File

@ -14,7 +14,7 @@ import (
) )
func _makefile_xterm(m *ice.Message, arg ...string) { func _makefile_xterm(m *ice.Message, arg ...string) {
ctx.Process(m, XTERM, func() []string { ctx.ProcessField(m, XTERM, func() []string {
m.Push(ctx.STYLE, html.OUTPUT) m.Push(ctx.STYLE, html.OUTPUT)
if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 { if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 {
return ls return ls

View File

@ -158,7 +158,7 @@ func init() {
kit.If(aaa.IsTechOrRoot(m), func() { m.PushButton(kit.Dict(m.CommandKey(), "终端")) }) kit.If(aaa.IsTechOrRoot(m), func() { m.PushButton(kit.Dict(m.CommandKey(), "终端")) })
}}, }},
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, cli.Shell(m), arg...) }}, web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, cli.Shell(m), arg...) }},
}, chat.FavorAction(), ctx.ProcessAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path")), Hand: func(m *ice.Message, arg ...string) { }, chat.FavorAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path")), Hand: func(m *ice.Message, arg ...string) {
if mdb.HashSelect(m, arg...); len(arg) == 0 { if mdb.HashSelect(m, arg...); len(arg) == 0 {
if web.IsLocalHost(m) { if web.IsLocalHost(m) {
m.Action(mdb.CREATE, mdb.PRUNES, ice.APP) m.Action(mdb.CREATE, mdb.PRUNES, ice.APP)
@ -175,7 +175,7 @@ func init() {
} }
func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) { func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) {
ctx.Process(m, XTERM, func() []string { ctx.ProcessField(m, XTERM, func() []string {
if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 { if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 {
return ls return ls
} else { } else {

View File

@ -44,7 +44,7 @@ func init() {
m.Cmdy(REPOS, mdb.INPUTS, arg) m.Cmdy(REPOS, mdb.INPUTS, arg)
} }
}}, }},
CONFIGS: {Name: "configs email* username*", Help: "配置", Hand: func(m *ice.Message, arg ...string) { ctx.CONFIG: {Name: "config email* username*", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.DEFS, kit.HomePath(_GITCONFIG), kit.Format(nfs.Template(m, "gitconfig"), m.Option(aaa.USERNAME), m.Option(aaa.EMAIL))) m.Cmd(nfs.DEFS, kit.HomePath(_GITCONFIG), kit.Format(nfs.Template(m, "gitconfig"), m.Option(aaa.USERNAME), m.Option(aaa.EMAIL)))
mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME)) mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME))
mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL)) mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL))
@ -85,12 +85,12 @@ func init() {
if len(arg) > 0 && arg[0] == ctx.ACTION { if len(arg) > 0 && arg[0] == ctx.ACTION {
m.Cmdy(REPOS, arg) m.Cmdy(REPOS, arg)
} else if config, err := config.LoadConfig(config.GlobalScope); err == nil && config.User.Email == "" && mdb.Config(m, aaa.EMAIL) == "" { } else if config, err := config.LoadConfig(config.GlobalScope); err == nil && config.User.Email == "" && mdb.Config(m, aaa.EMAIL) == "" {
m.EchoInfoButton(nfs.Template(m, "email.html"), CONFIGS) m.EchoInfoButton(nfs.Template(m, "email.html"), ctx.CONFIG)
} else if !nfs.Exists(m, _GIT) { } else if !nfs.Exists(m, _GIT) {
m.EchoInfoButton(nfs.Template(m, "init.html"), INIT) m.EchoInfoButton(nfs.Template(m, "init.html"), INIT)
} else if len(arg) == 0 { } else if len(arg) == 0 {
kit.If(config != nil, func() { m.Option(aaa.EMAIL, kit.Select(mdb.Config(m, aaa.EMAIL), config.User.Email)) }) kit.If(config != nil, func() { m.Option(aaa.EMAIL, kit.Select(mdb.Config(m, aaa.EMAIL), config.User.Email)) })
m.Cmdy(REPOS, STATUS).Action(PULL, PUSH, INSTEADOF, mdb.DEV_REQUEST, CONFIGS) m.Cmdy(REPOS, STATUS).Action(PULL, PUSH, INSTEADOF, mdb.DEV_REQUEST, ctx.CONFIG)
kit.If(!m.IsCliUA(), func() { m.Cmdy(code.PUBLISH, ice.CONTEXTS, ice.DEV) }) kit.If(!m.IsCliUA(), func() { m.Cmdy(code.PUBLISH, ice.CONTEXTS, ice.DEV) })
ctx.Toolkit(m) ctx.Toolkit(m)
} else { } else {

View File

@ -203,6 +203,10 @@ func (c *Context) Close(m *Message, arg ...string) {
kit.If(c.server != nil, func() { c.server.Close(m, arg...) }) kit.If(c.server != nil, func() { c.server.Close(m, arg...) })
} }
type IMessage interface {
Option(key string, arg ...Any) string
PrefixKey() string
}
type Message struct { type Message struct {
time time.Time time time.Time
code int code int