1
0
forked from x/icebergs

opt WEB_STORY

This commit is contained in:
shaoying 2020-03-11 01:03:27 +08:00
parent 5f36ef2b0f
commit 762c9becb2
9 changed files with 469 additions and 475 deletions

View File

@ -96,7 +96,8 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
}) })
} }
}}, }},
ice.MDB_IMPORT: {Name: "import", Help: "导入数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
ice.MDB_IMPORT: {Name: "import conf key type file", Help: "导入数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
msg := m.Cmd(ice.WEB_STORY, "index", arg[3]) msg := m.Cmd(ice.WEB_STORY, "index", arg[3])
switch arg[2] { switch arg[2] {
@ -107,6 +108,7 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
r := csv.NewReader(buf) r := csv.NewReader(buf)
if msg.Append("file") != "" { if msg.Append("file") != "" {
if f, e := os.Open(msg.Append("file")); m.Assert(e) { if f, e := os.Open(msg.Append("file")); m.Assert(e) {
// 导入文件
r = csv.NewReader(f) r = csv.NewReader(f)
} }
} }
@ -122,8 +124,9 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
for i, k := range head { for i, k := range head {
data[k] = line[i] data[k] = line[i]
} }
m.Grow(arg[0], arg[1], data) // 导入数据
m.Info("import %v", data) n := m.Grow(arg[0], arg[1], data)
m.Log(ice.LOG_INSERT, "index: %d value: %v", n, data)
} }
case kit.MDB_HASH: case kit.MDB_HASH:
@ -131,11 +134,11 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
m.Assert(json.Unmarshal([]byte(msg.Append("text")), &data)) m.Assert(json.Unmarshal([]byte(msg.Append("text")), &data))
for k, v := range data { for k, v := range data {
m.Conf(arg[0], kit.Keys(arg[1], k), v) m.Conf(arg[0], kit.Keys(arg[1], k), v)
m.Info("import %v", v) m.Log(ice.LOG_MODIFY, "%s: %s", k, v)
} }
} }
}}, }},
ice.MDB_EXPORT: {Name: "export conf key list|hash", Help: "导出数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.MDB_EXPORT: {Name: "export conf key type name", Help: "导出数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
name := kit.Select(kit.Select(arg[0], arg[0]+":"+arg[1], arg[1] != ""), arg, 3) name := kit.Select(kit.Select(arg[0], arg[0]+":"+arg[1], arg[1] != ""), arg, 3)
switch arg[2] { switch arg[2] {
@ -170,6 +173,17 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
m.Cmdy(ice.WEB_STORY, "add", "json", name, kit.Formats(m.Confv(arg[0], arg[1]))) m.Cmdy(ice.WEB_STORY, "add", "json", name, kit.Formats(m.Confv(arg[0], arg[1])))
} }
}}, }},
ice.MDB_DELETE: {Name: "delete conf key type", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[2] {
case kit.MDB_DICT:
m.Log(ice.LOG_DELETE, "%s: %s", arg[1], m.Conf(arg[0], arg[1]))
m.Echo("%s", m.Conf(arg[0], arg[1]))
m.Conf(arg[0], arg[1], "")
case kit.MDB_META:
case kit.MDB_LIST:
case kit.MDB_HASH:
}
}},
}, },
} }

View File

