mirror of
https://shylinux.com/x/icebergs
synced 2025-04-27 01:48:27 +08:00
add json
This commit is contained in:
parent
00c4286e1d
commit
7e40569cba
@ -12,6 +12,11 @@ import (
|
|||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func _cmd_render(m *ice.Message, cmd string, args ...interface{}) {
|
||||||
|
list := []interface{}{kit.Dict("index", cmd, "args", args)}
|
||||||
|
m.RenderResult(kit.Format(m.Conf(CMD, kit.Keym(kit.MDB_TEMPLATE)), kit.Format(list)))
|
||||||
|
}
|
||||||
|
|
||||||
const CMD = "cmd"
|
const CMD = "cmd"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -36,14 +41,24 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch p := path.Join(m.Conf(CMD, kit.META_PATH), path.Join(arg...)); kit.Ext(p) {
|
switch p := path.Join(m.Conf(CMD, kit.META_PATH), path.Join(arg...)); kit.Ext(p) {
|
||||||
|
case "svg":
|
||||||
|
_cmd_render(m, "web.wiki.draw", path.Dir(p)+"/", path.Base(p))
|
||||||
|
case "json":
|
||||||
|
_cmd_render(m, "web.wiki.json", p)
|
||||||
case "shy":
|
case "shy":
|
||||||
list := []interface{}{kit.Dict("index", "web.wiki.word", "args", []interface{}{p})}
|
_cmd_render(m, "web.wiki.word", p)
|
||||||
m.RenderResult(kit.Format(m.Conf(CMD, kit.Keym(kit.MDB_TEMPLATE)), kit.Format(list)))
|
case "csv":
|
||||||
|
_cmd_render(m, "web.wiki.data", p)
|
||||||
|
case "go", "mod", "sum":
|
||||||
|
_cmd_render(m, "web.code.inner", path.Dir(p)+"/", path.Base(p))
|
||||||
default:
|
default:
|
||||||
m.RenderDownload(p)
|
m.RenderDownload(p)
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
CMD: {Name: "cmd path auto up", Help: "命令", Action: map[string]*ice.Action{
|
CMD: {Name: "cmd path auto up home", Help: "命令", Action: map[string]*ice.Action{
|
||||||
|
"home": {Name: "home", Help: "根目录", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.ProcessLocation("/chat/cmd/")
|
||||||
|
}},
|
||||||
"up": {Name: "up", Help: "上一级", Hand: func(m *ice.Message, arg ...string) {
|
"up": {Name: "up", Help: "上一级", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if strings.TrimPrefix(m.R.URL.Path, "/cmd") == "/" {
|
if strings.TrimPrefix(m.R.URL.Path, "/cmd") == "/" {
|
||||||
m.Cmdy(CMD)
|
m.Cmdy(CMD)
|
||||||
|
32
core/wiki/json.go
Normal file
32
core/wiki/json.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package wiki
|
||||||
|
|
||||||
|
import (
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/nfs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
)
|
||||||
|
|
||||||
|
const JSON = "json"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Index.Merge(&ice.Context{
|
||||||
|
Configs: map[string]*ice.Config{
|
||||||
|
JSON: {Name: JSON, Help: "数据表格", Value: kit.Data(
|
||||||
|
kit.MDB_PATH, ice.USR_LOCAL_EXPORT, kit.MDB_REGEXP, ".*\\.csv",
|
||||||
|
)},
|
||||||
|
},
|
||||||
|
Commands: map[string]*ice.Command{
|
||||||
|
JSON: {Name: "json path auto", Help: "数据结构", Meta: kit.Dict(
|
||||||
|
ice.Display("/plugin/local/wiki/json.js"),
|
||||||
|
), Action: map[string]*ice.Action{
|
||||||
|
nfs.SAVE: {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_wiki_save(m, JSON, arg[0], arg[1])
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if !_wiki_list(m, JSON, kit.Select("./", arg, 0)) {
|
||||||
|
m.Cmdy(nfs.CAT, arg[0])
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user