1
0
forked from x/icebergs

opt upload

This commit is contained in:
shaoying 2020-09-25 19:48:29 +08:00
parent fec87fa5f4
commit 3f5860f63d
19 changed files with 383 additions and 598 deletions

View File

@ -28,183 +28,146 @@ func _file_ext(name string) string {
func _file_list(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) {
switch strings.Split(name, "/")[0] {
case "etc", "var":
if m.Option(ice.MSG_USERROLE) == "root" {
break
if m.Option(ice.MSG_USERROLE) == "void" {
return // 保护目录
}
if m.Option(ice.MSG_USERROLE) == "tech" {
break
}
return
}
if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil {
if f, e := os.Open(path.Join(root, name)); e != nil {
} else {
defer f.Close()
if b, e := ioutil.ReadAll(f); e == nil {
m.Echo(string(b))
return
}
fs, e := ioutil.ReadDir(path.Join(root, name))
if m.Warn(e != nil, ice.ErrNotFound, name) {
return // 查找失败
}
for _, f := range fs {
if f.Name() == "." || f.Name() == ".." {
continue
}
if strings.HasPrefix(f.Name(), ".") && dir_type != TYPE_ALL {
continue
}
} else {
for _, f := range fs {
if f.Name() == "." || f.Name() == ".." {
continue
}
if strings.HasPrefix(f.Name(), ".") && dir_type != "all" {
continue
}
p := path.Join(root, name, f.Name())
// if f, e = os.Lstat(p); e != nil {
// m.Log("info", "%s", e)
// continue
// } else if (f.Mode()&os.ModeSymlink) != 0 && f.IsDir() {
// // continue
// } else {
// }
//
if !(dir_type == "file" && f.IsDir() || dir_type == "dir" && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) {
for _, field := range fields {
switch field {
case "time":
m.Push("time", f.ModTime().Format(ice.MOD_TIME))
case "type":
if m.Assert(e) && f.IsDir() {
m.Push("type", DIR)
} else {
m.Push("type", FILE)
}
case "full":
if f.IsDir() {
m.Push("full", path.Join(root, name, f.Name())+"/")
} else {
m.Push("full", path.Join(root, name, f.Name()))
}
case "path":
if f.IsDir() {
m.Push("path", path.Join(name, f.Name())+"/")
} else {
m.Push("path", path.Join(name, f.Name()))
}
case "file":
if f.IsDir() {
m.Push("file", f.Name()+"/")
} else {
m.Push("file", f.Name())
}
case "name":
m.Push("name", f.Name())
case "link":
if f.IsDir() {
m.Push("link", "")
} else {
m.Push("link", m.Cmdx("mdb.render", "download",
kit.MergeURL(path.Join("/share/local/", root, name, f.Name()), "pod", m.Option("user.pod")), f.Name()))
}
p := path.Join(root, name, f.Name())
case "tree":
if level == 0 {
m.Push("tree", f.Name())
if !(dir_type == TYPE_FILE && f.IsDir() || dir_type == TYPE_DIR && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) {
for _, field := range fields {
switch field {
case "time":
m.Push("time", f.ModTime().Format(ice.MOD_TIME))
case "type":
if m.Assert(e) && f.IsDir() {
m.Push("type", DIR)
} else {
m.Push("type", FILE)
}
case "tree":
if level == 0 {
m.Push("tree", f.Name())
} else {
m.Push("tree", strings.Repeat("| ", level-1)+"|-"+f.Name())
}
case "full":
if f.IsDir() {
m.Push("full", path.Join(root, name, f.Name())+"/")
} else {
m.Push("full", path.Join(root, name, f.Name()))
}
case "path":
if f.IsDir() {
m.Push("path", path.Join(name, f.Name())+"/")
} else {
m.Push("path", path.Join(name, f.Name()))
}
case "file":
if f.IsDir() {
m.Push("file", f.Name()+"/")
} else {
m.Push("file", f.Name())
}
case "name":
m.Push("name", f.Name())
case "link":
if f.IsDir() {
m.Push("link", "")
} else {
m.PushRender("link", "a", kit.MergeURL(path.Join("/share/local/",
root, name, f.Name()), "pod", m.Option(ice.MSG_USERPOD)), f.Name())
}
case "size":
if f.IsDir() {
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
m.Push("size", len(ls))
} else {
m.Push("tree", strings.Repeat("| ", level-1)+"|-"+f.Name())
m.Push("size", 0)
}
case "size":
if f.IsDir() {
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
m.Push("size", len(ls))
} else {
m.Push("size", 0)
}
} else {
m.Push("size", kit.FmtSize(f.Size()))
}
case "line":
if f.IsDir() {
if ls, e := ioutil.ReadDir(path.Join(root, name, f.Name())); e == nil {
m.Push("size", len(ls))
} else {
m.Push("size", kit.FmtSize(f.Size()))
m.Push("size", 0)
}
case "line":
if f.IsDir() {
if d, e := ioutil.ReadDir(p); m.Assert(e) {
count := 0
for _, f := range d {
if strings.HasPrefix(f.Name(), ".") {
continue
}
count++
}
m.Push("line", count)
}
} else {
nline := 0
if f, e := os.Open(p); m.Assert(e) {
defer f.Close()
for bio := bufio.NewScanner(f); bio.Scan(); nline++ {
bio.Text()
}
}
m.Push("line", nline)
}
case "hash", "hashs":
var h [20]byte
if f.IsDir() {
if d, e := ioutil.ReadDir(p); m.Assert(e) {
meta := []string{}
for _, v := range d {
meta = append(meta, fmt.Sprintf("%s%d%s", v.Name(), v.Size(), v.ModTime()))
}
sort.Strings(meta)
h = sha1.Sum([]byte(strings.Join(meta, "")))
}
} else {
if f, e := ioutil.ReadFile(path.Join(name, f.Name())); m.Assert(e) {
h = sha1.Sum(f)
} else {
nline := 0
if f, e := os.Open(p); m.Assert(e) {
defer f.Close()
for bio := bufio.NewScanner(f); bio.Scan(); nline++ {
bio.Text()
}
}
if field == "hash" {
m.Push("hash", hex.EncodeToString(h[:]))
} else {
m.Push("hash", hex.EncodeToString(h[:4]))
m.Push("line", nline)
}
case "hash", "hashs":
var h [20]byte
if f.IsDir() {
if d, e := ioutil.ReadDir(p); m.Assert(e) {
meta := []string{}
for _, v := range d {
meta = append(meta, fmt.Sprintf("%s%d%s", v.Name(), v.Size(), v.ModTime()))
}
sort.Strings(meta)
h = sha1.Sum([]byte(strings.Join(meta, "")))
}
} else {
if f, e := ioutil.ReadFile(path.Join(name, f.Name())); m.Assert(e) {
h = sha1.Sum(f)
}
}
if field == "hash" {
m.Push("hash", hex.EncodeToString(h[:]))
} else {
m.Push("hash", hex.EncodeToString(h[:6]))
}
}
}
if f.IsDir() && deep {
_file_list(m, root, path.Join(name, f.Name()), level+1, deep, dir_type, dir_reg, fields)
}
}
if f.IsDir() && deep {
_file_list(m, root, path.Join(name, f.Name()), level+1, deep, dir_type, dir_reg, fields)
}
}
}
func _file_show(m *ice.Message, name string) {
// if n := m.Cmd("file_rewrite", name).Append("to"); n != "" {
// m.Logs("rewrite", "from", name, "to", n)
// name = n
// }
if strings.HasPrefix(name, "http") {
m.Cmdy("web.spide", "dev", "raw", "GET", name)
return
return // 远程文件
}
if f, e := os.OpenFile(path.Join(m.Option(DIR_ROOT), name), os.O_RDONLY, 0640); os.IsNotExist(e) {
if f, e := os.Open(path.Join(m.Option(DIR_ROOT), name)); e == nil {
defer f.Close()
switch cb := m.Optionv(CAT_CB).(type) {
case func(string, int):
bio := bufio.NewScanner(bytes.NewBufferString(m.Cmdx("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))))
bio := bufio.NewScanner(f)
for i := 0; bio.Scan(); i++ {
cb(bio.Text(), i)
}
default:
m.Cmdy("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))
}
} else if e == nil {
defer f.Close()
if s, e := f.Stat(); m.Assert(e) {
switch cb := m.Optionv(CAT_CB).(type) {
case func(string, int):
bio := bufio.NewScanner(f)
for i := 0; bio.Scan(); i++ {
cb(bio.Text(), i)
}
default:
if s, e := f.Stat(); m.Assert(e) {
buf := make([]byte, s.Size())
if n, e := f.Read(buf); m.Assert(e) {
m.Log_IMPORT(kit.MDB_FILE, name, kit.MDB_SIZE, n)
@ -212,11 +175,24 @@ func _file_show(m *ice.Message, name string) {
}
}
}
return
}
// 远程文件
switch cb := m.Optionv(CAT_CB).(type) {
case func(string, int):
bio := bufio.NewScanner(bytes.NewBufferString(m.Cmdx("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))))
for i := 0; bio.Scan(); i++ {
cb(bio.Text(), i)
}
default:
m.Cmdy("web.spide", "dev", "raw", "GET", path.Join("/share/local/", name))
}
}
func _file_save(m *ice.Message, name string, text ...string) {
if f, p, e := kit.Create(name); m.Assert(e) {
defer f.Close()
for _, v := range text {
if n, e := f.WriteString(v); m.Assert(e) {
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
@ -228,10 +204,12 @@ func _file_save(m *ice.Message, name string, text ...string) {
func _file_copy(m *ice.Message, name string, from ...string) {
if f, p, e := kit.Create(name); m.Assert(e) {
defer f.Close()
for _, v := range from {
if s, e := os.Open(v); !m.Warn(e != nil, "%s", e) {
if s, e := os.Open(v); !m.Warn(e != nil, e) {
defer s.Close()
if n, e := io.Copy(f, s); !m.Warn(e != nil, "%s", e) {
if n, e := io.Copy(f, s); !m.Warn(e != nil, e) {
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, n)
}
}
@ -242,16 +220,17 @@ func _file_link(m *ice.Message, name string, from string) {
if from == "" {
return
}
os.MkdirAll(path.Dir(name), 0760)
os.Remove(name)
os.MkdirAll(path.Dir(name), 0750)
os.Link(from, name)
m.Echo(name)
}
func _file_trash(m *ice.Message, name string) {
if s, e := os.Stat(name); e == nil {
if s.IsDir() {
name := path.Base(name) + ".tar.gz"
m.Cmd(cli.SYSTEM, "tar", "zcf", name, name)
tar := path.Base(name) + ".tar.gz"
m.Cmd(cli.SYSTEM, "tar", "zcf", tar, name)
name = tar
}
if f, e := os.Open(name); m.Assert(e) {
@ -261,12 +240,10 @@ func _file_trash(m *ice.Message, name string) {
p := path.Join(m.Conf(TRASH, "meta.path"), h[:2], h)
os.MkdirAll(path.Dir(p), 0777)
os.Rename(name, p)
m.Cmd("web.favor", TRASH, "bin", name, p)
m.Cmdy("mdb.insert", m.Prefix(TRASH), "", "list", "file", p, "from", name)
}
}
}
func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
if kind == kit.MDB_FOREACH {
return
@ -275,11 +252,13 @@ func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
m.Assert(e)
msg := m.Spawn()
_file_list(msg, "./", "", 0, true, "both", rg, []string{"time", "size", "type", "path"})
_file_list(msg, "./", "", 0, true, TYPE_ALL, rg, []string{"time", "size", "type", "path"})
msg.Table(func(index int, value map[string]string, head []string) {
if !strings.Contains(value["path"], name) {
return
}
ext := _file_ext(value["path"])
if value["type"] == DIR {
ext = DIR
@ -288,7 +267,7 @@ func _file_search(m *ice.Message, kind, name, text string, arg ...string) {
}
m.Push("pod", m.Option("pod"))
m.Push("ctx", NFS)
m.Push("ctx", "nfs")
m.Push("cmd", FILE)
m.Push(kit.MDB_TIME, value["time"])
m.Push(kit.MDB_SIZE, value["size"])
@ -304,11 +283,6 @@ const (
SAVE = "save"
COPY = "copy"
LINK = "link"
TRASH = "trash"
DIR = "dir"
FILE = "file"
NFS = "nfs"
)
const (
DIR_ROOT = "dir_root"
@ -318,67 +292,56 @@ const (
)
const (
TYPE_ALL = "all"
TYPE_DIR = "dir"
TYPE_BOTH = "both"
TYPE_FILE = "file"
TYPE_DIR = "dir"
)
const TRASH = "trash"
const FILE = "file"
const DIR = "dir"
var Index = &ice.Context{Name: "nfs", Help: "存储模块",
Configs: map[string]*ice.Config{
TRASH: {Name: "trash", Help: "删除", Value: kit.Data("path", "var/trash")},
FILE: {Name: "file", Help: "文件", Value: kit.Data(
DIR: {Name: DIR, Help: "目录", Value: kit.Data()},
FILE: {Name: FILE, Help: "文件", Value: kit.Data(
"source", kit.Dict(
"sh", "true", "shy", "true", "py", "true",
"go", "true", "vim", "true", "js", "true",
"conf", "true", "json", "true",
"makefile", "true",
"sh", "true",
"shy", "true",
"py", "true",
"js", "true",
"go", "true",
"vim", "true",
"conf", "true",
"json", "true",
),
)},
"file_rewrite": {Name: "file_rewrite", Help: "重定向", Value: kit.Data(kit.MDB_SHORT, "from")},
TRASH: {Name: TRASH, Help: "删除", Value: kit.Data("path", "var/trash")},
},
Commands: map[string]*ice.Command{
"file_rewrite": {Name: "file_rewrite", Help: "重定向", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create from to", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix("file_rewrite"), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, "time,hash,from,to")
m.Cmdy(mdb.SELECT, m.Prefix("file_rewrite"), "", mdb.HASH, "from", arg)
}},
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(mdb.SEARCH, mdb.CREATE, FILE)
m.Cmd(mdb.SEARCH, mdb.CREATE, DIR)
m.Cmd(mdb.RENDER, mdb.CREATE, FILE, FILE, NFS)
m.Cmd(mdb.RENDER, mdb.CREATE, DIR)
m.Cmd(mdb.RENDER, mdb.CREATE, "bin", m.AddCmd(&ice.Command{Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo("hello world")
}}))
m.Cmd(mdb.RENDER, mdb.CREATE, "m4v", m.AddCmd(&ice.Command{Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !strings.HasPrefix(arg[1], "http") {
arg[1] = path.Join("/share/local", kit.Path(arg[1]))
}
m.Echo(`<video src="%s" height=400 controls autoplay loop></video>`, arg[1])
}}))
m.Cmd(mdb.SEARCH, mdb.CREATE, FILE, m.Prefix(FILE))
m.Cmd(mdb.RENDER, mdb.CREATE, FILE, m.Prefix(FILE))
}},
FILE: {Name: "file", Help: "文件", Action: map[string]*ice.Action{
DIR: {Name: "dir path field... auto 上传", Help: "目录", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_file_show(m, path.Join(arg[2], arg[1]))
_file_list(m, arg[2], arg[1], 0, m.Option(DIR_DEEP) == "true", kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)),
nil, []string{"time", "size", "type", "path"})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
reg, _ := regexp.Compile(m.Option(DIR_REG))
_file_list(m, kit.Select("./", m.Option(DIR_ROOT)), kit.Select("", arg, 0),
0, m.Options(DIR_DEEP), kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), reg,
kit.Split(kit.Select("time size path", strings.Join(arg[1:], " ")), " "))
m.Sort(kit.MDB_TIME, "time_r")
}},
FILE: {Name: "file path auto", Help: "文件", Action: map[string]*ice.Action{
"append": {Name: "append", Help: "追加", Hand: func(m *ice.Message, arg ...string) {
if f, e := os.OpenFile(arg[0], os.O_WRONLY|os.O_APPEND, 0664); m.Assert(e) {
defer f.Close()
for _, k := range arg[1:] {
if n, e := f.WriteString(k); m.Assert(e) {
m.Log_EXPORT(kit.MDB_FILE, arg[0], kit.MDB_SIZE, n)
@ -386,32 +349,21 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
}
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
DIR: {Name: "dir path=auto field... auto 上传", Help: "目录", Action: map[string]*ice.Action{
"upload": {Name: "upload [name path dev]", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 {
m.Cmdy("spide", "dev", "cache", "GET", kit.MergeURL(arg[2], "path", arg[1], "name", m.Option("name", arg[0])))
} else {
m.Cmdy("cache", "upload")
}
m.Cmdy("cache", "watch", m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
_file_list(m, arg[2], arg[1], 0, m.Option(DIR_DEEP) == "true", kit.Select("both", m.Option(DIR_TYPE)),
nil, []string{"time", "size", "type", "path"})
_file_show(m, path.Join(arg[2], arg[1]))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
reg, _ := regexp.Compile(m.Option(DIR_REG))
_file_list(m, kit.Select("./", m.Option(DIR_ROOT)), kit.Select("", arg, 0),
0, m.Options(DIR_DEEP), kit.Select("both", m.Option(DIR_TYPE)), reg,
kit.Split(kit.Select("time size path", strings.Join(arg[1:], " ")), " "))
m.Sort(kit.MDB_TIME, "time_r")
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
m.Cmdy(DIR, arg)
return
}
_file_show(m, arg[0])
}},
CAT: {Name: "cat file", Help: "查看", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_file_show(m, arg[0])
}},
@ -424,7 +376,6 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
LINK: {Name: "link file from", Help: "链接", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_file_link(m, arg[0], arg[1])
}},
TRASH: {Name: "trash file", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_file_trash(m, arg[0])
}},

View File

@ -2,6 +2,7 @@ package web
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits"
@ -191,7 +192,8 @@ func init() {
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_cache_list(m, kit.Select("", arg, 0))
m.Option(mdb.FIELDS, "time,size,type,name,text,file")
m.Cmdy(mdb.SELECT, m.Prefix(CACHE), "", mdb.HASH, kit.MDB_HASH, arg)
}},
"/cache/": {Name: "/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Richs(CACHE, nil, arg[0], func(key string, value map[string]interface{}) {

View File

@ -110,6 +110,10 @@ func _share_proxy(m *ice.Message, arg ...string) {
}
}
func _share_cache(m *ice.Message, arg ...string) {
msg := m.Cmd(CACHE, arg[0])
m.Render(ice.RENDER_DOWNLOAD, msg.Append(kit.MDB_FILE), msg.Append(kit.MDB_TYPE), msg.Append(kit.MDB_NAME))
}
func _share_remote(m *ice.Message, pod string, arg ...string) {
m.Cmdy(SPACE, pod, "web./publish/", arg)
m.Render(ice.RENDER_RESULT)
@ -285,6 +289,9 @@ func init() {
"/share/proxy/": {Name: "/share/proxy/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_proxy(m, arg...)
}},
"/share/cache/": {Name: "/share/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_cache(m, arg...)
}},
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Richs(SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
m.Log_SELECT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))

View File

@ -104,7 +104,6 @@ func _spide_render(m *ice.Message, kind, name, text string, arg ...string) {
m.Echo(`<iframe src="%s" width=800 height=400></iframe>`, text)
}
const SPIDE = "spide"
const (
SPIDE_SHY = "shy"
SPIDE_DEV = "dev"
@ -138,6 +137,8 @@ const (
ContentHTML = "text/html"
)
const SPIDE = "spide"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
@ -155,7 +156,7 @@ func init() {
m.Cmdy(mdb.SELECT, m.Prefix("spide_rewrite"), "", mdb.HASH, "from", arg)
}},
SPIDE: {Name: "spide name=auto [action:select=msg|raw|cache] [method:select=POST|GET] url [format:select=json|form|part|data|file] arg... auto", Help: "蜘蛛侠", Action: map[string]*ice.Action{
SPIDE: {Name: "spide name=auto [action:select=msg|raw|save|cache] [method:select=POST|GET] url [format:select=json|form|part|data|file] arg... auto", Help: "蜘蛛侠", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create name address", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
_spide_create(m, arg[0], arg[1])
}},

View File

@ -8,6 +8,13 @@ import (
kit "github.com/shylinux/toolkits"
)
func _action_upload(m *ice.Message, arg ...string) {
msg := m.Cmd(web.CACHE, web.UPLOAD)
m.Debug(msg.Formats("meta"))
m.Option("_upload", msg.Append("data"), msg.Append("name"))
m.Debug(m.Formats("meta"))
}
func _action_right(m *ice.Message, river string, storm string) (ok bool) {
if ok = true; m.Option(ice.MSG_USERROLE) == aaa.VOID {
m.Richs(RIVER, "", river, func(key string, value map[string]interface{}) {
@ -28,13 +35,12 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
cmds := []string{index}
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
if m.Grows(RIVER, prefix, kit.MDB_ID, index, func(index int, value map[string]interface{}) {
if cmds = kit.Simple(kit.Keys(value[CTX], value[CMD])); value[POD] != "" {
m.Option(POD, value[POD])
if cmds = kit.Simple(kit.Keys(value[CTX], value[CMD])); kit.Format(value[POD]) != "" {
m.Option(kit.GDB_POD, value[POD])
}
}) == nil && m.Warn(!m.Right(cmds), ice.ErrNotAuth) {
return
}
m.Cmdy(_action_proxy(m), cmds, arg)
}
func _action_proxy(m *ice.Message) (proxy []string) {
@ -50,14 +56,6 @@ const ACTION = "action"
func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
"/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.STORY, web.UPLOAD)
m.Option(kit.MDB_NAME, msg.Append(kit.MDB_NAME))
m.Option(web.DATA, msg.Append(web.DATA))
_action_show(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), m.Option(ice.MSG_ACTION),
append([]string{ACTION, web.UPLOAD}, arg...)...)
}},
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
for _, k := range arg {
m.Cmdy(ctx.COMMAND, k)
@ -73,7 +71,11 @@ func init() {
if len(arg) == 2 {
_action_list(m, arg[0], arg[1])
return
return //命令列表
}
if m.Option("_upload") != "" {
_action_upload(m)
}
_action_show(m, arg[0], arg[1], arg[2], arg[3:]...)
}},

View File

@ -21,11 +21,22 @@ var Index = &ice.Context{Name: CHAT, Help: "聊天中心",
"web.chat.tool",
"web.chat.node",
},
"scan", []interface{}{
"web.chat.scan",
"web.chat.paste",
"web.chat.location",
},
"miss", []interface{}{
"web.team.task",
"web.team.plan",
"web.wiki.word",
},
"wiki", []interface{}{
"web.wiki.draw",
"web.wiki.data",
"web.wiki.feel",
"web.wiki.word",
},
),
))
m.Watch(web.SPACE_START, m.Prefix(NODE))

View File

@ -1,11 +1,13 @@
package chat
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/toolkits"
ice "github.com/shylinux/icebergs"
kit "github.com/shylinux/toolkits"
)
const LEGAL = "legal"
const (
LEGAL = "legal"
)
const FOOTER = "footer"
func init() {

View File

@ -8,7 +8,6 @@ import (
"math"
"net/url"
"strings"
)
func distance(lat1, long1, lat2, long2 float64) float64 {
@ -18,6 +17,11 @@ func distance(lat1, long1, lat2, long2 float64) float64 {
long2 = long2 * math.Pi / 180
return 2 * 6371 * math.Asin(math.Sqrt(math.Pow(math.Sin(math.Abs(lat1-lat2)/2), 2)+math.Cos(lat1)*math.Cos(lat2)*math.Pow(math.Sin(math.Abs(long1-long2)/2), 2)))
}
func _trans(arg []string, tr map[string]string) {
for i := 0; i < len(arg)-1; i += 2 {
arg[i] = kit.Select(arg[i], tr[arg[i]])
}
}
const (
LATITUDE = "latitude"
@ -26,11 +30,6 @@ const (
const LOCATION = "location"
func _trans(arg []string, tr map[string]string) {
for i := 0; i < len(arg)-1; i += 2 {
arg[i] = kit.Select(arg[i], tr[arg[i]])
}
}
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
@ -49,32 +48,21 @@ func init() {
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.DELETE, LOCATION, m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_TEXT, m.Option(kit.MDB_TEXT))
}},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
m.Richs(LOCATION, kit.Keys(kit.MDB_META, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM)), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
if strings.Contains(kit.Format(value[kit.MDB_NAME]), arg[1]) ||
strings.Contains(kit.Format(value[kit.MDB_TEXT]), arg[1]) {
m.Push("pod", m.Option("pod"))
m.Push("ctx", m.Cap(ice.CTX_FOLLOW))
m.Push("cmd", LOCATION)
m.Push(kit.MDB_TIME, value["time"])
m.Push(kit.MDB_SIZE, value["size"])
m.Push(kit.MDB_TYPE, LOCATION)
m.Push(kit.MDB_NAME, value["name"])
m.Push(kit.MDB_TEXT, value["text"])
}
})
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.EXPORT, m.Prefix(LOCATION), m.Option(ice.MSG_DOMAIN), mdb.HASH)
}},
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.IMPORT, m.Prefix(LOCATION), m.Option(ice.MSG_DOMAIN), mdb.HASH)
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INPUTS, LOCATION, m.Option(ice.MSG_DOMAIN), mdb.HASH, arg)
}},
mdb.RENDER: {Name: "render type name text", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.RENDER, web.RENDER.Frame, kit.Format(
"https://map.baidu.com/search/%s/@12958750.085,4825785.55,16z?querytype=s&da_src=shareurl&wd=%s",
arg[2], arg[2]))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INPUTS, LOCATION, m.Option(ice.MSG_DOMAIN), mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, "time,type,name,text,longitude,latitude")
m.Cmdy(mdb.SELECT, LOCATION, m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_HASH, arg)

View File

@ -93,12 +93,12 @@ func init() {
m.Cmdy(mdb.SELECT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), AUTH), mdb.HASH, kit.MDB_HASH, arg)
m.PushAction("删除")
}},
NODE: {Name: "node name ctx cmd auto 邀请", Help: "设备", Action: map[string]*ice.Action{
NODE: {Name: "node name ctx cmd auto 添加 邀请", Help: "设备", Action: map[string]*ice.Action{
mdb.INVITE: {Name: "invite", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
m.Option(web.SHARE, m.Cmdx(AUTH, mdb.CREATE, kit.MDB_TYPE, NODE))
m.Cmdy(code.PUBLISH, "contexts", "tool")
}},
mdb.INSERT: {Name: "insert", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
mdb.INSERT: {Name: "insert type name share", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(RIVER), NODE), mdb.HASH, arg)
}},
web.SPACE_START: {Name: "start type name share river", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
@ -115,10 +115,17 @@ func init() {
m.Cmdy(mdb.DELETE, RIVER, kit.Keys(kit.MDB_HASH, m.Option(RIVER), NODE), mdb.HASH,
kit.MDB_NAME, m.Option(kit.MDB_NAME))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.SPACE)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
m.Option(mdb.FIELDS, "time,type,name,share")
m.Cmdy(mdb.SELECT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), NODE), mdb.HASH)
m.Table(func(index int, value map[string]string, head []string) {
m.PushRender(kit.MDB_LINK, "a", value[kit.MDB_NAME],
kit.MergeURL(m.Option(ice.MSG_USERWEB), kit.GDB_POD, kit.Keys(m.Option(kit.GDB_POD), value[kit.MDB_NAME])))
})
m.PushAction("删除")
return
}
@ -194,25 +201,28 @@ func init() {
m.Cmdy(web.SPACE, value[POD], ctx.CONTEXT, value[CTX], ctx.COMMAND, value[CMD])
})
}},
USER: {Name: "user username auto 邀请", Help: "用户", Action: map[string]*ice.Action{
USER: {Name: "user username auto 添加 邀请", Help: "用户", Action: map[string]*ice.Action{
mdb.INVITE: {Name: "invite", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
share := m.Option(web.SHARE, m.Cmdx(AUTH, mdb.CREATE, kit.MDB_TYPE, USER))
m.Cmdy(wiki.SPARK, "inner", kit.MergeURL(m.Option(ice.MSG_USERWEB), "river", m.Option(ice.MSG_RIVER), "share", share))
m.Cmdy(wiki.IMAGE, "qrcode", kit.MergeURL(m.Option(ice.MSG_USERWEB), "river", m.Option(ice.MSG_RIVER), "share", share))
m.Render("")
}},
mdb.INSERT: {Name: "insert", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
mdb.INSERT: {Name: "insert username userzone usernick", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), mdb.HASH, arg)
}},
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.DELETE, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), mdb.HASH, aaa.USERNAME, m.Option(aaa.USERNAME))
}},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(aaa.USER)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(mdb.FIELDS, "time,username")
m.Cmdy(mdb.SELECT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), USER), mdb.HASH, aaa.USERNAME, arg)
m.Table(func(index int, value map[string]string, head []string) {
m.Push(aaa.USERZONE, aaa.UserZone(m, value[aaa.USERNAME]))
m.Push(aaa.USERNICK, aaa.UserNick(m, value[aaa.USERNAME]))
m.Push(aaa.USERZONE, aaa.UserZone(m, value[aaa.USERNAME]))
})
m.PushAction("删除")
}},
@ -258,19 +268,26 @@ func init() {
"/river": {Name: "/river", Help: "小河流", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Warn(m.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin) {
return
return // 没有登录
}
if len(arg) == 0 {
_river_list(m)
return
return // 群组列表
}
if len(arg) == 2 && arg[1] == TOOL {
m.Option(ice.MSG_RIVER, arg[0])
m.Cmdy(m.Prefix(arg[1]), arg[2:])
return // 应用列表
}
if m.Warn(!m.Right(RIVER, arg), ice.ErrNotAuth) {
return // 没有授权
}
switch kit.Select("", arg, 1) {
case USER, TOOL, NODE:
m.Option(ice.MSG_RIVER, arg[0])
m.Cmdy(m.Prefix(arg[1]), arg[2:])
return
}
if !m.Warn(!m.Right(RIVER, arg), ice.ErrNotAuth) {
default:
m.Cmdy(RIVER, arg)
}
}},

View File

@ -23,6 +23,12 @@ func init() {
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.DELETE, m.Prefix(SCAN), m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_TEXT, m.Option(kit.MDB_TEXT))
}},
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.EXPORT, m.Prefix(SCAN), m.Option(ice.MSG_DOMAIN), mdb.HASH)
}},
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.IMPORT, m.Prefix(SCAN), m.Option(ice.MSG_DOMAIN), mdb.HASH)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 {
text := m.Cmd(mdb.SELECT, m.Prefix(SCAN), m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_HASH, arg[0]).Append(kit.MDB_TEXT)

View File

@ -9,11 +9,11 @@ func init() {
Index.Merge(&ice.Context{
Commands: map[string]*ice.Command{
"/search": {Name: "/search", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "render" {
m.Cmdy(m.Space(m.Option("pod")), mdb.RENDER, arg[1:])
if arg[0] == mdb.RENDER {
m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:])
return
}
m.Cmdy(m.Space(m.Option("pod")), mdb.SEARCH, arg)
m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg)
}},
},
}, nil)

View File

@ -1,39 +1,34 @@
package wiki
import (
"path"
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
kit "github.com/shylinux/toolkits"
)
func _data_show(m *ice.Message, name string, arg ...string) {
m.Cmdy(nfs.CAT, name)
m.CSV(m.Result())
m.CSV(m.Cmd(nfs.CAT, name).Result())
}
const DATA = "data"
const (
DataPlugin = "/plugin/local/wiki/data.js"
)
func init() {
Index.Merge(&ice.Context{Name: "data", Help: "数据表格",
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
DATA: {Name: "data", Help: "数据表格", Value: kit.Data(
DATA: {Name: DATA, Help: "数据表格", Value: kit.Data(
"path", "usr/export", "regs", ".*\\.csv",
)},
},
Commands: map[string]*ice.Command{
DATA: {Name: "data path=auto auto", Help: "数据表格", Meta: kit.Dict(mdb.PLUGIN, DataPlugin), Action: map[string]*ice.Action{
DATA: {Name: "data path auto", Help: "数据表格", Meta: kit.Dict(
"display", "/plugin/local/wiki/data.js",
), Action: map[string]*ice.Action{
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_wiki_save(m, DATA, arg[0], arg[1])
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if !_wiki_list(m, DATA, kit.Select("./", arg, 0)) {
_data_show(m, path.Join(m.Conf(DATA, "meta.path"), arg[0]))
_data_show(m, arg[0])
}
}},
},

View File

@ -11,14 +11,14 @@ import (
const DRAW = "draw"
func init() {
Index.Register(&ice.Context{Name: "draw", Help: "思维导图",
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
DRAW: {Name: "draw", Help: "思维导图", Value: kit.Data(
DRAW: {Name: DRAW, Help: "思维导图", Value: kit.Data(
"path", "", "regs", ".*\\.svg",
)},
},
Commands: map[string]*ice.Command{
DRAW: {Name: "draw path=src/ file=main.svg 刷新:button=auto 编辑:button 保存:button 项目:button 变参:button", Help: "思维导图", Meta: kit.Dict(
DRAW: {Name: "draw path=src/ file=main.svg 刷新:button=auto 编辑 保存 项目 变参", Help: "思维导图", Meta: kit.Dict(
"display", "/plugin/local/wiki/draw.js", "style", "drawer",
), Action: map[string]*ice.Action{
nfs.SAVE: {Name: "save path file text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {

View File

@ -2,58 +2,37 @@ package wiki
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"os"
"path"
)
const FEEL = "feel"
func init() {
Index.Merge(&ice.Context{Name: "feel", Help: "影音媒体",
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
FEEL: {Name: "feel", Help: "影音媒体", Value: kit.Data(
FEEL: {Name: FEEL, Help: "影音媒体", Value: kit.Data(
"path", "usr/image", "regs", ".*.(qrc|png|PNG|jpg|jpeg|JPG|MOV|m4v|mp4)",
)},
},
Commands: map[string]*ice.Command{
FEEL: {Name: "feel path=auto auto 上传:button 上一页:button 下一页:button 下载:button 参数:button", Help: "影音媒体", Meta: kit.Dict(
"display", "/plugin/local/wiki/feel.js", "detail", []string{"标签", "删除"},
FEEL: {Name: "feel path auto 上传 上一页 下一页 下载 参数", Help: "影音媒体", Meta: kit.Dict(
"display", "/plugin/local/wiki/feel.js",
), Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Conf(FEEL, kit.Keys(path.Base(arg[2]), "-2"), arg[3])
p := path.Join(m.Conf(FEEL, "meta.path"), arg[2])
q := path.Join(m.Conf(FEEL, "meta.path"), arg[3])
os.MkdirAll(q, 0777)
m.Assert(os.Link(p, path.Join(q, path.Base(arg[2]))))
}},
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
m.Assert(os.Remove(path.Join(m.Conf(FEEL, "meta.path"), m.Option("path"))))
}},
web.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
if m.Option(ice.MSG_DOMAIN) != "" {
m.Option("path", path.Join("local", m.Option(ice.MSG_DOMAIN), m.Option("path")))
}
_wiki_upload(m, FEEL)
}},
web.SPIDE: {Name: "spide type title url poster", Help: "爬虫", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.SPIDE, "self", "cache", "GET", arg[2])
m.Cmd(web.CACHE, "watch", m.Append("data"), path.Join(m.Conf(FEEL, "meta.path"), m.Option("path"), arg[1])+path.Ext(arg[2]))
if m.Option("path") != "最近" {
m.Cmd(web.CACHE, "watch", m.Append("data"), path.Join(m.Conf(FEEL, "meta.path"), "最近", arg[1])+path.Ext(arg[2]))
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option("prefix", m.Conf(FEEL, "meta.path"))
if m.Option(ice.MSG_DOMAIN) == "" {
_wiki_list(m, FEEL, path.Join(kit.Select("", arg, 0))+"/")
_wiki_list(m, FEEL, kit.Select("./", arg, 0))
} else {
_wiki_list(m, FEEL, path.Join("local", m.Option(ice.MSG_DOMAIN), kit.Select("", arg, 0))+"/")
_wiki_list(m, FEEL, path.Join("local", m.Option(ice.MSG_DOMAIN), kit.Select(".", arg, 0))+"/")
}
m.Sort("time", "time_r")
m.Sort(kit.MDB_TIME, "time_r")
m.Option("_display", "")
}},
},
}, nil)

View File

@ -1,30 +0,0 @@
package wiki
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits"
)
const QRCODE = "qrcode"
func init() {
Index.Register(&ice.Context{Name: QRCODE, Help: "二维码",
Configs: map[string]*ice.Config{
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
QRCODE: {Name: "qrcode", Help: "二维码", Action: map[string]*ice.Action{
mdb.INSERT: {Hand: func(m *ice.Message, arg ...string) {
m.Grow(QRCODE, kit.Keys(m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM)), func(index int, value map[string]interface{}) {
m.Push("", value, []string{kit.MDB_TIME, kit.MDB_TEXT})
})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Grow(QRCODE, kit.Keys(m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM)), func(index int, value map[string]interface{}) {
m.Push("", value, []string{kit.MDB_TIME, kit.MDB_TEXT})
})
}},
},
}, nil)
}

View File

@ -1,126 +0,0 @@
package wiki
import (
"path"
"strings"
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/ssh"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
)
func _wiki_list(m *ice.Message, cmd, name string, arg ...string) bool {
m.Debug(name)
if strings.HasSuffix(name, "/") {
m.Option(nfs.DIR_ROOT, m.Conf(cmd, "meta.path"))
m.Option(nfs.DIR_TYPE, nfs.TYPE_DIR)
m.Cmdy(nfs.DIR, name, "time size path")
m.Option(nfs.DIR_TYPE, nfs.TYPE_FILE)
m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs"))
m.Cmdy(nfs.DIR, name, "time size path")
return true
}
return false
}
func _wiki_show(m *ice.Message, cmd, name string, arg ...string) {
m.Cmdy(nfs.CAT, path.Join(m.Conf(cmd, "meta.path"), name))
}
func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) {
m.Cmd(nfs.SAVE, path.Join(m.Conf(cmd, "meta.path"), name), text)
}
func _wiki_upload(m *ice.Message, cmd string) {
m.Cmdy(web.CACHE, web.UPLOAD)
m.Cmdy(web.CACHE, web.WATCH, m.Option(web.DATA), path.Join(m.Conf(cmd, "meta.path"), m.Option("path"), m.Option("name")))
}
func reply(m *ice.Message, cmd string, arg ...string) bool {
// 文件列表
m.Option(nfs.DIR_ROOT, m.Conf(cmd, "meta.path"))
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
m.Option("_display", "table")
// if m.Option(nfs.DIR_DEEP) == "true" {
// return true
// }
// 目录列表
m.Option(nfs.DIR_TYPE, nfs.DIR)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
// 文件列表
m.Option(nfs.DIR_TYPE, nfs.FILE)
m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs"))
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
return true
}
return false
}
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
"walk": {Name: "walk", Help: "走遍世界", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.csv")},
},
Commands: map[string]*ice.Command{
"walk": {Name: "walk path=@province auto", Help: "走遍世界", Meta: kit.Dict("display", "local/wiki/walk"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "保存":
m.Cmd("nfs.save", path.Join(m.Conf(cmd, "meta.path"), arg[2]), arg[3])
}
return
}
// 文件列表
m.Option("dir_root", m.Conf(cmd, "meta.path"))
m.Option("dir_reg", m.Conf(cmd, "meta.regs"))
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
m.Sort("time", "time_r")
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
// 目录列表
m.Option("dir_reg", "")
m.Option("dir_type", "dir")
m.Cmdy("nfs.dir", kit.Select("./", arg, 0))
return
}
m.Option("title", "我走过的世界")
m.CSV(m.Result())
}},
"mind": {Name: "mind zone type name text", Help: "思考", List: kit.List(
kit.MDB_INPUT, "text", "name", "path", "action", "auto", "figure", "key",
kit.MDB_INPUT, "text", "name", "type", "figure", "key",
kit.MDB_INPUT, "text", "name", "name", "figure", "key",
kit.MDB_INPUT, "button", "name", "添加",
kit.MDB_INPUT, "textarea", "name", "text",
kit.MDB_INPUT, "text", "name", "location", "figure", "key", "cb", "location",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "input":
// 输入补全
switch arg[2] {
case "type":
m.Push("type", []string{"spark", "order", "table", "label", "chain", "refer", "brief", "chapter", "section", "title"})
case "path":
m.Option("_refresh", "true")
reply(m, "word", arg[3:]...)
}
return
}
}
if len(arg) < 2 {
m.Cmdy("word", arg)
return
}
m.Cmd("word", "action", "追加", arg)
m.Option("scan_mode", "scan")
m.Cmdy(ssh.SOURCE, path.Join(m.Conf("word", "meta.path"), arg[0]))
}},
},
}, nil)
}

View File

@ -1,51 +0,0 @@
package wiki
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/format"
)
func init() {
format.RegisterAll()
Index.Register(&ice.Context{Name: "m4v", Help: "视频",
Configs: map[string]*ice.Config{
VIDEO: {Name: "video", Help: "视频", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
"list": {Name: "list name", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(arg[0])
}},
"save": {Name: "save name text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy("nfs.qrcodes", arg)
}},
"show": {Name: "show name", Help: "渲染", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if file, e := avutil.Open(arg[0]); m.Assert(e) {
defer file.Close()
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
m.Push("type", vstream.Type().String())
m.Push("width", vstream.Width())
m.Push("height", vstream.Height())
}
}
}
}
}},
"video": {Name: "video", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(web.FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
m.Echo(`<video src="%s" controls loop></video>`, value["text"])
})
}},
},
}, nil)
}