@ -137,7 +137,6 @@ func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server
return &Frame{} return &Frame{}
} }
func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server { func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
m.Target().Configs["history"] = &ice.Config{Name: "history", Help: "历史", Value: kit.Data()}
return f return f
} }
func (f *Frame) Start(m *ice.Message, arg ...string) bool { func (f *Frame) Start(m *ice.Message, arg ...string) bool {

View File

@ -5,26 +5,16 @@ import (
) )
var share_template = kit.Dict( var share_template = kit.Dict(
"story.prefix", `<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body>
`, "story.suffix", `</body>`,
"download", `<a href="/code/zsh?cmd=download&arg=%s" target="_blank">%s</a>`,
"share", `<a href="/share/%s" target="_blank">%s</a>`, "share", `<a href="/share/%s" target="_blank">%s</a>`,
"shy/story", `{{.}}`, "qrcode", `<img src="/share/%s/qrcode">`,
"shy/chain", `<!DOCTYPE html>
"simple", `<!DOCTYPE html>
<head> <head>
<meta charset="utf-8"> <meta charset='utf-8'>
<link rel="stylesheet" text="text/css" href="/style.css"> <title>{{.Option "name"}}</title>
</head> </head>
<body> <body>
<fieldset> {{.Option "text"}}
{{.Append "type"}}
{{.Append "text"}}
</fieldset>
</body> </body>
`, `,
) )

File diff suppressed because it is too large Load Diff

View File

@ -168,8 +168,11 @@ const ( // CHAT
const ( // TYPE const ( // TYPE
TYPE_SPACE = "space" TYPE_SPACE = "space"
TYPE_STORY = "story" TYPE_STORY = "story"
TYPE_RIVER = "river" TYPE_RIVER = "river"
TYPE_STORM = "storm" TYPE_STORM = "storm"
TYPE_ACTION = "action"
TYPE_ACTIVE = "active"
TYPE_DRIVE = "drive" TYPE_DRIVE = "drive"
TYPE_SHELL = "shell" TYPE_SHELL = "shell"
@ -185,7 +188,10 @@ const ( // FAVOR
) )
const ( // STORY const ( // STORY
STORY_CATCH = "catch" STORY_CATCH = "catch"
STORY_INDEX = "index"
STORY_TRASH = "trash"
STORY_WATCH = "watch" STORY_WATCH = "watch"
STORY_STATUS = "status" STORY_STATUS = "status"
STORY_COMMIT = "commit" STORY_COMMIT = "commit"
STORY_BRANCH = "branch" STORY_BRANCH = "branch"

View File

@ -10,21 +10,13 @@ import (
var Index = &ice.Context{Name: "chrome", Help: "浏览器", var Index = &ice.Context{Name: "chrome", Help: "浏览器",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"chrome": {Name: "chrome", Help: "chrome", Value: kit.Data(kit.MDB_SHORT, "name")}, "chrome": {Name: "chrome", Help: "chrome", Value: kit.Data(kit.MDB_SHORT, "name", "history", "url.history")},
"history": {Name: "history", Help: "history", Value: kit.Data(kit.MDB_SHORT, "name")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("history")
}},
"/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] { switch arg[0] {
case "history": case "history":
m.Cmdy("history", arg[1:]) m.Cmdy(ice.WEB_FAVOR, m.Conf("chrome", "meta.history"), "spide", arg[3], arg[2])
} }
}}, }},
"chrome": {Name: "chrome", Help: "浏览器", List: kit.List( "chrome": {Name: "chrome", Help: "浏览器", List: kit.List(
@ -70,18 +62,6 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器",
// 下发命令 // 下发命令
m.Cmdy(ice.WEB_SPACE, arg[0], "cookie", arg[1:]) m.Cmdy(ice.WEB_SPACE, arg[0], "cookie", arg[1:])
}}, }},
"history": {Name: "history id url title", Help: "历史", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 {
// 查看记录
m.Grows("history", nil, "", "", func(index int, value map[string]interface{}) {
m.Push("", value)
})
m.Sort("id", "int_r")
return
}
// 添加记录
m.Grow("history", nil, kit.Dict("hid", arg[0], "url", arg[1], "title", arg[2]))
}},
"bookmark": {Name: "bookmark", Help: "书签", List: kit.List( "bookmark": {Name: "bookmark", Help: "书签", List: kit.List(
kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "text", "name", "name", "action", "auto",
kit.MDB_INPUT, "text", "name", "id", "action", "auto", kit.MDB_INPUT, "text", "name", "id", "action", "auto",

View File

@ -13,7 +13,7 @@ import (
var Index = &ice.Context{Name: "vim", Help: "编辑器", var Index = &ice.Context{Name: "vim", Help: "编辑器",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"vim": {Name: "vim", Help: "编辑器", Value: kit.Data(kit.MDB_SHORT, "name")}, "vim": {Name: "vim", Help: "编辑器", Value: kit.Data(kit.MDB_SHORT, "name", "history", "vim.history")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -47,7 +47,7 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] { switch arg[0] {
case "read", "write", "exec", "insert": case "read", "write", "exec", "insert":
m.Cmd(ice.WEB_FAVOR, "vim.history", "vimrc", arg[0], kit.Select(m.Option("arg"), m.Option("sub")), m.Cmd(ice.WEB_FAVOR, m.Conf("vim", "meta.history"), "vimrc", arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")) "sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
default: default:

View File

@ -70,6 +70,7 @@ ShyLogin() {
echo "${ctx_welcome}" echo "${ctx_welcome}"
echo "${ctx_dev}" echo "${ctx_dev}"
echo "sid: ${ctx_sid}" echo "sid: ${ctx_sid}"
echo "begin: ${ctx_begin}"
} }
ShyLogout() { ShyLogout() {
echo ${ctx_goodbye} && [ "$ctx_sid" != "" ] && ShyPost logout echo ${ctx_goodbye} && [ "$ctx_sid" != "" ] && ShyPost logout
@ -94,6 +95,13 @@ ShySend() {
# 同步数据 # 同步数据
ShySync() { ShySync() {
case "$1" in case "$1" in
"base")
ShySync df &>/dev/null
ShySync ps &>/dev/null
ShySync env &>/dev/null
ShySync free &>/dev/null
ShySync history
;;
"history") "history")
ctx_end=`history|tail -n1|awk '{print $1}'` ctx_end=`history|tail -n1|awk '{print $1}'`
ctx_begin=${ctx_begin:=$ctx_end} ctx_begin=${ctx_begin:=$ctx_end}
@ -108,18 +116,6 @@ ShySync() {
*) ShySend "$@" *) ShySend "$@"
esac esac
} }
ShySyncs() {
case "$1" in
"base")
ShySync df &>/dev/null
ShySync ps &>/dev/null
ShySync env &>/dev/null
ShySync free &>/dev/null
ShySync history
;;
*)
esac
}
ShyInput() { ShyInput() {
if [ "$1" = "line" ] ; then if [ "$1" = "line" ] ; then
READLINE_LINE=`ShyPost input "$1" line "$READLINE_LINE" point "$READLINE_POINT"` READLINE_LINE=`ShyPost input "$1" line "$READLINE_LINE" point "$READLINE_POINT"`
@ -166,8 +162,8 @@ ShyInit() {
elif bindkey &>/dev/null; then elif bindkey &>/dev/null; then
# zsh # zsh
bindkey -s '\C-G\C-R' 'ShySyncs base\n' bindkey -s '\C-G\C-R' 'ShySync base\n'
bindkey -s '\C-G\C-G' 'ShySyncs history\n' bindkey -s '\C-G\C-G' 'ShySync history\n'
setopt nosharehistory setopt nosharehistory
fi fi

View File

@ -14,7 +14,7 @@ import (
var Index = &ice.Context{Name: "zsh", Help: "命令行", var Index = &ice.Context{Name: "zsh", Help: "命令行",
Caches: map[string]*ice.Cache{}, Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"zsh": {Name: "zsh", Help: "命令行", Value: kit.Data(kit.MDB_SHORT, "name")}, "zsh": {Name: "zsh", Help: "命令行", Value: kit.Data(kit.MDB_SHORT, "name", "history", "zsh.history")},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
@ -205,7 +205,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
}}, }},
"/history": {Name: "/history", Help: "历史", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "/history": {Name: "/history", Help: "历史", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
vs := strings.SplitN(strings.TrimSpace(arg[0]), " ", 2) vs := strings.SplitN(strings.TrimSpace(arg[0]), " ", 2)
m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR, "zsh.history", ice.TYPE_SHELL, vs[0], kit.Select("", vs, 1), m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 1),
"sid", m.Option("sid"), "pwd", m.Option("pwd")) "sid", m.Option("sid"), "pwd", m.Option("pwd"))
}}, }},
}, },