mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
add some
This commit is contained in:
parent
3534665b88
commit
02b707e79f
@ -2,6 +2,7 @@ package aaa
|
||||
|
||||
import (
|
||||
"net/smtp"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -10,6 +11,7 @@ import (
|
||||
|
||||
const (
|
||||
SEND = "send"
|
||||
DATE = "date"
|
||||
FROM = "from"
|
||||
TO = "to"
|
||||
CC = "cc"
|
||||
@ -41,7 +43,7 @@ func init() {
|
||||
if m.Warn(msg.Append(SERVICE) == "", ice.ErrNotValid, SERVICE) {
|
||||
return
|
||||
}
|
||||
content := []byte(kit.JoinKV(DF, NL, kit.Simple(FROM, msg.Append(USERNAME), m.OptionSimple(TO, CC, SUBJECT), "Content-Type", "text/html; charset=UTF-8")...) + NL + NL + m.Option(CONTENT))
|
||||
content := []byte(kit.JoinKV(DF, NL, kit.Simple(FROM, msg.Append(USERNAME), m.OptionSimple(TO, CC, SUBJECT), DATE, time.Now().Format(time.RFC1123Z), "Content-Type", "text/html; charset=UTF-8")...) + NL + NL + m.Option(CONTENT))
|
||||
auth := smtp.PlainAuth("", msg.Append(USERNAME), msg.Append(PASSWORD), kit.Split(msg.Append(SERVICE), ice.DF)[0])
|
||||
m.Logs(EMAIL, SEND, string(content)).Warn(smtp.SendMail(msg.Append(SERVICE), auth, msg.Append(USERNAME), kit.Split(m.Option(TO)), content))
|
||||
}},
|
||||
|
@ -112,13 +112,11 @@ func CmdInputs(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func PodCmd(m *ice.Message, arg ...ice.Any) bool {
|
||||
Upload(m)
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
m.Options(ice.POD, []string{}, ice.MSG_USERPOD, pod).Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
|
||||
return true
|
||||
}
|
||||
if pod := m.Option(ice.SPACE); pod != "" {
|
||||
m.Options(ice.SPACE, []string{}, ice.MSG_USERPOD, pod).Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
|
||||
return true
|
||||
for _, key := range []string{ice.SPACE, ice.POD} {
|
||||
if pod := m.Option(key); pod != "" {
|
||||
m.Options(key, []string{}, ice.MSG_USERPOD, pod).Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -46,13 +46,25 @@ func Process(m *ice.Message, key string, args ice.Any, arg ...string) {
|
||||
ProcessField(m, key, args, arg...)
|
||||
}
|
||||
}
|
||||
func GetPod(m *ice.Message) string {
|
||||
for _, key := range []string{ice.SPACE, ice.POD} {
|
||||
if pod := m.Option(key); pod != "" {
|
||||
m.Options(key, []string{}, ice.MSG_USERPOD, pod)
|
||||
return pod
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, ice.RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()).ProcessField(ACTION, m.ActionKey(), ice.RUN)
|
||||
} else {
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
m.Options(ice.POD, []string{}, ice.MSG_USERPOD, pod).Cmdy("web.space", pod, cmd, arg[1:])
|
||||
if PodCmd(m, COMMAND, cmd) {
|
||||
m.Push(ice.SPACE, m.Option(ice.MSG_USERPOD))
|
||||
} else {
|
||||
m.Cmdy(COMMAND, cmd)
|
||||
}
|
||||
m.Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()).ProcessField(ACTION, m.ActionKey(), ice.RUN)
|
||||
} else {
|
||||
if !PodCmd(m, cmd, arg[1:]) {
|
||||
kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) })
|
||||
}
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func init() {
|
||||
}}, mdb.UPLOAD: {},
|
||||
"finder": {Help: "本机", Hand: func(m *ice.Message, arg ...string) { m.Cmd("cli.system", "opens", "Finder.app") }},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
mdb.SHOW: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.SHOW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) {
|
||||
Show(m.ProcessInner(), path.Join(m.Option(DIR_ROOT), m.Option(PATH)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -193,7 +193,7 @@ func init() {
|
||||
m.Logs(FIND, DIR_ROOT, root, PATH, dir, DIR_TYPE, m.Option(DIR_TYPE))
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
size, last := _dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields)
|
||||
m.Status(mdb.TIME, last, mdb.COUNT, kit.Split(m.FormatSize())[0], SIZE, kit.FmtSize(size), kit.MDB_COST, m.FormatCost())
|
||||
m.Status(mdb.TIME, last, mdb.COUNT, kit.Split(m.FormatSize())[0], SIZE, kit.FmtSize(size), DIR_ROOT, m.Option(DIR_ROOT), kit.MDB_COST, m.FormatCost())
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func PushNotice(m *ice.Message, arg ...ice.Any) {
|
||||
func PushNoticeToast(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("toast", arg)...) }
|
||||
func PushNoticeGrow(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("grow", arg)...) }
|
||||
func PushStream(m *ice.Message) {
|
||||
m.Options(cli.CMD_OUTPUT, file.NewWriteCloser(func(buf []byte) { PushNoticeGrow(m, string(buf)) }, func() { PushNoticeToast(m, "done") })).ProcessHold()
|
||||
m.Options(cli.CMD_OUTPUT, file.NewWriteCloser(func(buf []byte) { PushNoticeGrow(m, string(buf)) }, nil)).ProcessHold(toastContent(m, ice.SUCCESS))
|
||||
}
|
||||
|
||||
func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [progress]]]
|
||||
@ -111,13 +111,16 @@ func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [p
|
||||
}
|
||||
PushNoticeToast(m, text, arg)
|
||||
}
|
||||
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, ice.FAILURE, arg...) }
|
||||
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, ice.SUCCESS, arg...) }
|
||||
func toastContent(m *ice.Message, state string) string {
|
||||
return kit.Join([]string{map[string]string{ice.PROCESS: "🕑", ice.FAILURE: "❌", ice.SUCCESS: "✅"}[state], state, m.ActionKey()}, " ")
|
||||
}
|
||||
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, toastContent(m, ice.FAILURE), arg...) }
|
||||
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, toastContent(m, ice.SUCCESS), arg...) }
|
||||
func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.List("", "-1") })
|
||||
kit.If(len(arg) == 1, func() { arg = append(arg, "-1") })
|
||||
Toast(m, ice.PROCESS, arg...)
|
||||
return func() { Toast(m, ice.SUCCESS) }
|
||||
Toast(m, toastContent(m, ice.PROCESS), arg...)
|
||||
return func() { Toast(m, toastContent(m, ice.SUCCESS)) }
|
||||
}
|
||||
func GoToast(m *ice.Message, title string, cb func(toast func(string, int, int)) []string) {
|
||||
_total := 0
|
||||
|
@ -78,7 +78,9 @@ Volcanos(chat.ONIMPORT, {
|
||||
sub.onexport.marginTop = function() { return 25 }
|
||||
sub.onexport.marginBottom = function() { return 100 }
|
||||
sub.onexport.actionHeight = function(sub) { return can.page.ClassList.has(can, sub._target, html.OUTPUT)? 0: html.ACTION_HEIGHT+20 },
|
||||
can.onmotion.move(can, sub._target, {"z-index": 10, top: item.top, left: item.left}), sub.onmotion.resize(can, sub._target, function(height, width) { sub.onimport.size(sub, height, width) }, 25)
|
||||
can.onmotion.move(can, sub._target, {"z-index": 10, top: item.top, left: item.left}), sub.onmotion.resize(can, sub._target, function(height, width) {
|
||||
sub.onimport.size(sub, item.height = height, item.width = width)
|
||||
}, 25)
|
||||
sub._target.onclick = function(event) { can.ondetail.select(can, sub._target) }
|
||||
}, can.ui.desktop)
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
const FINDER = "finder"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{FINDER: {Name: "finder list insert", Actions: ice.MergeActions(ice.Actions{
|
||||
Index.MergeCommands(ice.Commands{FINDER: {Name: "finder list insert", Help: "应用", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(APPLICATIONS, mdb.INPUTS, arg) }},
|
||||
mdb.INSERT: {Name: "insert space index* args name* icon*", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(APPLICATIONS, mdb.CREATE, arg) }},
|
||||
}, CmdHashAction(mdb.NAME))}})
|
||||
|
@ -39,6 +39,16 @@ func _install_download(m *ice.Message) {
|
||||
web.GoToast(m, name, func(toast func(string, int, int)) (list []string) {
|
||||
defer nfs.TarExport(m, file)
|
||||
begin := time.Now()
|
||||
if mdb.Config(m, "repos") != "" {
|
||||
web.SpideSave(m, file, mdb.Config(m, "repos")+path.Base(link), func(count, total, value int) {
|
||||
cost := time.Now().Sub(begin)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, value })
|
||||
toast(kit.FormatShow(nfs.FROM, begin.Format("15:04:05"), cli.COST, kit.FmtDuration(cost), cli.REST, kit.FmtDuration(cost*time.Duration(101)/time.Duration(value+1)-cost)), count, total)
|
||||
})
|
||||
if s, e := nfs.StatFile(m, file); e == nil && s.Size() > 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
web.SpideSave(m, file, link, func(count, total, value int) {
|
||||
cost := time.Now().Sub(begin)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, value })
|
||||
@ -61,8 +71,10 @@ func _install_build(m *ice.Message, arg ...string) string {
|
||||
case func(string):
|
||||
cb(p)
|
||||
case nil:
|
||||
if msg := m.Cmd(cli.SYSTEM, "./configure", "--prefix="+pp, arg[1:]); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR) + msg.Append(cli.CMD_OUT)
|
||||
if nfs.Exists(m, path.Join(p, "./configure")) {
|
||||
if msg := m.Cmd(cli.SYSTEM, "./configure", "--prefix="+pp, arg[1:]); !cli.IsSuccess(msg) {
|
||||
return msg.Append(cli.CMD_ERR) + msg.Append(cli.CMD_OUT)
|
||||
}
|
||||
}
|
||||
default:
|
||||
return m.ErrorNotImplement(cb).Result()
|
||||
@ -138,7 +150,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(arg[1:]), "time,port,status,pid,cmd,dir")
|
||||
m.Fields(len(kit.Slice(arg, 1)), "time,port,status,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] {
|
||||
|
@ -55,7 +55,7 @@ const PLAN = "plan"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PLAN: {Name: "plan scale=week,day,week,month,year,long begin_time@date list prev next", Help: "计划表", Actions: ice.MergeActions(ice.Actions{
|
||||
PLAN: {Name: "plan scale=month,day,week,month,year,long begin_time@date list prev next", Help: "计划表", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TODO, mdb.INPUTS, arg) }},
|
||||
mdb.PLUGIN: {Name: "plugin extra.index extra.args", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TASK, mdb.MODIFY, arg) }},
|
||||
ice.RUN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
7
exec.go
7
exec.go
@ -69,7 +69,7 @@ func (m *Message) Go(cb func(), arg ...Any) *Message {
|
||||
func (m *Message) Wait(cb ...Handler) (wait func(), done Handler) {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
t := time.AfterFunc(kit.Duration("30s"), func() { wg.Done() })
|
||||
t := time.AfterFunc(kit.Duration("180s"), func() { wg.Done() })
|
||||
return func() { wg.Wait() }, func(msg *Message, arg ...string) {
|
||||
defer wg.Done()
|
||||
defer t.Stop()
|
||||
@ -90,7 +90,7 @@ func (m *Message) Cmdx(arg ...Any) string {
|
||||
}
|
||||
func (m *Message) Cmdy(arg ...Any) *Message { return m.Copy(m._command(arg...)) }
|
||||
func (m *Message) CmdHand(cmd *Command, key string, arg ...string) *Message {
|
||||
if m._cmd, m._key = cmd, key; cmd == nil {
|
||||
if m._cmd, m._key, m._sub = cmd, key, LIST; cmd == nil {
|
||||
return m
|
||||
}
|
||||
if m._target = cmd.FileLines(); key == SELECT {
|
||||
@ -101,6 +101,7 @@ func (m *Message) CmdHand(cmd *Command, key string, arg ...string) *Message {
|
||||
if cmd.Hand != nil {
|
||||
cmd.Hand(m, arg...)
|
||||
} else if cmd.Actions != nil && cmd.Actions[SELECT] != nil {
|
||||
m._sub = SELECT
|
||||
cmd.Actions[SELECT].Hand(m, arg...)
|
||||
}
|
||||
return m
|
||||
@ -175,7 +176,7 @@ func (m *Message) _command(arg ...Any) *Message {
|
||||
return m
|
||||
}
|
||||
func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) *Message {
|
||||
if m._cmd, m._key, m._sub = cmd, key, SELECT; cmd == nil {
|
||||
if m._cmd, m._key = cmd, key; cmd == nil {
|
||||
return m
|
||||
}
|
||||
if m.meta[MSG_DETAIL] = kit.Simple(m.PrefixKey(), arg); cmd.Actions != nil {
|
||||
|
@ -468,6 +468,11 @@ func init() {
|
||||
CLONE: {Name: "clone origin* branch name path", Help: "克隆", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(mdb.NAME, path.Base(m.Option(ORIGIN)))
|
||||
m.OptionDefault(nfs.PATH, path.Join(path.Join(nfs.USR, m.Option(mdb.NAME))))
|
||||
defer m.Cmdy(nfs.DIR, m.Option(nfs.PATH))
|
||||
if nfs.Exists(m, m.Option(nfs.PATH)) {
|
||||
return
|
||||
}
|
||||
defer web.ToastProcess(m)()
|
||||
if _, err := git.PlainClone(m.Option(nfs.PATH), false, &git.CloneOptions{URL: m.Option(ORIGIN), Auth: _repos_auth(m, m.Option(ORIGIN))}); m.Warn(err) {
|
||||
_repos_insert(m, m.Option(nfs.PATH))
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
psh "shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/chat/macos"
|
||||
"shylinux.com/x/icebergs/misc/xterm"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -147,6 +148,10 @@ func init() {
|
||||
psh.Index.MergeCommands(ice.Commands{
|
||||
SERVICE: {Name: "service port id auto listen prunes", Help: "服务", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() {
|
||||
m.Sleep("1s")
|
||||
macos.AppInstall(m, "sshd", m.Prefix(SERVICE), mdb.ICON, "usr/icons/ssh.png")
|
||||
})
|
||||
mdb.HashSelect(m).Table(func(value ice.Maps) {
|
||||
if value[mdb.STATUS] == tcp.OPEN {
|
||||
m.Cmd(SERVICE, tcp.LISTEN, tcp.PORT, value[tcp.PORT], value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user