forked from x/icebergs
add lex.split
This commit is contained in:
parent
805759a171
commit
f421b9cbc1
111
base/nfs/cat.go
111
base/nfs/cat.go
@ -14,11 +14,32 @@ import (
|
|||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _cat_ext(name string) string {
|
type ReadCloser struct {
|
||||||
return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), ".")))
|
r io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ReadCloser) Read(buf []byte) (int, error) {
|
||||||
|
return r.r.Read(buf)
|
||||||
|
}
|
||||||
|
func (r *ReadCloser) Close() error {
|
||||||
|
if c, ok := r.r.(io.Closer); ok {
|
||||||
|
return c.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func NewReadCloser(r io.Reader) *ReadCloser {
|
||||||
|
return &ReadCloser{r: r}
|
||||||
|
}
|
||||||
|
|
||||||
func _cat_right(m *ice.Message, name string) bool {
|
func _cat_right(m *ice.Message, name string) bool {
|
||||||
switch strings.Split(name, "/")[0] {
|
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, "of", name) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
case ice.ETC, ice.VAR:
|
case ice.ETC, ice.VAR:
|
||||||
if m.Warn(m.Option(ice.MSG_USERROLE) == aaa.VOID, ice.ErrNotRight, "of", name) {
|
if m.Warn(m.Option(ice.MSG_USERROLE) == aaa.VOID, ice.ErrNotRight, "of", name) {
|
||||||
return false
|
return false
|
||||||
@ -27,56 +48,62 @@ func _cat_right(m *ice.Message, name string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
func _cat_find(m *ice.Message, name string) io.ReadCloser {
|
||||||
|
if m.Option("content") != "" {
|
||||||
|
return NewReadCloser(bytes.NewBufferString(m.Option("content")))
|
||||||
|
}
|
||||||
|
|
||||||
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
if b, ok := ice.Info.Pack[name]; ok {
|
if b, ok := ice.Info.Pack[name]; ok {
|
||||||
m.Logs("binpack", len(b), name)
|
m.Logs("binpack", len(b), name)
|
||||||
return kit.NewReadCloser(bytes.NewBuffer(b))
|
return NewReadCloser(bytes.NewBuffer(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := m.Cmd("web.spide", ice.DEV, "raw", "GET", path.Join("/share/local/", name))
|
msg := m.Cmd("web.spide", ice.DEV, "raw", "GET", path.Join("/share/local/", name))
|
||||||
if msg.Result(0) == ice.ErrWarn {
|
if msg.Result(0) == ice.ErrWarn {
|
||||||
return kit.NewReadCloser(bytes.NewBufferString(""))
|
return NewReadCloser(bytes.NewBufferString(""))
|
||||||
}
|
}
|
||||||
return kit.NewReadCloser(bytes.NewBufferString(msg.Result()))
|
return NewReadCloser(bytes.NewBufferString(msg.Result()))
|
||||||
}
|
}
|
||||||
func _cat_show(m *ice.Message, name string) {
|
func _cat_show(m *ice.Message, name string) {
|
||||||
if !_cat_right(m, name) {
|
if !_cat_right(m, name) {
|
||||||
return // 没有权限
|
return // 没有权限
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本地文件
|
|
||||||
f := _cat_find(m, name)
|
f := _cat_find(m, name)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
switch cb := m.Optionv(kit.Keycb(CAT)).(type) {
|
switch cb := m.Optionv(kit.Keycb(CAT)).(type) {
|
||||||
case func(string, int) string:
|
case func(string, int) string:
|
||||||
list := []string{}
|
list := []string{}
|
||||||
bio := bufio.NewScanner(f)
|
for bio, i := bufio.NewScanner(f), 0; bio.Scan(); i++ {
|
||||||
for i := 0; bio.Scan(); i++ {
|
|
||||||
list = append(list, cb(bio.Text(), i))
|
list = append(list, cb(bio.Text(), i))
|
||||||
}
|
}
|
||||||
m.Echo(strings.Join(list, "\n") + "\n")
|
m.Echo(strings.Join(list, ice.NL) + ice.NL)
|
||||||
|
|
||||||
case func(string, int):
|
case func(string, int):
|
||||||
bio := bufio.NewScanner(f)
|
for bio, i := bufio.NewScanner(f), 0; bio.Scan(); i++ {
|
||||||
for i := 0; bio.Scan(); i++ {
|
|
||||||
cb(bio.Text(), i)
|
cb(bio.Text(), i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case func(string):
|
||||||
|
for bio := bufio.NewScanner(f); bio.Scan(); {
|
||||||
|
cb(bio.Text())
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
buf := make([]byte, ice.MOD_BUFS)
|
buf := make([]byte, ice.MOD_BUFS)
|
||||||
for begin := 0; true; {
|
for begin := 0; true; {
|
||||||
n, e := f.Read(buf[begin:])
|
if n, e := f.Read(buf[begin:]); !m.Warn(e != nil && e != io.EOF, e) {
|
||||||
m.Warn(e != nil && e != io.EOF, e)
|
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
|
||||||
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
|
if begin += n; begin < len(buf) {
|
||||||
if begin += n; begin < len(buf) {
|
buf = buf[:begin]
|
||||||
buf = buf[:begin]
|
break
|
||||||
break
|
}
|
||||||
|
buf = append(buf, make([]byte, ice.MOD_BUFS)...)
|
||||||
}
|
}
|
||||||
buf = append(buf, make([]byte, ice.MOD_BUFS)...)
|
|
||||||
}
|
}
|
||||||
m.Echo(string(buf))
|
m.Echo(string(buf))
|
||||||
}
|
}
|
||||||
@ -90,30 +117,26 @@ const (
|
|||||||
const CAT = "cat"
|
const CAT = "cat"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
Configs: map[string]*ice.Config{
|
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
|
||||||
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
|
kit.SSH_SOURCE, kit.Dict(
|
||||||
kit.SSH_SOURCE, kit.Dict(
|
"sh", "true", "shy", "true", "py", "true",
|
||||||
"sh", "true", "shy", "true", "py", "true",
|
"go", "true", "vim", "true", "js", "true",
|
||||||
"go", "true", "vim", "true", "js", "true",
|
"json", "true", "conf", "true", "yml", "true",
|
||||||
"conf", "true", "json", "true",
|
"makefile", "true",
|
||||||
"makefile", "true",
|
),
|
||||||
"yml", "true",
|
)},
|
||||||
),
|
}, Commands: map[string]*ice.Command{
|
||||||
)},
|
CAT: {Name: "cat path auto", Help: "文件", Action: map[string]*ice.Action{
|
||||||
},
|
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
Commands: map[string]*ice.Command{
|
_cat_show(m, path.Join(arg[2], arg[1]))
|
||||||
CAT: {Name: "cat path auto", Help: "文件", Action: map[string]*ice.Action{
|
|
||||||
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_cat_show(m, path.Join(arg[2], arg[1]))
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
|
||||||
m.Cmdy(DIR, arg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_cat_show(m, arg[0])
|
|
||||||
}},
|
}},
|
||||||
},
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
})
|
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||||
|
m.Cmdy(DIR, arg)
|
||||||
|
} else {
|
||||||
|
_cat_show(m, arg[0])
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func _dir_search(m *ice.Message, kind, name string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if value[kit.MDB_TYPE] == CAT {
|
if value[kit.MDB_TYPE] == CAT {
|
||||||
value[kit.MDB_TYPE] = _cat_ext(value[kit.MDB_NAME])
|
value[kit.MDB_TYPE] = kit.Ext(value[kit.MDB_NAME])
|
||||||
}
|
}
|
||||||
|
|
||||||
m.PushSearch(cli.CMD, CAT, value)
|
m.PushSearch(cli.CMD, CAT, value)
|
||||||
|
@ -11,35 +11,30 @@ import (
|
|||||||
const P_SEARCH = "/search"
|
const P_SEARCH = "/search"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||||
Configs: map[string]*ice.Config{
|
P_SEARCH: {Name: P_SEARCH, Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||||
P_SEARCH: {Name: P_SEARCH, Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
}, Commands: map[string]*ice.Command{
|
||||||
},
|
P_SEARCH: {Name: P_SEARCH, Help: "搜索引擎", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
Commands: map[string]*ice.Command{
|
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
m.Richs(P_SEARCH, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
m.Cmd(mdb.SEARCH, mdb.CREATE, P_SEARCH, m.Prefix(P_SEARCH))
|
if value = kit.GetMeta(value); arg[1] != "" && !kit.Contains(value[kit.MDB_NAME], arg[1]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.PushSearch(cli.CMD, P_SEARCH, value)
|
||||||
|
})
|
||||||
}},
|
}},
|
||||||
P_SEARCH: {Name: P_SEARCH, Help: "搜索引擎", Action: ice.MergeAction(map[string]*ice.Action{
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
m.Cmdy(m.Space(m.Option(cli.POD)), mdb.RENDER, arg[1:])
|
||||||
m.Richs(P_SEARCH, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
|
||||||
if value = kit.GetMeta(value); arg[1] != "" && !kit.Contains(value[kit.MDB_NAME], arg[1]) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.PushSearch(cli.CMD, P_SEARCH, value)
|
|
||||||
})
|
|
||||||
}},
|
|
||||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy(m.Space(m.Option(cli.POD)), mdb.RENDER, arg[1:])
|
|
||||||
}},
|
|
||||||
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if kit.Contains(arg[1], ";") {
|
|
||||||
arg = kit.Split(arg[1], ";", ";", ";")
|
|
||||||
}
|
|
||||||
if m.Cmdy(m.Space(m.Option(cli.POD)), mdb.SEARCH, arg); arg[1] == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Cmd(mdb.INSERT, m.Prefix(P_SEARCH), "", mdb.HASH,
|
|
||||||
kit.MDB_NAME, arg[1], kit.MDB_TYPE, arg[0], kit.MDB_TEXT, kit.Select("", arg, 2))
|
|
||||||
}},
|
}},
|
||||||
}})
|
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if kit.Contains(arg[1], ";") {
|
||||||
|
arg = kit.Split(arg[1], ";", ";", ";")
|
||||||
|
}
|
||||||
|
if m.Cmdy(m.Space(m.Option(cli.POD)), mdb.SEARCH, arg); arg[1] == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Cmd(mdb.INSERT, m.Prefix(P_SEARCH), "", mdb.HASH,
|
||||||
|
kit.MDB_NAME, arg[1], kit.MDB_TYPE, arg[0], kit.MDB_TEXT, kit.Select("", arg, 2))
|
||||||
|
}},
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
|
1
go.sum
1
go.sum
@ -1,4 +1,5 @@
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||||
shylinux.com/x/toolkits v0.3.5 h1:J0KlCuIPiJc074+5T0nUJawp3MJGH8VQKzqlpRsVQ70=
|
shylinux.com/x/toolkits v0.3.5 h1:J0KlCuIPiJc074+5T0nUJawp3MJGH8VQKzqlpRsVQ70=
|
||||||
shylinux.com/x/toolkits v0.3.5/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
shylinux.com/x/toolkits v0.3.5/go.mod h1:8LbYHe7oxBIqb6s4MSOD+4d28QvPdvkyCVtwB/JW7AA=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user