forked from x/icebergs
add island
This commit is contained in:
parent
f11eebe099
commit
83fdeae371
@ -9,49 +9,24 @@ import (
|
||||
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 {
|
||||
switch cb := args.(type) {
|
||||
case func():
|
||||
cb()
|
||||
return []string{}
|
||||
case func() string:
|
||||
return []string{cb()}
|
||||
case func() []string:
|
||||
return cb()
|
||||
case []string:
|
||||
return cb
|
||||
case string:
|
||||
return []string{cb}
|
||||
case func() string:
|
||||
return []string{cb()}
|
||||
case func() []string:
|
||||
return cb()
|
||||
case func():
|
||||
cb()
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(args)
|
||||
}
|
||||
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 {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, RUN) {
|
||||
if PodCmd(m, COMMAND, cmd) {
|
||||
@ -59,13 +34,12 @@ func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.
|
||||
} else {
|
||||
m.Cmdy(COMMAND, cmd)
|
||||
}
|
||||
m.Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey())
|
||||
m.ProcessField(ACTION, m.ActionKey(), RUN)
|
||||
m.Push(ARGS, kit.Format(_process_args(m, args)))
|
||||
kit.If(m.IsMetaKey(), func() { m.Push(STYLE, html.FLOAT) })
|
||||
} else {
|
||||
if !PodCmd(m, cmd, arg[1:]) {
|
||||
kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) })
|
||||
}
|
||||
m.ProcessField(ACTION, m.ActionKey(), RUN)
|
||||
m.Options(ice.MSG_INDEX, m.PrefixKey())
|
||||
} else if !PodCmd(m, cmd, arg[1:]) && aaa.Right(m, cmd, arg[1:]) {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
@ -220,6 +220,4 @@ func Temp(m *ice.Message, cb func(p string)) {
|
||||
cb(p)
|
||||
}
|
||||
|
||||
var ImageResize = func(m *ice.Message, p string, height, width uint) bool {
|
||||
return false
|
||||
}
|
||||
var ImageResize = func(m *ice.Message, p string, height, width uint) bool { return false }
|
||||
|
@ -58,15 +58,8 @@ func init() {
|
||||
}
|
||||
func AdminCmd(m *ice.Message, cmd string, arg ...string) string {
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,7 @@ import (
|
||||
"shylinux.com/x/toolkits/file"
|
||||
)
|
||||
|
||||
type Message interface {
|
||||
Option(key string, arg ...ice.Any) string
|
||||
PrefixKey() string
|
||||
}
|
||||
|
||||
func UserWeb(m Message) *url.URL {
|
||||
func UserWeb(m ice.IMessage) *url.URL {
|
||||
return kit.ParseURL(m.Option(ice.MSG_USERWEB))
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
func AgentIs(m Message, arg ...string) bool {
|
||||
func AgentIs(m ice.IMessage, arg ...string) bool {
|
||||
for _, k := range arg {
|
||||
if strings.HasPrefix(strings.ToLower(m.Option(ice.MSG_USERUA)), k) {
|
||||
return true
|
||||
|
@ -72,10 +72,9 @@ const SHARE = "share"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
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) {
|
||||
// kit.If(m.Option(mdb.TYPE) == LOGIN, func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(mdb.TEXT))) })
|
||||
mdb.CREATE: {Name: "create type name text space", Hand: func(m *ice.Message, arg ...string) {
|
||||
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()))))
|
||||
Count(m, "", m.Option(mdb.TYPE))
|
||||
}},
|
||||
@ -124,7 +123,7 @@ func init() {
|
||||
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] != "" {
|
||||
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))
|
||||
}
|
||||
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)))))
|
||||
}
|
||||
|
@ -396,7 +396,6 @@ func init() {
|
||||
return
|
||||
}
|
||||
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) })
|
||||
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] != "" {
|
||||
|
@ -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() })
|
||||
if port == tcp.PORT_443 {
|
||||
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
|
||||
} else if port == "" {
|
||||
return kit.Format("%s://%s", UserWeb(m).Scheme, host) + p
|
||||
} else {
|
||||
return kit.Format("http://%s:%s", host, port) + p
|
||||
}
|
||||
|
@ -16,12 +16,14 @@ func init() {
|
||||
mdb.CREATE: {Name: "create zone*=数据结构"},
|
||||
mdb.INSERT: {Name: "insert zone*=数据结构 type=go name*=hi text*=hello path file line"},
|
||||
XTERM: {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, "", msg.OptionSplit(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...)
|
||||
ctx.ProcessField(m, "", func() []string {
|
||||
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) {
|
||||
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, "", msg.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...)
|
||||
ctx.ProcessField(m, "", func() []string {
|
||||
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) {
|
||||
if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
|
||||
|
@ -185,7 +185,9 @@ func init() {
|
||||
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.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.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) {
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
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)
|
||||
if ls := kit.Simple(kit.UnMarshal(m.Option(ctx.ARGS))); len(ls) > 0 {
|
||||
return ls
|
||||
|
@ -158,7 +158,7 @@ func init() {
|
||||
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...) }},
|
||||
}, 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 web.IsLocalHost(m) {
|
||||
m.Action(mdb.CREATE, mdb.PRUNES, ice.APP)
|
||||
@ -175,7 +175,7 @@ func init() {
|
||||
}
|
||||
|
||||
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 {
|
||||
return ls
|
||||
} else {
|
||||
|
@ -44,7 +44,7 @@ func init() {
|
||||
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)))
|
||||
mdb.Config(m, aaa.USERNAME, m.Option(aaa.USERNAME))
|
||||
mdb.Config(m, aaa.EMAIL, m.Option(aaa.EMAIL))
|
||||
@ -85,12 +85,12 @@ func init() {
|
||||
if len(arg) > 0 && arg[0] == ctx.ACTION {
|
||||
m.Cmdy(REPOS, arg)
|
||||
} 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) {
|
||||
m.EchoInfoButton(nfs.Template(m, "init.html"), INIT)
|
||||
} else if len(arg) == 0 {
|
||||
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) })
|
||||
ctx.Toolkit(m)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user