View File

@ -1,35 +1,64 @@
package wiki
import (
"path"
"strings"
ice "github.com/shylinux/icebergs"
_ "github.com/shylinux/icebergs/base"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
)
func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
m.Option(nfs.DIR_ROOT, m.Conf(cmd, "meta.path"))
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
m.Option("_display", "table")
if m.Option(nfs.DIR_DEEP) != "true" {
// 目录列表
m.Option(nfs.DIR_TYPE, nfs.DIR)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time size path")
}
// 文件列表
m.Option(nfs.DIR_TYPE, nfs.FILE)
m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs"))
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0), "time size path")
return true
}
return false
}
func _wiki_show(m *ice.Message, cmd, name string, arg ...string) {
m.Cmdy(nfs.CAT, path.Join(m.Conf(cmd, "meta.path"), name))
}
func _wiki_save(m *ice.Message, cmd, name, text string, arg ...string) {
m.Cmd(nfs.SAVE, path.Join(m.Conf(cmd, "meta.path"), name), text)
}
func _wiki_upload(m *ice.Message, cmd string) {
if up := kit.Simple(m.Optionv("_upload")); m.Option(ice.MSG_USERPOD) == "" {
m.Cmdy(web.CACHE, web.WATCH, up[0], path.Join(m.Conf(cmd, "meta.path"), m.Option("path"), up[1]))
} else {
m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_SAVE, path.Join(m.Conf(cmd, "meta.path"), m.Option("path"), up[1]), web.SPIDE_GET, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
}
}
const WIKI = "wiki"
var Index = &ice.Context{Name: WIKI, Help: "文档中心",
Configs: map[string]*ice.Config{
WIKI: {Name: WIKI, Help: "文档中心", Value: kit.Data(
kit.MDB_FIELD, "time,hash,type,name,text",
)},
},
Commands: map[string]*ice.Command{
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
WIKI: {Name: WIKI, Help: "文档中心", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.INSERT, m.Prefix(WIKI), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy(mdb.SELECT, m.Prefix(WIKI), "", mdb.HASH, kit.MDB_HASH, arg)
m.Save()
}},
},
}
func init() { web.Index.Register(Index, &web.Frame{}, SPARK, IMAGE) }
func init() {
web.Index.Register(Index, &web.Frame{},
FEEL, WORD, DATA, DRAW,
SPARK, IMAGE,
)
}

