forked from x/icebergs
add some
This commit is contained in:
parent
38824867b5
commit
34210fb807
@ -120,7 +120,7 @@ func init() {
|
||||
}},
|
||||
STOP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
h, pid := m.Option(mdb.HASH), m.Option(PID)
|
||||
mdb.HashSelects(m, h).Table(func(value ice.Maps) {
|
||||
mdb.HashSelects(m.Spawn(), h).Table(func(value ice.Maps) {
|
||||
if h == "" && value[PID] != pid {
|
||||
return
|
||||
}
|
||||
@ -130,7 +130,7 @@ func init() {
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
h, pid := m.Option(mdb.HASH), m.Option(PID)
|
||||
mdb.HashSelects(m, h).Table(func(value ice.Maps) {
|
||||
mdb.HashSelects(m.Spawn(), h).Table(func(value ice.Maps) {
|
||||
if h == "" && value[PID] != pid {
|
||||
return
|
||||
}
|
||||
|
@ -207,3 +207,12 @@ func ShortCmd(key string) string {
|
||||
}
|
||||
return key
|
||||
}
|
||||
func ResourceFile(m *ice.Message, file string, arg ...string) string {
|
||||
if kit.HasPrefix(file, nfs.PS, ice.HTTP) {
|
||||
return file
|
||||
} else if nfs.Exists(m, file) {
|
||||
return file
|
||||
} else {
|
||||
return path.Join(path.Dir(GetCmdFile(m, m.PrefixKey())), file)
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func _spide_create(m *ice.Message, link, types, name, icons, token string) {
|
||||
}
|
||||
func _spide_show(m *ice.Message, name string, arg ...string) {
|
||||
file := ""
|
||||
action, arg := _spide_args(m, arg, SPIDE_RAW, SPIDE_MSG, SPIDE_SAVE, SPIDE_CACHE)
|
||||
action, arg := _spide_args(m, arg, SPIDE_RAW, SPIDE_DETAIL, SPIDE_MSG, SPIDE_SAVE, SPIDE_CACHE)
|
||||
kit.If(action == SPIDE_SAVE, func() { file, arg = arg[0], arg[1:] })
|
||||
msg := mdb.HashSelects(m.Spawn(), name)
|
||||
method, arg := _spide_args(m, arg, http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
|
||||
@ -67,7 +67,7 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
defer res.Body.Close()
|
||||
m.Cost(cli.STATUS, res.Status, nfs.SIZE, kit.FmtSize(kit.Int64(res.Header.Get(html.ContentLength))), mdb.TYPE, res.Header.Get(html.ContentType))
|
||||
if action != SPIDE_RAW {
|
||||
if action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, STATUS).Push(mdb.NAME, res.StatusCode).Push(mdb.VALUE, res.Status)
|
||||
}
|
||||
m.Options(STATUS, res.Status)
|
||||
@ -75,7 +75,7 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
m.Logs(RESPONSE, k, v)
|
||||
}
|
||||
if m.Options(k, v); action != SPIDE_RAW {
|
||||
if m.Options(k, v); action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, SPIDE_HEADER).Push(mdb.NAME, k).Push(mdb.VALUE, v[0])
|
||||
}
|
||||
})
|
||||
@ -85,7 +85,7 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
m.Logs(RESPONSE, v.Name, v.Value)
|
||||
}
|
||||
if action != SPIDE_RAW {
|
||||
if action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, COOKIE).Push(mdb.NAME, v.Name).Push(mdb.VALUE, v.Value)
|
||||
}
|
||||
})
|
||||
@ -187,13 +187,9 @@ func _spide_send(m *ice.Message, name string, req *http.Request, timeout string)
|
||||
return client.Do(req)
|
||||
}
|
||||
func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
|
||||
if action == SPIDE_RAW {
|
||||
m.SetResult()
|
||||
} else {
|
||||
m.SetResult().SetAppend()
|
||||
}
|
||||
m.SetResult()
|
||||
switch action {
|
||||
case SPIDE_RAW:
|
||||
case SPIDE_RAW, SPIDE_DETAIL:
|
||||
b, _ := ioutil.ReadAll(res.Body)
|
||||
m.Echo(string(b))
|
||||
case SPIDE_MSG:
|
||||
@ -219,10 +215,11 @@ func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
|
||||
}
|
||||
|
||||
const (
|
||||
SPIDE_RAW = "raw"
|
||||
SPIDE_MSG = "msg"
|
||||
SPIDE_SAVE = "save"
|
||||
SPIDE_CACHE = "cache"
|
||||
SPIDE_RAW = "raw"
|
||||
SPIDE_DETAIL = "detail"
|
||||
SPIDE_MSG = "msg"
|
||||
SPIDE_SAVE = "save"
|
||||
SPIDE_CACHE = "cache"
|
||||
|
||||
SPIDE_BODY = "body"
|
||||
SPIDE_FORM = "form"
|
||||
|
@ -138,7 +138,7 @@ func _install_trash(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _install_service(m *ice.Message, arg ...string) {
|
||||
name := kit.Split(path.Base(arg[0]), "_-.")[0]
|
||||
m.Fields(len(kit.Slice(arg, 1)), "time,port,status,pid,cmd,dir")
|
||||
m.Fields(len(kit.Slice(arg, 1)), "time,status,port,pid,cmd,dir")
|
||||
m.Cmd(mdb.SELECT, cli.DAEMON, "", mdb.HASH, func(value ice.Maps) {
|
||||
if strings.Contains(value[ice.CMD], path.Join(ice.BIN, name)) {
|
||||
switch m.Push("", value, kit.Split(m.OptionFields())); value[mdb.STATUS] {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -18,22 +19,35 @@ const PACKAGE = "package"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACKAGE: {Name: "package index auto", Help: "软件包", Actions: ice.MergeActions(ice.Actions{
|
||||
cli.START: {Name: "start port*=10000", Hand: func(m *ice.Message, arg ...string) {
|
||||
if cli.IsSuccess(m.Cmdy(m.Option(ctx.INDEX), m.ActionKey(), arg)) {
|
||||
web.OpsCmd(m, tcp.PORT, mdb.CREATE, m.OptionSimple(tcp.PORT, mdb.NAME, mdb.TEXT, mdb.ICON, ctx.INDEX), web.SPACE, m.Option(ice.MSG_USERPOD), m.AppendSimple(cli.CMD, cli.PID))
|
||||
}
|
||||
web.DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(m.Option(ctx.INDEX), m.ActionKey(), arg)
|
||||
m.Cmdy(nfs.DIR, path.Join(ice.USR_INSTALL, path.Base(m.Option(web.LINK))))
|
||||
mdb.HashModify(m, m.AppendSimple(mdb.TIME), mdb.TEXT, m.Append(nfs.PATH))
|
||||
}},
|
||||
cli.BUILD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(m.Option(ctx.INDEX), m.ActionKey(), arg)
|
||||
m.Cmdy(nfs.DIR, path.Join(_install_path(m, m.Option(web.LINK)), "_install/bin/nginx"))
|
||||
mdb.HashModify(m, mdb.TIME, m.Append(mdb.TIME), cli.CMD, m.Append(nfs.PATH))
|
||||
mdb.HashModify(m, m.AppendSimple(mdb.TIME), cli.CMD, m.Append(nfs.PATH))
|
||||
}},
|
||||
cli.START: {Name: "start port*=10000", Hand: func(m *ice.Message, arg ...string) {
|
||||
if cli.IsSuccess(m.Cmdy(m.Option(ctx.INDEX), m.ActionKey(), arg)) {
|
||||
web.OpsCmd(m, tcp.PORT, mdb.CREATE, m.OptionSimple(tcp.PORT, mdb.NAME, mdb.TEXT, mdb.ICON, ctx.INDEX), web.SPACE, m.Option(ice.MSG_USERPOD),
|
||||
m.AppendSimple(cli.CMD, cli.PID))
|
||||
mdb.HashModify(m, m.AppendSimple(cli.PID), m.OptionSimple(tcp.PORT))
|
||||
}
|
||||
}},
|
||||
cli.STOP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if cli.IsSuccess(m.Cmdy(m.Option(ctx.INDEX), m.ActionKey(), arg)) {
|
||||
web.OpsCmd(m, tcp.PORT, mdb.MODIFY, m.OptionSimple(tcp.PORT), cli.PID, "")
|
||||
mdb.HashModify(m, cli.PID, "", tcp.PORT, "")
|
||||
}
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Trash(m, path.Join(ice.USR_INSTALL, path.Base(m.Option(web.LINK))))
|
||||
nfs.Trash(m, _install_path(m, m.Option(web.LINK)))
|
||||
mdb.HashModify(m, cli.CMD, "")
|
||||
mdb.HashModify(m, mdb.TEXT, "", cli.CMD, "")
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, "index", mdb.FIELD, "time,index,type,name,text,icon,cmd,link")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, "index", mdb.FIELD, "time,index,type,name,text,icon,cmd,pid,port,link")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.HasPrefixList(arg, ctx.ACTION) {
|
||||
m.Cmdy(m.Option(ctx.INDEX), arg)
|
||||
return
|
||||
@ -48,7 +62,11 @@ func init() {
|
||||
button = append(button, nfs.TRASH)
|
||||
})
|
||||
case nfs.SOURCE:
|
||||
button = append(button, cli.START, cli.BUILD)
|
||||
if value[cli.PID] == "" {
|
||||
button = append(button, cli.START, cli.BUILD)
|
||||
} else {
|
||||
button = append(button, cli.STOP, cli.BUILD)
|
||||
}
|
||||
kit.If(!nfs.Exists(m, _install_path(m, value[mdb.LINK])), func() {
|
||||
button = append(button, web.DOWNLOAD)
|
||||
}, func() {
|
||||
@ -58,7 +76,8 @@ func init() {
|
||||
m.PushButton(button...)
|
||||
})
|
||||
web.PushPodCmd(m, "", arg...)
|
||||
kit.If(m.Option(ice.MSG_USERPOD) == "", func() { m.RenameAppend(web.SPACE, ice.POD) })
|
||||
kit.If(!m.IsWorker(), func() { m.RenameAppend(web.SPACE, ice.POD) })
|
||||
m.Action(html.FILTER)
|
||||
}},
|
||||
})
|
||||
}
|
||||
@ -67,7 +86,7 @@ func PackageCreate(m *ice.Message, kind, name, text, icon, link string) {
|
||||
return
|
||||
}
|
||||
m.Cmd(PACKAGE, mdb.CREATE, ctx.INDEX, m.PrefixKey(),
|
||||
mdb.TYPE, kind, mdb.NAME, name, mdb.TEXT, kit.Select(path.Base(link), text),
|
||||
mdb.ICON, icon, web.LINK, link,
|
||||
mdb.TYPE, kind, mdb.NAME, name, mdb.TEXT, "",
|
||||
mdb.ICON, ctx.ResourceFile(m, kit.Select(name+".png", icon)), web.LINK, link,
|
||||
)
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ func (s node) List(m *ice.Message, arg ...string) {
|
||||
s.Code.Source(m, "", arg...)
|
||||
}
|
||||
func (s node) Xterm(m *ice.Message, arg ...string) {
|
||||
s.Code.Xterm(m, []string{mdb.TYPE, NODE}, arg...)
|
||||
s.Code.Xterm(m, "", []string{mdb.TYPE, NODE}, arg...)
|
||||
}
|
||||
func init() { ice.CodeCtxCmd(node{}) }
|
||||
|
@ -120,6 +120,9 @@ func (m *Message) RenderVoid(arg ...Any) *Message {
|
||||
func (m *Message) IsDebug() bool {
|
||||
return m.Option(MSG_DEBUG) == TRUE
|
||||
}
|
||||
func (m *Message) IsWorker() bool {
|
||||
return Info.NodeType == "worker"
|
||||
}
|
||||
func (m *Message) IsCliUA() bool {
|
||||
return m.Option(MSG_USERUA) == "" || !strings.HasPrefix(m.Option(MSG_USERUA), html.Mozilla)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user