mirror of
https://shylinux.com/x/icebergs
synced 2025-05-01 19:19:24 +08:00
opt nfs
This commit is contained in:
parent
114a75b45f
commit
ea23534857
@ -35,7 +35,7 @@ func _user_create(m *ice.Message, role, name, word string) {
|
||||
func _user_search(m *ice.Message, name, text string) {
|
||||
m.Richs(USER, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); name == "" || name == value[USERNAME] {
|
||||
m.PushSearch(kit.SimpleKV("", kit.Format(value[USERROLE]), kit.Format(value[USERNAME]), kit.Format(value[USERNICK])), value)
|
||||
m.PushSearch(kit.SimpleKV("", value[USERROLE], value[USERNAME], value[USERNICK]), value)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -110,6 +110,7 @@ func init() {
|
||||
USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, USER, m.PrefixKey())
|
||||
UserRoot(ice.Pulse)
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == USER {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const CLI = "cli"
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ctx
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const CTX = "ctx"
|
||||
|
||||
|
@ -38,9 +38,12 @@ const (
|
||||
LINK = "link"
|
||||
SCAN = "scan"
|
||||
HELP = "help"
|
||||
SHOW = "show"
|
||||
|
||||
SHORT = "short"
|
||||
FIELD = "field"
|
||||
COUNT = "count"
|
||||
LIMIT = "limit"
|
||||
EXPIRE = "expire"
|
||||
|
||||
FOREACH = "*"
|
||||
@ -114,8 +117,11 @@ func NextPageLimit(m *ice.Message, total string, arg ...string) {
|
||||
const MDB = "mdb"
|
||||
|
||||
var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
ice.Pulse.Option(CACHE_LIMIT, "10")
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
INSERT: {Name: "insert key sub type arg...", Help: "添加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case ZONE: // insert key sub type zone arg...
|
||||
|
@ -31,45 +31,41 @@ func NewReadCloser(r io.Reader) *ReadCloser {
|
||||
return &ReadCloser{r: r}
|
||||
}
|
||||
|
||||
var rewriteList = []interface{}{}
|
||||
|
||||
func AddRewrite(cb interface{}) { rewriteList = append(rewriteList, cb) }
|
||||
|
||||
func _cat_right(m *ice.Message, name string) bool {
|
||||
switch ls := strings.Split(name, "/"); ls[0] {
|
||||
case ice.USR:
|
||||
switch kit.Select("", ls, 1) {
|
||||
case "local":
|
||||
if m.Warn(m.Option(ice.MSG_USERROLE) == aaa.VOID, ice.ErrNotRight, name) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
case ice.ETC, ice.VAR:
|
||||
if m.Warn(m.Option(ice.MSG_USERROLE) == aaa.VOID, ice.ErrNotRight, name) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return aaa.RoleRight(m, m.Option(ice.MSG_USERROLE), strings.Split(name, ice.PS)...)
|
||||
}
|
||||
func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
||||
if m.Option(CAT_CONTENT) != "" {
|
||||
return NewReadCloser(bytes.NewBufferString(m.Option(CAT_CONTENT)))
|
||||
}
|
||||
|
||||
// 模块回调
|
||||
for _, h := range rewriteList {
|
||||
switch h := h.(type) {
|
||||
case func(m *ice.Message, name string) io.ReadCloser:
|
||||
if r := h(m, name); r != nil {
|
||||
return r
|
||||
}
|
||||
case func(m *ice.Message, name string) []byte:
|
||||
if b := h(m, name); b != nil {
|
||||
return NewReadCloser(bytes.NewBuffer(b))
|
||||
}
|
||||
case func(m *ice.Message, name string) string:
|
||||
if s := h(m, name); s != "" {
|
||||
return NewReadCloser(bytes.NewBufferString(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 本地文件
|
||||
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
||||
return f
|
||||
}
|
||||
|
||||
if m.Option(CAT_LOCAL) == ice.TRUE {
|
||||
return nil
|
||||
}
|
||||
|
||||
if b, ok := ice.Info.Pack[name]; ok {
|
||||
m.Logs("binpack", len(b), name)
|
||||
return NewReadCloser(bytes.NewBuffer(b))
|
||||
}
|
||||
|
||||
msg := m.Cmd("spide", ice.DEV, "raw", "GET", path.Join("/share/local/", name))
|
||||
if msg.Result(0) == ice.ErrWarn {
|
||||
return NewReadCloser(bytes.NewBufferString(""))
|
||||
}
|
||||
return NewReadCloser(bytes.NewBufferString(msg.Result()))
|
||||
return nil
|
||||
}
|
||||
func _cat_list(m *ice.Message, name string) {
|
||||
if !_cat_right(m, name) {
|
||||
@ -77,7 +73,7 @@ func _cat_list(m *ice.Message, name string) {
|
||||
}
|
||||
|
||||
f := _cat_find(m, name)
|
||||
if f == nil {
|
||||
if m.Warn(f == nil, ice.ErrNotFound) {
|
||||
return // 没有文件
|
||||
}
|
||||
defer f.Close()
|
||||
@ -104,7 +100,7 @@ func _cat_list(m *ice.Message, name string) {
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
for begin := 0; true; {
|
||||
if n, e := f.Read(buf[begin:]); !m.Warn(e, ice.ErrNotFound, name) {
|
||||
m.Log_IMPORT(FILE, name, kit.MDB_SIZE, n)
|
||||
m.Log_IMPORT(FILE, name, SIZE, n)
|
||||
if begin += n; begin < len(buf) {
|
||||
buf = buf[:begin]
|
||||
break
|
||||
@ -117,9 +113,12 @@ func _cat_list(m *ice.Message, name string) {
|
||||
}
|
||||
|
||||
const (
|
||||
CAT_CONTENT = "cat_content"
|
||||
|
||||
TEMPLATE = "template"
|
||||
SOURCE = "source"
|
||||
TARGET = "target"
|
||||
|
||||
SOURCE = "source"
|
||||
TARGET = "target"
|
||||
|
||||
MASTER = "master"
|
||||
BRANCH = "branch"
|
||||
@ -130,9 +129,6 @@ const (
|
||||
FILE = "file"
|
||||
LINE = "line"
|
||||
SIZE = "size"
|
||||
|
||||
CAT_LOCAL = "cat_local"
|
||||
CAT_CONTENT = "cat_content"
|
||||
)
|
||||
const CAT = "cat"
|
||||
|
||||
@ -140,17 +136,17 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
|
||||
SOURCE, kit.Dict(
|
||||
"sh", ice.TRUE, "shy", ice.TRUE, "py", ice.TRUE,
|
||||
"go", ice.TRUE, "vim", ice.TRUE, "js", ice.TRUE,
|
||||
"json", ice.TRUE, "conf", ice.TRUE, "yml", ice.TRUE,
|
||||
"sh", ice.TRUE, "go", ice.TRUE, "js", ice.TRUE,
|
||||
"shy", ice.TRUE, "json", ice.TRUE, "csv", ice.TRUE,
|
||||
"conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
|
||||
"makefile", ice.TRUE, "license", ice.TRUE, "md", ice.TRUE,
|
||||
),
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, CAT, m.Prefix(CAT))
|
||||
}},
|
||||
CAT: {Name: "cat path auto", Help: "文件", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, CAT, m.PrefixKey())
|
||||
}},
|
||||
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cat_list(m, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
@ -159,7 +155,9 @@ func init() {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
}
|
||||
m.Info("dir_root: %v", m.Option(DIR_ROOT))
|
||||
if m.Option(DIR_ROOT) != "" {
|
||||
m.Info("dir_root: %v", m.Option(DIR_ROOT))
|
||||
}
|
||||
_cat_list(m, arg[0])
|
||||
}},
|
||||
}})
|
||||
|
@ -30,6 +30,8 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
}
|
||||
name = path.Dir(name)
|
||||
}
|
||||
|
||||
// 文件排序
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
for j := i + 1; j < len(list); j++ {
|
||||
if list[i].Name() > list[j].Name() {
|
||||
@ -59,9 +61,9 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
|
||||
for _, field := range fields {
|
||||
switch field {
|
||||
case kit.MDB_TIME:
|
||||
case mdb.TIME:
|
||||
m.Push(field, f.ModTime().Format(ice.MOD_TIME))
|
||||
case kit.MDB_TYPE:
|
||||
case mdb.TYPE:
|
||||
m.Push(field, kit.Select(CAT, DIR, f.IsDir()))
|
||||
|
||||
case "tree":
|
||||
@ -76,10 +78,10 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
m.Push(field, path.Join(name, f.Name())+kit.Select("", ice.PS, f.IsDir()))
|
||||
case FILE:
|
||||
m.Push(field, f.Name()+kit.Select("", ice.PS, f.IsDir()))
|
||||
case kit.MDB_NAME:
|
||||
case mdb.NAME:
|
||||
m.Push(field, f.Name())
|
||||
|
||||
case kit.MDB_SIZE:
|
||||
case SIZE:
|
||||
if f.IsDir() {
|
||||
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
|
||||
m.Push(field, len(ls))
|
||||
@ -106,7 +108,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
}
|
||||
m.Push(field, nline)
|
||||
}
|
||||
case kit.MDB_HASH, "hashs":
|
||||
case mdb.HASH, "hashs":
|
||||
var h [20]byte
|
||||
if f.IsDir() {
|
||||
if d, e := ioutil.ReadDir(p); m.Assert(e) {
|
||||
@ -123,20 +125,19 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
}
|
||||
}
|
||||
|
||||
m.Push(kit.MDB_HASH, kit.Select(kit.Format(h[:6]), kit.Format(h[:]), field == kit.MDB_HASH))
|
||||
case kit.MDB_LINK:
|
||||
m.PushDownload(kit.MDB_LINK, kit.Select("", f.Name(), !f.IsDir()), path.Join(root, name, f.Name()))
|
||||
case "show":
|
||||
p := m.MergeURL2("/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD))
|
||||
switch kit.Ext(f.Name()) {
|
||||
case "jpg", "png":
|
||||
m.Push(mdb.HASH, kit.Select(kit.Format(h[:6]), kit.Format(h[:]), field == mdb.HASH))
|
||||
case mdb.LINK:
|
||||
m.PushDownload(mdb.LINK, kit.Select("", f.Name(), !f.IsDir()), path.Join(root, name, f.Name()))
|
||||
case mdb.SHOW:
|
||||
switch p := m.MergeURL2("/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(f.Name()) {
|
||||
case "png", "jpg":
|
||||
m.PushImages(field, p)
|
||||
case "mp4":
|
||||
m.PushVideos(field, p)
|
||||
default:
|
||||
m.Push(field, "")
|
||||
}
|
||||
case kit.MDB_ACTION:
|
||||
case "action":
|
||||
if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == aaa.VOID {
|
||||
break
|
||||
}
|
||||
@ -156,15 +157,13 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
func _dir_search(m *ice.Message, kind, name string) {
|
||||
msg := _dir_list(m.Spawn(), ice.PWD, "", 0, true, TYPE_BOTH, nil, kit.Split("time,type,name"))
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if !strings.Contains(value[kit.MDB_NAME], name) {
|
||||
if !strings.Contains(value[mdb.NAME], name) {
|
||||
return
|
||||
}
|
||||
|
||||
if value[kit.MDB_TYPE] == CAT {
|
||||
value[kit.MDB_TYPE] = kit.Ext(value[kit.MDB_NAME])
|
||||
if value[mdb.TYPE] == CAT {
|
||||
value[mdb.TYPE] = kit.Ext(value[mdb.NAME])
|
||||
}
|
||||
|
||||
m.PushSearch(ice.CMD, CAT, value)
|
||||
m.PushSearch(value)
|
||||
})
|
||||
}
|
||||
|
||||
@ -195,13 +194,13 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
DIR: {Name: DIR, Help: "目录", Value: kit.Data()},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, DIR, m.Prefix(DIR))
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, DIR, m.Prefix(DIR))
|
||||
}},
|
||||
DIR: {Name: "dir path field... auto upload", Help: "目录", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, DIR, m.PrefixKey())
|
||||
m.Cmd(mdb.RENDER, mdb.CREATE, DIR, m.PrefixKey())
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == kit.MDB_FOREACH {
|
||||
if arg[0] == mdb.FOREACH {
|
||||
return
|
||||
}
|
||||
_dir_search(m, arg[0], arg[1])
|
||||
@ -213,12 +212,12 @@ func init() {
|
||||
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Upload(m.Option(PATH))
|
||||
}},
|
||||
TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(TRASH, m.Option(PATH))
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
os.Remove(m.Option(PATH))
|
||||
}},
|
||||
TRASH: {Name: "trash", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(TRASH, m.Option(PATH))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option(DIR_ROOT) != "" {
|
||||
m.Info("dir_root: %v", m.Option(DIR_ROOT))
|
||||
@ -226,7 +225,7 @@ func init() {
|
||||
_dir_list(m, kit.Select(ice.PWD, m.Option(DIR_ROOT)), kit.Select(ice.PWD, arg, 0),
|
||||
0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)),
|
||||
kit.Split(kit.Select(kit.Select("time,path,size,action", m.OptionFields()), kit.Join(kit.Slice(arg, 1)))))
|
||||
m.SortTimeR(kit.MDB_TIME)
|
||||
m.SortTimeR(mdb.TIME)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, TAR, CAT, DIR, TAIL, TRASH, SAVE, PUSH, COPY, LINK, DEFS) }
|
||||
func init() { ice.Index.Register(Index, nil, TAR, CAT, DIR, DEFS, SAVE, PUSH, COPY, LINK, TAIL, TRASH) }
|
||||
|
@ -10,23 +10,23 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _defs_file(m *ice.Message, name string, text ...string) {
|
||||
if _, e := os.Stat(path.Join(m.Option(DIR_ROOT), name)); os.IsNotExist(e) {
|
||||
_save_file(m, name, text...)
|
||||
}
|
||||
}
|
||||
func _save_file(m *ice.Message, name string, text ...string) {
|
||||
if f, p, e := kit.Create(path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
for _, v := range text {
|
||||
if n, e := f.WriteString(v); m.Assert(e) {
|
||||
m.Log_EXPORT(FILE, p, kit.MDB_SIZE, n)
|
||||
m.Log_EXPORT(FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}
|
||||
func _defs_file(m *ice.Message, name string, text ...string) {
|
||||
if _, e := os.Stat(path.Join(m.Option(DIR_ROOT), name)); os.IsNotExist(e) {
|
||||
_save_file(m, name, text...)
|
||||
}
|
||||
}
|
||||
func _push_file(m *ice.Message, name string, text ...string) {
|
||||
p := path.Join(m.Option(DIR_ROOT), name)
|
||||
if strings.Contains(p, ice.PS) {
|
||||
@ -38,7 +38,7 @@ func _push_file(m *ice.Message, name string, text ...string) {
|
||||
|
||||
for _, k := range text {
|
||||
if n, e := f.WriteString(k); m.Assert(e) {
|
||||
m.Log_EXPORT(FILE, p, kit.MDB_SIZE, n)
|
||||
m.Log_EXPORT(FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
@ -53,8 +53,8 @@ func _copy_file(m *ice.Message, name string, from ...string) {
|
||||
defer s.Close()
|
||||
|
||||
if n, e := io.Copy(f, s); !m.Warn(e, ice.ErrNotFound, name) {
|
||||
m.Log_IMPORT(FILE, v, kit.MDB_SIZE, n)
|
||||
m.Log_EXPORT(FILE, p, kit.MDB_SIZE, n)
|
||||
m.Log_IMPORT(FILE, v, SIZE, n)
|
||||
m.Log_EXPORT(FILE, p, SIZE, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,30 +67,35 @@ func _link_file(m *ice.Message, name string, from string) {
|
||||
}
|
||||
os.Remove(name)
|
||||
os.MkdirAll(path.Dir(name), ice.MOD_DIR)
|
||||
m.Warn(os.Link(from, name), ice.ErrNotFound, from)
|
||||
if e := os.Link(from, name); e != nil {
|
||||
m.Warn(os.Symlink(from, name), ice.ErrFailure, from)
|
||||
}
|
||||
m.Echo(name)
|
||||
}
|
||||
|
||||
const SAVE = "save"
|
||||
const (
|
||||
CONTENT = "content"
|
||||
)
|
||||
const DEFS = "defs"
|
||||
const SAVE = "save"
|
||||
const PUSH = "push"
|
||||
const COPY = "copy"
|
||||
const LINK = "link"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
SAVE: {Name: "save file text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option(kit.MDB_CONTENT))
|
||||
}
|
||||
_save_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
DEFS: {Name: "defs file text...", Help: "默认", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_defs_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
SAVE: {Name: "save file text...", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option(CONTENT))
|
||||
}
|
||||
_save_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
PUSH: {Name: "push file text...", Help: "追加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, m.Option(kit.MDB_CONTENT))
|
||||
arg = append(arg, m.Option(CONTENT))
|
||||
}
|
||||
_push_file(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
@ -98,6 +103,7 @@ func init() {
|
||||
for _, file := range arg[1:] {
|
||||
if _, e := os.Stat(file); e == nil {
|
||||
_copy_file(m, arg[0], arg[1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
@ -17,9 +17,9 @@ func _tail_create(m *ice.Message, arg ...string) {
|
||||
r, w := io.Pipe()
|
||||
m.Go(func() {
|
||||
for bio := bufio.NewScanner(r); bio.Scan(); {
|
||||
m.Log_IMPORT(FILE, file, kit.MDB_SIZE, len(bio.Text()))
|
||||
m.Grow(TAIL, kit.Keys(kit.MDB_HASH, h), kit.Dict(
|
||||
FILE, file, kit.MDB_SIZE, len(bio.Text()), kit.MDB_TEXT, bio.Text(),
|
||||
m.Log_IMPORT(FILE, file, SIZE, len(bio.Text()))
|
||||
m.Grow(TAIL, kit.Keys(mdb.HASH, h), kit.Dict(
|
||||
FILE, file, SIZE, len(bio.Text()), mdb.TEXT, bio.Text(),
|
||||
))
|
||||
}
|
||||
})
|
||||
@ -30,7 +30,7 @@ func _tail_create(m *ice.Message, arg ...string) {
|
||||
})
|
||||
}
|
||||
func _tail_count(m *ice.Message, name string) string {
|
||||
return m.Conf(TAIL, kit.KeyHash(name, kit.Keym(kit.MDB_COUNT)))
|
||||
return m.Conf(TAIL, kit.KeyHash(name, kit.Keym(mdb.COUNT)))
|
||||
}
|
||||
|
||||
const TAIL = "tail"
|
||||
@ -38,24 +38,24 @@ const TAIL = "tail"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
TAIL: {Name: TAIL, Help: "日志流", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,id,file,text",
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,id,file,text",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(TAIL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
value, _ = kit.GetMeta(value), m.Option(kit.MDB_HASH, key)
|
||||
m.Cmd(TAIL, mdb.CREATE, FILE, kit.Format(value[FILE]), kit.MDB_NAME, kit.Format(value[kit.MDB_NAME]))
|
||||
})
|
||||
}},
|
||||
TAIL: {Name: "tail name id auto page filter:text create", Help: "日志流", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(TAIL, "", mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
value, _ = kit.GetMeta(value), m.Option(mdb.HASH, key)
|
||||
m.Cmd(TAIL, mdb.CREATE, kit.SimpleKV("file,name", value))
|
||||
})
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case FILE:
|
||||
m.Cmdy(DIR, kit.Select(ice.PWD, arg, 1), PATH).RenameAppend(PATH, FILE)
|
||||
m.ProcessAgain()
|
||||
case kit.MDB_NAME:
|
||||
case mdb.NAME:
|
||||
m.Push(arg[0], kit.Split(m.Option(FILE), ice.PS))
|
||||
case kit.MDB_LIMIT:
|
||||
case mdb.LIMIT:
|
||||
m.Push(arg[0], kit.List("10", "20", "30", "50"))
|
||||
}
|
||||
}},
|
||||
@ -63,11 +63,11 @@ func init() {
|
||||
_tail_create(m, arg...)
|
||||
}},
|
||||
}, mdb.ZoneAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(kit.Slice(arg, 0, 2)), "time,name,count,file", m.Config(kit.MDB_FIELD))
|
||||
m.Fields(len(kit.Slice(arg, 0, 2)), "time,name,count,file", m.Config(mdb.FIELD))
|
||||
m.OptionPage(kit.Slice(arg, 2)...)
|
||||
|
||||
mdb.ZoneSelect(m.Spawn(c), arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
if strings.Contains(value[kit.MDB_TEXT], m.Option(ice.CACHE_FILTER)) {
|
||||
if strings.Contains(value[mdb.TEXT], m.Option(ice.CACHE_FILTER)) {
|
||||
m.Push("", value, head)
|
||||
}
|
||||
})
|
||||
|
@ -24,28 +24,30 @@ func _trash_create(m *ice.Message, name string) {
|
||||
p := path.Join(m.Config(PATH), h[:2], h)
|
||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||
os.Rename(name, p)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, FILE, p, kit.MDB_FROM, name)
|
||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, FILE, p, FROM, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
FROM = "from"
|
||||
)
|
||||
const TRASH = "trash"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
TRASH: {Name: TRASH, Help: "回收站", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_FROM, kit.MDB_FIELD, "time,hash,file,from",
|
||||
PATH, ice.VAR_TRASH,
|
||||
mdb.SHORT, FROM, mdb.FIELD, "time,hash,file,from", PATH, ice.VAR_TRASH,
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
TRASH: {Name: "trash hash auto prunes", Help: "回收站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.REVERT: {Name: "revert", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
|
||||
os.Rename(m.Option(FILE), m.Option(kit.MDB_FROM))
|
||||
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, m.OptionSimple(kit.MDB_HASH))
|
||||
os.Rename(m.Option(FILE), m.Option(FROM))
|
||||
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
os.Remove(m.Option(FILE))
|
||||
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, m.OptionSimple(kit.MDB_HASH))
|
||||
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunes(m, func(value map[string]string) bool {
|
||||
|
@ -136,7 +136,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2)))
|
||||
ps := f.ps1
|
||||
|
||||
m.Sleep("300ms")
|
||||
m.Sleep300ms()
|
||||
m.I, m.O = f.stdin, f.stdout
|
||||
bio := bufio.NewScanner(f.stdin)
|
||||
for f.prompt(m, ps...); bio.Scan() && f.stdin != nil; f.prompt(m, ps...) {
|
||||
@ -290,7 +290,7 @@ func init() {
|
||||
for _, line := range kit.Split(arg[0], ice.NL, ice.NL) {
|
||||
fmt.Fprintf(f.pipe, line+ice.NL)
|
||||
f.printf(m, line+ice.NL)
|
||||
m.Sleep("300ms")
|
||||
m.Sleep300ms()
|
||||
}
|
||||
m.Echo(f.res)
|
||||
}},
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const SSH = "ssh"
|
||||
|
||||
|
@ -83,7 +83,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
|
||||
// 启动任务
|
||||
m.Cmd(cli.DAEMON, m.Configv(ice.CMD), ice.DEV, ice.DEV, mdb.NAME, name, m.OptionSimple(RIVER))
|
||||
defer m.Event(DREAM_CREATE, kit.SimpleKV(m.Option(mdb.TYPE), name)...)
|
||||
defer m.Event(DREAM_CREATE, kit.SimpleKV("", m.Option(mdb.TYPE), name)...)
|
||||
m.Sleep300ms()
|
||||
}
|
||||
|
||||
|
1
conf.go
1
conf.go
@ -223,6 +223,7 @@ const ( // Err
|
||||
ErrExists = "exists: "
|
||||
ErrExpire = "expire: "
|
||||
ErrTimeout = "timeout: "
|
||||
ErrFailure = "failure: "
|
||||
ErrNotLogin = "not login: "
|
||||
ErrNotFound = "not found: "
|
||||
ErrNotRight = "not right: "
|
||||
|
@ -86,6 +86,13 @@ func init() {
|
||||
}
|
||||
return false
|
||||
})
|
||||
nfs.AddRewrite(func(msg *ice.Message, name string) []byte {
|
||||
if b, ok := ice.Info.Pack[name]; ok {
|
||||
m.Logs("binpack", len(b), name)
|
||||
return b
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if pack, p, e := kit.Create(ice.SRC_BINPACK_GO); m.Assert(e) {
|
||||
|
1
init.go
1
init.go
@ -109,7 +109,6 @@ func Run(arg ...string) string {
|
||||
}
|
||||
|
||||
Index.root, Pulse.root = Index, Pulse
|
||||
Pulse.Option(CACHE_LIMIT, "10")
|
||||
|
||||
switch Index.Merge(Index).Begin(Pulse.Spawn(), arg...); kit.Select("", arg, 0) {
|
||||
case "serve", "space":
|
||||
|
@ -49,7 +49,6 @@ func _status_tags(m *ice.Message) {
|
||||
}
|
||||
|
||||
change := false
|
||||
m.Option(nfs.CAT_LOCAL, ice.TRUE)
|
||||
m.Option(nfs.DIR_ROOT, _repos_path(k))
|
||||
mod := m.Cmdx(nfs.CAT, ice.GO_MOD, func(text string, line int) string {
|
||||
ls := kit.Split(strings.TrimPrefix(text, ice.REQUIRE))
|
||||
|
@ -188,7 +188,7 @@ func init() {
|
||||
}},
|
||||
CMD: {Name: "cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(cli.SYSTEM, TMUX, "send-keys", "-t", arg[0], strings.Join(arg[1:], ice.SP), "Enter")
|
||||
m.Sleep("100ms")
|
||||
m.Sleep300ms()
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user