View File

@ -18,6 +18,12 @@ import (
"strings"
)
func _name(m *ice.Message, arg []string) []string {
if len(arg) == 1 {
return []string{"", arg[0]}
}
return arg
}
func _option(m *ice.Message, kind, name, text string, arg ...string) {
m.Option(kit.MDB_TYPE, kind)
m.Option(kit.MDB_NAME, name)
@ -45,13 +51,13 @@ func _title_show(m *ice.Message, kind, text string, arg ...string) {
// 分节标题
title[SECTION]++
m.Option("level", "h3")
m.Option("prefix", fmt.Sprintf("%d.%d", title[CHAPTER], title[SECTION]))
m.Option("prefix", fmt.Sprintf("%d.%d ", title[CHAPTER], title[SECTION]))
case CHAPTER:
// 章节标题
title[CHAPTER]++
title[SECTION] = 0
m.Option("level", "h2")
m.Option("prefix", fmt.Sprintf("%d", title[CHAPTER]))
m.Option("prefix", fmt.Sprintf("%d ", title[CHAPTER]))
default:
// 文章标题
m.Option("level", "h1")
@ -76,8 +82,8 @@ func _brief_show(m *ice.Message, name, text string, arg ...string) {
}
func _refer_show(m *ice.Message, name, text string, arg ...string) {
list := [][]string{}
for _, v := range kit.Split(strings.TrimSpace(text), "\n") {
list = append(list, kit.Split(v, " "))
for _, v := range kit.Split(strings.TrimSpace(text), "\n", "\n") {
list = append(list, kit.Split(v))
}
m.Optionv("list", list)
@ -99,9 +105,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
m.Echo("</div>")
return
}
m.Option("style", kit.Select("", name))
m.Optionv("list", kit.Split(text, "\n"))
m.Optionv("list", kit.Split(text, "\n", "\n"))
_option(m, SPARK, name, text, arg...)
m.Render(ice.RENDER_TEMPLATE, m.Conf(SPARK, "meta.template"))
@ -295,6 +299,25 @@ func _word_show(m *ice.Message, name string, arg ...string) {
m.Optionv(ice.MSG_ALIAS, m.Confv(WORD, "meta.alias"))
m.Cmdy(ssh.SOURCE, path.Join(m.Conf(WORD, "meta.path"), name))
}
func reply(m *ice.Message, cmd string, arg ...string) bool {
m.Option(nfs.DIR_ROOT, m.Conf(cmd, "meta.path"))
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
m.Option("_display", "table")
if m.Option(nfs.DIR_DEEP) != "true" {
// 目录列表
m.Option(nfs.DIR_TYPE, nfs.DIR)
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
}
// 文件列表
m.Option(nfs.DIR_TYPE, nfs.FILE)
m.Option(nfs.DIR_REG, m.Conf(cmd, "meta.regs"))
m.Cmdy(nfs.DIR, kit.Select("./", arg, 0))
return true
}
return false
}
const (
TITLE = "title"
@ -312,9 +335,8 @@ const (
IMAGE = "image"
VIDEO = "video"
BAIDU = "baidu"
OTHER = "other"
SNIPPET = "snippet"
BAIDU = "baidu"
OTHER = "other"
PREMENU = "premenu"
CHAPTER = "chapter"
@ -333,8 +355,7 @@ func init() {
TITLE: {Name: TITLE, Help: "标题", Value: kit.Data("template", title)},
BRIEF: {Name: BRIEF, Help: "摘要", Value: kit.Data("template", brief)},
REFER: {Name: REFER, Help: "参考", Value: kit.Data("template", refer)},
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
"template", spark,
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data("template", spark,
"prompt", kit.Dict("shell", "$ "),
)},
@ -365,9 +386,8 @@ func init() {
ns := strings.Split(cli.NodeName, "-")
arg = append(arg, kit.Select(ns[len(ns)-1], ""))
}
if len(arg) == 1 {
arg = append(arg, arg[0])
}
arg = _name(m, arg)
_title_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
BRIEF: {Name: "brief [name] text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -375,15 +395,12 @@ func init() {
m.Echo(`<br class="story" data-type="brief">`)
return
}
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
arg = _name(m, arg)
_brief_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
REFER: {Name: "refer name `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
REFER: {Name: "refer [name] `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_refer_show(m, arg[0], arg[1], arg[2:]...)
}},
SPARK: {Name: "spark [name] text", Help: "灵感", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -391,58 +408,50 @@ func init() {
m.Echo(`<br class="story" data-type="spark">`)
return
}
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
arg = _name(m, arg)
_spark_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
CHART: {Name: "chart label|chain name text arg...", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 2 {
arg = []string{arg[0], "", arg[1]}
}
_chart_show(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
FIELD: {Name: "field name cmd", Help: "插件", Action: map[string]*ice.Action{
FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
if !m.Warn(!m.Right(arg[1:]), ice.ErrNotAuth, arg[1:]) {
m.Cmdy(arg[1:])
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_field_show(m, strings.ReplaceAll(arg[0], " ", "_"), arg[1], arg[2:]...)
}},
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
arg = _name(m, arg)
_shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
LOCAL: {Name: "local [name] text", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
ORDER: {Name: "order name `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
TABLE: {Name: "table name `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
TABLE: {Name: "table [name] `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "cmd" {
msg := m.Cmd(kit.Split(arg[1])).Table()
arg[1] = msg.Result()
}
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
arg = _name(m, arg)
_table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
IMAGE: {Name: "image name url", Help: "图片", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
IMAGE: {Name: "image [name] url", Help: "图片", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "qrcode" {
buf := bytes.NewBuffer(make([]byte, 0, 4096))
if qr, e := qrcode.New(arg[1], qrcode.Medium); m.Assert(e) {
@ -450,29 +459,22 @@ func init() {
}
arg[1] = "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
}
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
arg = _name(m, arg)
_image_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
m.Render("")
}},
VIDEO: {Name: "video name url", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
VIDEO: {Name: "video [name] url", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_video_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
BAIDU: {Name: "baidu word", Help: "百度", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
BAIDU: {Name: "baidu [name] word", Help: "百度", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_baidu_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
OTHER: {Name: "other word", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {
arg = []string{"", arg[0]}
}
OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},