forked from x/icebergs
opt share
This commit is contained in:
parent
7c53a6df44
commit
b25ca6233f
@ -13,19 +13,39 @@ import (
|
|||||||
type Frame struct {
|
type Frame struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
GETPORT = "getport"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _tcp_port(m *ice.Message) {
|
||||||
|
current := kit.Int(m.Conf(GETPORT, "meta.current"))
|
||||||
|
end := kit.Int(m.Conf(GETPORT, "meta.end"))
|
||||||
|
if current >= end {
|
||||||
|
current = kit.Int(m.Conf(GETPORT, "meta.begin"))
|
||||||
|
}
|
||||||
|
for i := current; i < end; i++ {
|
||||||
|
if m.Cmd(ice.CLI_SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append("code") != "0" {
|
||||||
|
m.Conf(GETPORT, "meta.current", i)
|
||||||
|
m.Log_CREATE(GETPORT, i)
|
||||||
|
m.Echo("%d", i)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"getport": &ice.Config{Name: "getport", Help: "getport", Value: kit.Data(
|
GETPORT: &ice.Config{Name: "getport", Help: "分配端口", Value: kit.Data(
|
||||||
"begin", 10000, "end", 20000,
|
"begin", 10000, "current", 10000, "end", 20000,
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
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) {
|
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
||||||
m.Load()
|
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(GETPORT) }},
|
||||||
}},
|
|
||||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
GETPORT: {Name: "getport", Help: "分配端口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Save("getport")
|
_tcp_port(m)
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"ip": {Name: "ifconfig [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"ip": {Name: "ifconfig [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
@ -35,20 +55,6 @@ var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"getport": {Name: "getport", Help: "分配端口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
begin := kit.Int(m.Conf("getport", "meta.begin"))
|
|
||||||
end := kit.Int(m.Conf("getport", "meta.end"))
|
|
||||||
if begin >= end {
|
|
||||||
begin = 10000
|
|
||||||
}
|
|
||||||
for i := begin; i < end; i++ {
|
|
||||||
if m.Cmd(ice.CLI_SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append("code") != "0" {
|
|
||||||
m.Conf("getport", "meta.begin", i+1)
|
|
||||||
m.Echo("%d", i)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
"netstat": {Name: "netstat [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"netstat": {Name: "netstat [name]", Help: "网络配置", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmdy(ice.CLI_SYSTEM, "netstat", "-lanp")
|
m.Cmdy(ice.CLI_SYSTEM, "netstat", "-lanp")
|
||||||
}},
|
}},
|
||||||
|
@ -21,14 +21,15 @@ func _cache_list(m *ice.Message) {
|
|||||||
func _cache_save(m *ice.Message, method, kind, name, text string, arg ...string) {
|
func _cache_save(m *ice.Message, method, kind, name, text string, arg ...string) {
|
||||||
size := kit.Int(kit.Select(kit.Format(len(text)), arg, 1))
|
size := kit.Int(kit.Select(kit.Format(len(text)), arg, 1))
|
||||||
if method == "add" && size > 512 {
|
if method == "add" && size > 512 {
|
||||||
// 创建文件
|
|
||||||
file := kit.Hashs(text)
|
file := kit.Hashs(text)
|
||||||
|
|
||||||
|
// 创建文件
|
||||||
if o, p, e := kit.Create(path.Join(m.Conf(CACHE, "meta.path"), file[:2], file)); m.Assert(e) {
|
if o, p, e := kit.Create(path.Join(m.Conf(CACHE, "meta.path"), file[:2], file)); m.Assert(e) {
|
||||||
defer o.Close()
|
defer o.Close()
|
||||||
|
|
||||||
// 导入数据
|
// 导入数据
|
||||||
if n, e := o.WriteString(text); m.Assert(e) {
|
if n, e := o.WriteString(text); m.Assert(e) {
|
||||||
m.Log(ice.LOG_IMPORT, "%s: %s", kit.FmtSize(int64(n)), p)
|
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_SIZE, kit.FmtSize(int64(n)))
|
||||||
text, arg = p, kit.Simple(p, n)
|
text, arg = p, kit.Simple(p, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ func _cache_save(m *ice.Message, method, kind, name, text string, arg ...string)
|
|||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
kit.MDB_FILE, kit.Select("", arg, 0), kit.MDB_SIZE, size,
|
kit.MDB_FILE, kit.Select("", arg, 0), kit.MDB_SIZE, size,
|
||||||
))
|
))
|
||||||
m.Log(ice.LOG_CREATE, "cache: %s %s: %s", h, kind, name)
|
m.Log_CREATE(CACHE, h, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
||||||
|
|
||||||
// 添加记录
|
// 添加记录
|
||||||
m.Grow(CACHE, nil, kit.Dict(
|
m.Grow(CACHE, nil, kit.Dict(
|
||||||
@ -84,11 +85,11 @@ func _cache_catch(m *ice.Message, arg ...string) []string {
|
|||||||
h := kit.Hashs(f)
|
h := kit.Hashs(f)
|
||||||
if o, p, e := kit.Create(path.Join(m.Conf(CACHE, "meta.path"), h[:2], h)); m.Assert(e) {
|
if o, p, e := kit.Create(path.Join(m.Conf(CACHE, "meta.path"), h[:2], h)); m.Assert(e) {
|
||||||
defer o.Close()
|
defer o.Close()
|
||||||
f.Seek(0, os.SEEK_SET)
|
|
||||||
|
|
||||||
// 导入数据
|
// 导入数据
|
||||||
|
f.Seek(0, os.SEEK_SET)
|
||||||
if n, e := io.Copy(o, f); m.Assert(e) {
|
if n, e := io.Copy(o, f); m.Assert(e) {
|
||||||
m.Log(ice.LOG_IMPORT, "%s: %s", kit.FmtSize(n), p)
|
m.Log_IMPORT(kit.MDB_FILE, kit.FmtSize(n), kit.MDB_SIZE, p)
|
||||||
arg = kit.Simple(arg[0], arg[1], arg[2], p, p, n)
|
arg = kit.Simple(arg[0], arg[1], arg[2], p, p, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,11 +152,11 @@ func init() {
|
|||||||
case "catch":
|
case "catch":
|
||||||
arg = _cache_catch(m, arg...)
|
arg = _cache_catch(m, arg...)
|
||||||
fallthrough
|
fallthrough
|
||||||
case "upload", "download":
|
case "download", "upload":
|
||||||
if m.R != nil {
|
if r, ok := m.Optionv("response").(*http.Response); ok {
|
||||||
arg = _cache_upload(m, arg...)
|
|
||||||
} else if r, ok := m.Optionv("response").(*http.Response); ok {
|
|
||||||
arg = _cache_download(m, r, arg...)
|
arg = _cache_download(m, r, arg...)
|
||||||
|
} else if m.R != nil {
|
||||||
|
arg = _cache_upload(m, arg...)
|
||||||
}
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
case "add":
|
case "add":
|
||||||
|
@ -1,77 +1,226 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
|
"encoding/csv"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
EXPORT = "usr/export/web.favor/favor.csv"
|
||||||
|
)
|
||||||
|
|
||||||
var FAVOR = ice.Name("favor", Index)
|
var FAVOR = ice.Name("favor", Index)
|
||||||
|
|
||||||
func _favor_list(m *ice.Message, favor, id string, fields ...string) {
|
func _favor_list(m *ice.Message, zone, id string, fields ...string) {
|
||||||
if favor == "" {
|
m.Richs(FAVOR, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
|
||||||
m.Richs(FAVOR, nil, "*", func(key string, value map[string]interface{}) {
|
if val = val[kit.MDB_META].(map[string]interface{}); zone == "" {
|
||||||
m.Push(key, value["meta"], []string{"time", "count"})
|
m.Push("", val, []string{
|
||||||
m.Push("render", kit.Select("spide", kit.Value(value, "meta.render")))
|
// 汇总信息
|
||||||
m.Push(FAVOR, kit.Value(value, "meta.name"))
|
kit.MDB_TIME, kit.MDB_COUNT, kit.MDB_ZONE,
|
||||||
})
|
|
||||||
m.Sort(FAVOR)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
if id == "" {
|
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("", value, fields)
|
|
||||||
})
|
})
|
||||||
|
m.Sort(kit.MDB_ZONE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if zone = kit.Format(kit.Value(val, kit.MDB_ZONE)); id == "" {
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", id, func(index int, value map[string]interface{}) {
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
// 列表信息
|
||||||
|
m.Push(zone, value, fields, val)
|
||||||
|
})
|
||||||
|
m.Sort(kit.MDB_ID, "int_r")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
// 详细信息
|
||||||
m.Push("detail", value)
|
m.Push("detail", value)
|
||||||
m.Optionv("value", value)
|
m.Optionv("value", value)
|
||||||
m.Push("key", "render")
|
m.Push(kit.MDB_KEY, kit.MDB_RENDER)
|
||||||
m.Push("value", m.Cmdx(m.Conf(ice.WEB_FAVOR, kit.Keys("meta.render", value["type"]))))
|
m.Push(kit.MDB_VALUE, m.Cmdx(m.Conf(ice.WEB_FAVOR, kit.Keys(kit.MDB_META, kit.MDB_RENDER, value[kit.MDB_TYPE]))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _favor_create(m *ice.Message, name string) string {
|
func _favor_show(m *ice.Message, zone, id string, arg ...string) {
|
||||||
favor := m.Rich(ice.WEB_FAVOR, nil, kit.Data(kit.MDB_NAME, name))
|
|
||||||
m.Log_CREATE("favor", favor, "name", favor)
|
|
||||||
return favor
|
|
||||||
}
|
}
|
||||||
func _favor_insert(m *ice.Message, favor, kind, name, text string, extra ...string) {
|
func _favor_sync(m *ice.Message, zone, route, favor string, arg ...string) {
|
||||||
index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict(
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
val = val[kit.MDB_META].(map[string]interface{})
|
||||||
"extra", kit.Dict(extra),
|
remote := kit.Keys("remote", route, favor)
|
||||||
))
|
count := kit.Int(kit.Value(val, kit.Keys(kit.MDB_COUNT)))
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
kit.Value(value, "meta.time", m.Time())
|
pull := kit.Int(kit.Value(val, kit.Keys(remote, kit.MDB_PULL)))
|
||||||
|
m.Cmd(ice.WEB_SPIDE, route, "msg", "/favor/pull", FAVOR, favor, "begin", pull+1).Table(func(index int, value map[string]string, head []string) {
|
||||||
|
_favor_insert(m, favor, value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TEXT], value[kit.MDB_EXTRA])
|
||||||
|
pull = kit.Int(value[kit.MDB_ID])
|
||||||
|
})
|
||||||
|
|
||||||
|
m.Option("cache.limit", count-kit.Int(kit.Value(val, kit.Keys(remote, kit.MDB_PUSH))))
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
m.Cmd(ice.WEB_SPIDE, route, "msg", "/favor/push", FAVOR, favor,
|
||||||
|
kit.MDB_TYPE, value[kit.MDB_TYPE], kit.MDB_NAME, value[kit.MDB_NAME], kit.MDB_TEXT, value[kit.MDB_TEXT],
|
||||||
|
kit.MDB_EXTRA, kit.Format(value[kit.MDB_EXTRA]),
|
||||||
|
)
|
||||||
|
pull++
|
||||||
|
})
|
||||||
|
kit.Value(val, kit.Keys(remote, kit.MDB_PULL), pull)
|
||||||
|
kit.Value(val, kit.Keys(remote, kit.MDB_PUSH), kit.Value(val, kit.MDB_COUNT))
|
||||||
|
m.Echo("%d", kit.Value(val, kit.MDB_COUNT))
|
||||||
|
return
|
||||||
})
|
})
|
||||||
m.Log_INSERT("favor", favor, "index", index, "name", name, "text", text)
|
|
||||||
m.Echo("%d", index)
|
|
||||||
}
|
}
|
||||||
func _favor_modify(m *ice.Message, favor, id, pro, set, old string) {
|
func _favor_pull(m *ice.Message, zone string) {
|
||||||
m.Richs(FAVOR, nil, favor, func(key string, val map[string]interface{}) {
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
|
m.Option("cache.limit", kit.Int(kit.Value(val, "meta.count"))+1-kit.Int(m.Option("begin")))
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
m.Log_EXPORT(kit.MDB_VALUE, value)
|
||||||
|
m.Push(key, value, []string{kit.MDB_ID, kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT})
|
||||||
|
m.Push(kit.MDB_EXTRA, kit.Format(value[kit.MDB_EXTRA]))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func _favor_push(m *ice.Message, zone, id string, arg ...string) {
|
||||||
|
}
|
||||||
|
func _favor_proxy(m *ice.Message, zone, id string, arg ...string) {
|
||||||
|
if p := kit.Select(m.Conf(FAVOR, kit.Keys(kit.MDB_META, kit.MDB_PROXY)), m.Option("you")); p != "" {
|
||||||
|
m.Option("you", "")
|
||||||
|
// 分发数据
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
m.Cmdy(ice.WEB_PROXY, p, ice.WEB_FAVOR, zone, kit.MDB_TYPE, value[kit.MDB_TYPE],
|
||||||
|
kit.MDB_NAME, value[kit.MDB_NAME], kit.MDB_TEXT, value[kit.MDB_TEXT],
|
||||||
|
kit.Format(value[kit.MDB_EXTRA]))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func _favor_share(m *ice.Message, zone, id string, arg ...string) {
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
m.Cmdy(ice.WEB_SHARE, value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TYPE], kit.Format(value[kit.MDB_EXTRA]))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func _favor_commit(m *ice.Message, zone, id string, arg ...string) {
|
||||||
|
m.Echo("list: ")
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
|
m.Cmdy(ice.WEB_STORY, "add", value[kit.MDB_TYPE], value[kit.MDB_NAME], value[kit.MDB_TEXT])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func _favor_modify(m *ice.Message, zone, id, pro, set, old string) {
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
switch pro {
|
switch pro {
|
||||||
case FAVOR, kit.MDB_ID, kit.MDB_TIME:
|
case kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME:
|
||||||
m.Warn(true, "deny modify %v", pro)
|
m.Warn(true, "deny modify %v", pro)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
|
||||||
// 修改信息
|
// 修改信息
|
||||||
m.Log_MODIFY(FAVOR, favor, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set, "old", old)
|
m.Log_MODIFY(kit.MDB_META, FAVOR, kit.MDB_ZONE, zone,
|
||||||
|
kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_VALUE, set, "old", kit.Value(value, pro))
|
||||||
kit.Value(value, pro, set)
|
kit.Value(value, pro, set)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
func _favor_insert(m *ice.Message, zone, kind, name, text string, arg ...string) {
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
|
kit.Value(val, kit.Keys(kit.MDB_META, kit.MDB_TIME), m.Time())
|
||||||
|
|
||||||
func FavorInsert(m *ice.Message, favor, kind, name, text string, extra ...string) {
|
id := m.Grow(FAVOR, kit.Keys(kit.MDB_HASH, key), kit.Dict(
|
||||||
_favor_insert(m, favor, kind, name, text, extra...)
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
|
kit.MDB_EXTRA, kit.Dict(arg),
|
||||||
|
))
|
||||||
|
m.Log_INSERT(kit.MDB_META, FAVOR, kit.MDB_ZONE, zone,
|
||||||
|
kit.MDB_ID, id, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
||||||
|
m.Echo("%d", id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func _favor_create(m *ice.Message, zone string, arg ...string) {
|
||||||
|
if m.Richs(FAVOR, nil, zone, nil) == nil {
|
||||||
|
m.Rich(FAVOR, nil, kit.Data(kit.MDB_ZONE, zone, arg))
|
||||||
|
m.Log_CREATE(kit.MDB_META, FAVOR, kit.MDB_ZONE, zone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func _favor_import(m *ice.Message, file string) {
|
||||||
|
f, e := os.Open(file)
|
||||||
|
m.Assert(e)
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
r := csv.NewReader(f)
|
||||||
|
heads, _ := r.Read()
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
for {
|
||||||
|
lines, e := r.Read()
|
||||||
|
if e != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
zone := ""
|
||||||
|
data := kit.Dict()
|
||||||
|
for i, k := range heads {
|
||||||
|
switch k {
|
||||||
|
case kit.MDB_ZONE:
|
||||||
|
zone = lines[i]
|
||||||
|
case kit.MDB_ID:
|
||||||
|
continue
|
||||||
|
case kit.MDB_EXTRA:
|
||||||
|
kit.Value(data, k, kit.UnMarshal(lines[i]))
|
||||||
|
default:
|
||||||
|
kit.Value(data, k, lines[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_favor_create(m, zone)
|
||||||
|
m.Richs(FAVOR, nil, zone, func(key string, value map[string]interface{}) {
|
||||||
|
id := m.Grow(FAVOR, kit.Keys(kit.MDB_HASH, key), data)
|
||||||
|
m.Log_INSERT(kit.MDB_META, FAVOR, kit.MDB_ZONE, zone, kit.MDB_ID, id, kit.MDB_TYPE, data[kit.MDB_TYPE], kit.MDB_NAME, data[kit.MDB_NAME])
|
||||||
|
count++
|
||||||
|
})
|
||||||
|
}
|
||||||
|
m.Log_IMPORT(kit.MDB_FILE, file, kit.MDB_COUNT, count)
|
||||||
|
}
|
||||||
|
func _favor_export(m *ice.Message, file string) {
|
||||||
|
f, p, e := kit.Create(file)
|
||||||
|
m.Assert(e)
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
w := csv.NewWriter(f)
|
||||||
|
defer w.Flush()
|
||||||
|
|
||||||
|
m.Assert(w.Write([]string{
|
||||||
|
kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME,
|
||||||
|
kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT,
|
||||||
|
kit.MDB_EXTRA,
|
||||||
|
}))
|
||||||
|
|
||||||
|
count := 0
|
||||||
|
m.Option("cache.limit", -2)
|
||||||
|
m.Richs(FAVOR, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||||
|
val = val[kit.MDB_META].(map[string]interface{})
|
||||||
|
m.Grows(FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
|
m.Assert(w.Write(kit.Simple(
|
||||||
|
kit.Format(val[kit.MDB_ZONE]),
|
||||||
|
kit.Format(value[kit.MDB_ID]),
|
||||||
|
kit.Format(value[kit.MDB_TIME]),
|
||||||
|
kit.Format(value[kit.MDB_TYPE]),
|
||||||
|
kit.Format(value[kit.MDB_NAME]),
|
||||||
|
kit.Format(value[kit.MDB_TEXT]),
|
||||||
|
kit.Format(value[kit.MDB_EXTRA]),
|
||||||
|
)))
|
||||||
|
count++
|
||||||
|
})
|
||||||
|
})
|
||||||
|
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
func FavorInsert(m *ice.Message, zone, kind, name, text string, extra ...string) {
|
||||||
|
_favor_create(m, zone)
|
||||||
|
_favor_insert(m, zone, kind, name, text, extra...)
|
||||||
}
|
}
|
||||||
func FavorList(m *ice.Message, favor, id string, fields ...string) {
|
func FavorList(m *ice.Message, favor, id string, fields ...string) {
|
||||||
_favor_list(m, favor, id, fields...)
|
_favor_list(m, favor, id, fields...)
|
||||||
@ -80,180 +229,66 @@ func FavorList(m *ice.Message, favor, id string, fields ...string) {
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data(
|
FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data(
|
||||||
kit.MDB_SHORT, kit.MDB_NAME, "template", favor_template,
|
kit.MDB_SHORT, kit.MDB_ZONE, "template", favor_template, "proxy", "",
|
||||||
"proxy", "",
|
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.WEB_FAVOR: {Name: "favor favor=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict(
|
FAVOR: {Name: "favor zone=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict(
|
||||||
"exports", []string{"hot", "favor"}, "detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
"detail", []string{"编辑", "收藏", "收录", "导出", "删除"},
|
||||||
), Action: map[string]*ice.Action{
|
), Action: map[string]*ice.Action{
|
||||||
|
kit.MDB_EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_export(m, kit.Select(EXPORT, arg, 0))
|
||||||
|
}},
|
||||||
|
kit.MDB_IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_import(m, kit.Select(EXPORT, arg, 0))
|
||||||
|
}},
|
||||||
|
kit.MDB_CREATE: {Name: "create zone", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_create(m, arg[0])
|
||||||
|
}},
|
||||||
|
kit.MDB_INSERT: {Name: "insert zone type name text", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_insert(m, arg[0], arg[1], arg[2], kit.Select("", arg, 3))
|
||||||
|
}},
|
||||||
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_favor_modify(m, m.Option(FAVOR), m.Option(kit.MDB_ID), arg[0], arg[1], kit.Select("", arg, 2))
|
_favor_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], kit.Select("", arg, 2))
|
||||||
|
}},
|
||||||
|
kit.MDB_COMMIT: {Name: "commit arg...", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_commit(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||||
|
}},
|
||||||
|
kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_share(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||||
|
}},
|
||||||
|
kit.MDB_PROXY: {Name: "proxy arg...", Help: "代理", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_proxy(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||||
|
}},
|
||||||
|
kit.MDB_SYNC: {Name: "sync route favor", Help: "同步", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_sync(m, m.Option(kit.MDB_ZONE), arg[0], arg[1], arg[2:]...)
|
||||||
|
}},
|
||||||
|
kit.MDB_SHOW: {Name: "show arg...", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
_favor_show(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg...)
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 1 && arg[0] == "action" {
|
|
||||||
favor, id := m.Option("favor"), m.Option("id")
|
|
||||||
switch arg[2] {
|
|
||||||
case "favor":
|
|
||||||
favor = arg[3]
|
|
||||||
case "id":
|
|
||||||
id = arg[3]
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg[1] {
|
|
||||||
case "commit", "收录":
|
|
||||||
m.Echo("list: ")
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "id", id, func(index int, value map[string]interface{}) {
|
|
||||||
m.Cmdy(ice.WEB_STORY, "add", value["type"], value["name"], value["text"])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
case "export", "导出":
|
|
||||||
m.Echo("list: ")
|
|
||||||
if favor == "" {
|
|
||||||
m.Cmdy(ice.MDB_EXPORT, ice.WEB_FAVOR, kit.MDB_HASH, kit.MDB_HASH, "favor")
|
|
||||||
} else {
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
m.Cmdy(ice.MDB_EXPORT, ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_LIST, favor)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case "import", "导入":
|
|
||||||
if favor == "" {
|
|
||||||
m.Cmdy(ice.MDB_IMPORT, ice.WEB_FAVOR, kit.MDB_HASH, kit.MDB_HASH, "favor")
|
|
||||||
} else {
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) {
|
|
||||||
m.Cmdy(ice.MDB_IMPORT, ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), kit.MDB_LIST, favor)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 0 {
|
|
||||||
_favor_list(m, "", "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg[0] {
|
|
||||||
case "save":
|
|
||||||
f, p, e := kit.Create(arg[1])
|
|
||||||
m.Assert(e)
|
|
||||||
defer f.Close()
|
|
||||||
w := csv.NewWriter(f)
|
|
||||||
|
|
||||||
w.Write([]string{"favor", "type", "name", "text", "extra"})
|
|
||||||
|
|
||||||
n := 0
|
|
||||||
m.Option("cache.offend", 0)
|
|
||||||
m.Option("cache.limit", -2)
|
|
||||||
for _, favor := range arg[2:] {
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, val map[string]interface{}) {
|
|
||||||
if m.Conf(ice.WEB_FAVOR, kit.Keys("meta.skip", kit.Value(val, "meta.name"))) == "true" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
w.Write(kit.Simple(kit.Value(val, "meta.name"), value["type"], value["name"], value["text"], kit.Format(value["extra"])))
|
|
||||||
n++
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
w.Flush()
|
|
||||||
m.Echo("%s: %d", p, n)
|
|
||||||
return
|
|
||||||
|
|
||||||
case "load":
|
|
||||||
f, e := os.Open(arg[1])
|
|
||||||
m.Assert(e)
|
|
||||||
defer f.Close()
|
|
||||||
r := csv.NewReader(f)
|
|
||||||
|
|
||||||
head, e := r.Read()
|
|
||||||
m.Assert(e)
|
|
||||||
m.Info("head: %v", head)
|
|
||||||
|
|
||||||
for {
|
|
||||||
line, e := r.Read()
|
|
||||||
if e != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
m.Cmd(ice.WEB_FAVOR, line)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
|
|
||||||
case "sync":
|
|
||||||
m.Richs(ice.WEB_FAVOR, nil, arg[1], func(key string, val map[string]interface{}) {
|
|
||||||
remote := kit.Keys("meta.remote", arg[2], arg[3])
|
|
||||||
count := kit.Int(kit.Value(val, kit.Keys("meta.count")))
|
|
||||||
|
|
||||||
pull := kit.Int(kit.Value(val, kit.Keys(remote, "pull")))
|
|
||||||
m.Cmd(ice.WEB_SPIDE, arg[2], "msg", "/favor/pull", "favor", arg[3], "begin", pull+1).Table(func(index int, value map[string]string, head []string) {
|
|
||||||
m.Cmd(ice.WEB_FAVOR, arg[1], value["type"], value["name"], value["text"], value["extra"])
|
|
||||||
pull = kit.Int(value["id"])
|
|
||||||
})
|
|
||||||
|
|
||||||
m.Option("cache.limit", count-kit.Int(kit.Value(val, kit.Keys(remote, "push"))))
|
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
|
||||||
m.Cmd(ice.WEB_SPIDE, arg[2], "msg", "/favor/push", "favor", arg[3],
|
|
||||||
"type", value["type"], "name", value["name"], "text", value["text"],
|
|
||||||
"extra", kit.Format(value["extra"]),
|
|
||||||
)
|
|
||||||
pull++
|
|
||||||
})
|
|
||||||
kit.Value(val, kit.Keys(remote, "pull"), pull)
|
|
||||||
kit.Value(val, kit.Keys(remote, "push"), kit.Value(val, "meta.count"))
|
|
||||||
m.Echo("%d", kit.Value(val, "meta.count"))
|
|
||||||
return
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fields := []string{kit.MDB_TIME, kit.MDB_ID, kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}
|
fields := []string{kit.MDB_TIME, kit.MDB_ID, kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}
|
||||||
if len(arg) > 1 && arg[1] == "extra" {
|
if len(arg) > 1 && arg[1] == "extra" {
|
||||||
fields, arg = append(fields, arg[2:]...), arg[:1]
|
fields, arg = append(fields, arg[2:]...), arg[:1]
|
||||||
}
|
}
|
||||||
m.Option("favor", arg[0])
|
|
||||||
if len(arg) < 3 {
|
if len(arg) < 3 {
|
||||||
// 收藏列表
|
_favor_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1), fields...)
|
||||||
_favor_list(m, arg[0], kit.Select("", arg, 1), fields...)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
favor := ""
|
_favor_create(m, arg[0])
|
||||||
if m.Richs(ice.WEB_FAVOR, nil, arg[0], func(key string, value map[string]interface{}) {
|
_favor_insert(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
|
||||||
favor = key
|
|
||||||
}) == nil {
|
|
||||||
// 创建收藏
|
|
||||||
favor = _favor_create(m, arg[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 3 {
|
|
||||||
arg = append(arg, "")
|
|
||||||
}
|
|
||||||
_favor_insert(m, favor, arg[1], arg[2], arg[3], arg[4:]...)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
// 分发数据
|
|
||||||
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" {
|
|
||||||
m.Option("you", "")
|
|
||||||
m.Cmdy(ice.WEB_PROXY, p, ice.WEB_FAVOR, arg)
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
"/favor/": {Name: "/story/", Help: "收藏夹", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/favor/": {Name: "/favor/", Help: "收藏夹", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case "pull":
|
case kit.MDB_PULL:
|
||||||
m.Richs(ice.WEB_FAVOR, nil, m.Option("favor"), func(key string, value map[string]interface{}) {
|
_favor_pull(m, m.Option(FAVOR))
|
||||||
m.Option("cache.limit", kit.Int(kit.Value(value, "meta.count"))+1-kit.Int(m.Option("begin")))
|
case kit.MDB_PUSH:
|
||||||
m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
_favor_insert(m, m.Option(FAVOR), m.Option(kit.MDB_TYPE),
|
||||||
m.Log(ice.LOG_EXPORT, "%v", value)
|
m.Option(kit.MDB_NAME), m.Option(kit.MDB_TEXT), m.Option(kit.MDB_EXTRA))
|
||||||
m.Push("", value, []string{"id", "type", "name", "text"})
|
|
||||||
m.Push("extra", kit.Format(value["extra"]))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
case "push":
|
|
||||||
m.Cmdy(ice.WEB_FAVOR, m.Option("favor"), m.Option("type"), m.Option("name"), m.Option("text"), m.Option("extra"))
|
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}}, nil)
|
}}, nil)
|
||||||
|
@ -91,7 +91,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessid := m.Cmdx(ice.AAA_SESS, "create", "")
|
sessid := m.Cmdx(ice.AAA_SESS, "create", "")
|
||||||
share := m.Cmdx(ice.WEB_SHARE, "add", "login", m.Option(ice.MSG_USERIP), sessid)
|
share := m.Cmdx(ice.WEB_SHARE, "login", m.Option(ice.MSG_USERIP), sessid)
|
||||||
Render(m, "cookie", sessid)
|
Render(m, "cookie", sessid)
|
||||||
m.Render(share)
|
m.Render(share)
|
||||||
}
|
}
|
||||||
|
@ -1,85 +1,61 @@
|
|||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _share_list(m *ice.Message, arg ...string) {
|
var SHARE = ice.Name(kit.MDB_SHARE, Index)
|
||||||
if len(arg) == 0 {
|
|
||||||
m.Grows(ice.WEB_SHARE, nil, "", "", func(index int, value map[string]interface{}) {
|
func _share_list(m *ice.Message, key string, fields ...string) {
|
||||||
m.Push("", value, []string{kit.MDB_TIME, "share", kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT})
|
if key == "" {
|
||||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), m.Conf(ice.WEB_SHARE, "meta.domain"), value["share"], value["share"]))
|
m.Grows(SHARE, nil, "", "", func(index int, value map[string]interface{}) {
|
||||||
|
m.Push("", value, []string{kit.MDB_TIME, kit.MDB_SHARE, kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT})
|
||||||
|
m.Push(kit.MDB_LINK, fmt.Sprintf(m.Conf(SHARE, "meta.template.link"), m.Conf(SHARE, "meta.domain"), value[kit.MDB_SHARE], value[kit.MDB_SHARE]))
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Richs(ice.WEB_SHARE, nil, arg[0], func(key string, value map[string]interface{}) {
|
m.Richs(SHARE, nil, key, func(key string, value map[string]interface{}) {
|
||||||
m.Push("detail", value)
|
m.Push("detail", value)
|
||||||
m.Push("key", "link")
|
|
||||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
|
|
||||||
m.Push("key", "share")
|
|
||||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
|
|
||||||
m.Push("key", "value")
|
|
||||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.value"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func _share_auth(m *ice.Message, share string, role string) {
|
m.Push(kit.MDB_KEY, kit.MDB_LINK)
|
||||||
m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
|
m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
|
||||||
switch value["type"] {
|
m.Push(kit.MDB_KEY, kit.MDB_SHARE)
|
||||||
case "active":
|
m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
|
||||||
m.Cmdy(ice.WEB_SPACE, value["name"], "sessid", m.Cmdx(ice.AAA_SESS, "create", role))
|
m.Push(kit.MDB_KEY, kit.MDB_VALUE)
|
||||||
case "user":
|
m.Push(kit.MDB_VALUE, fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.value"), m.Conf(ice.WEB_SHARE, "meta.domain"), key))
|
||||||
m.Cmdy(ice.AAA_ROLE, role, value["name"])
|
|
||||||
default:
|
|
||||||
m.Cmdy(ice.AAA_SESS, "auth", value["text"], role)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _share_check(m *ice.Message, share string) {
|
func _share_show(m *ice.Message, key string, value map[string]interface{}, arg ...string) bool {
|
||||||
m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
|
switch kit.Select("", arg, 0) {
|
||||||
|
case "check", "安全码":
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict(
|
m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict(
|
||||||
kit.MDB_TYPE, "share", kit.MDB_NAME, value["type"], kit.MDB_TEXT, key,
|
kit.MDB_TYPE, SHARE, kit.MDB_NAME, value[kit.MDB_TYPE], kit.MDB_TEXT, key,
|
||||||
)))
|
)))
|
||||||
})
|
case kit.MDB_SHARE, "共享码":
|
||||||
}
|
m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/?share=%s", m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
|
||||||
func _share_create(m *ice.Message, kind, name, text string, arg ...string) {
|
case kit.MDB_VALUE, "数据值":
|
||||||
arg = append(arg, "storm", m.Option("storm"), "river", m.Option("river"))
|
m.Render(ice.RENDER_QRCODE, kit.Format(value), kit.Select("256", arg, 1))
|
||||||
h := m.Rich(ice.WEB_SHARE, nil, kit.Dict(
|
case kit.MDB_TEXT:
|
||||||
kit.MDB_TIME, m.Time(m.Conf(ice.WEB_SHARE, "meta.expire")),
|
m.Render(ice.RENDER_QRCODE, kit.Format(value[kit.MDB_TEXT]))
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
case "detail", "详情":
|
||||||
"extra", kit.Dict(arg),
|
m.Render(kit.Formats(value))
|
||||||
))
|
case "download", "下载":
|
||||||
|
if strings.HasPrefix(kit.Format(value["text"]), m.Conf(ice.WEB_CACHE, "meta.path")) {
|
||||||
// 创建列表
|
m.Render(ice.RENDER_DOWNLOAD, value["text"], value["type"], value["name"])
|
||||||
m.Grow(ice.WEB_SHARE, nil, kit.Dict(
|
} else {
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
m.Render("%s", value["text"])
|
||||||
"share", h,
|
}
|
||||||
))
|
default:
|
||||||
m.Logs(ice.LOG_CREATE, "share", h, "type", kind, "name", name)
|
return false
|
||||||
m.Echo(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func _share_local(m *ice.Message, arg ...string) {
|
|
||||||
p := path.Join(arg...)
|
|
||||||
if m.Option("pod") != "" {
|
|
||||||
m.Cmdy(ice.WEB_SPACE, m.Option("pod"), "nfs.cat", p)
|
|
||||||
m.Render(ice.RENDER_RESULT)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
switch ls := strings.Split(p, "/"); ls[0] {
|
|
||||||
case "etc", "var":
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.Render(ice.RENDER_DOWNLOAD, p)
|
|
||||||
}
|
}
|
||||||
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
||||||
prefix := m.Conf(ice.WEB_SERVE, "meta.volcanos.require")
|
prefix := m.Conf(ice.WEB_SERVE, "meta.volcanos.require")
|
||||||
@ -88,10 +64,46 @@ func _share_repos(m *ice.Message, repos string, arg ...string) {
|
|||||||
}
|
}
|
||||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(prefix, repos, path.Join(arg...)))
|
m.Render(ice.RENDER_DOWNLOAD, path.Join(prefix, repos, path.Join(arg...)))
|
||||||
}
|
}
|
||||||
|
func _share_local(m *ice.Message, arg ...string) {
|
||||||
|
p := path.Join(arg...)
|
||||||
|
if m.Option("pod") != "" {
|
||||||
|
// 远程文件
|
||||||
|
m.Cmdy(ice.WEB_SPACE, m.Option("pod"), "nfs.cat", p)
|
||||||
|
m.Render(ice.RENDER_RESULT)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ls := strings.Split(p, "/"); ls[0] {
|
||||||
|
case "etc", "var":
|
||||||
|
// 私有文件
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 本地文件
|
||||||
|
m.Render(ice.RENDER_DOWNLOAD, p)
|
||||||
|
}
|
||||||
func _share_remote(m *ice.Message, pod string, arg ...string) {
|
func _share_remote(m *ice.Message, pod string, arg ...string) {
|
||||||
m.Cmdy(ice.WEB_SPACE, pod, "web./publish/", arg)
|
m.Cmdy(ice.WEB_SPACE, pod, "web./publish/", arg)
|
||||||
m.Render(ice.RENDER_RESULT)
|
m.Render(ice.RENDER_RESULT)
|
||||||
}
|
}
|
||||||
|
func _share_create(m *ice.Message, kind, name, text string, arg ...string) {
|
||||||
|
for _, k := range []string{"river", "storm"} {
|
||||||
|
arg = append(arg, k, m.Option(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
h := m.Rich(SHARE, nil, kit.Dict(
|
||||||
|
kit.MDB_TIME, m.Time(m.Conf(ice.WEB_SHARE, "meta.expire")),
|
||||||
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
|
kit.MDB_EXTRA, kit.Dict(arg),
|
||||||
|
))
|
||||||
|
|
||||||
|
// 创建列表
|
||||||
|
m.Grow(SHARE, nil, kit.Dict(
|
||||||
|
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||||
|
kit.MDB_SHARE, h,
|
||||||
|
))
|
||||||
|
m.Log_CREATE(kit.MDB_SHARE, h, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
||||||
|
m.Echo(h)
|
||||||
|
}
|
||||||
|
|
||||||
func _share_story(m *ice.Message, value map[string]interface{}, arg ...string) map[string]interface{} {
|
func _share_story(m *ice.Message, value map[string]interface{}, arg ...string) map[string]interface{} {
|
||||||
msg := m.Cmd(ice.WEB_STORY, ice.STORY_INDEX, value["text"])
|
msg := m.Cmd(ice.WEB_STORY, ice.STORY_INDEX, value["text"])
|
||||||
@ -102,49 +114,6 @@ func _share_story(m *ice.Message, value map[string]interface{}, arg ...string) m
|
|||||||
m.Log(ice.LOG_EXPORT, "%s: %v", arg, kit.Format(value))
|
m.Log(ice.LOG_EXPORT, "%s: %v", arg, kit.Format(value))
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
func _share_download(m *ice.Message, value map[string]interface{}) {
|
|
||||||
if strings.HasPrefix(kit.Format(value["text"]), m.Conf(ice.WEB_CACHE, "meta.path")) {
|
|
||||||
m.Render(ice.RENDER_DOWNLOAD, value["text"], value["type"], value["name"])
|
|
||||||
} else {
|
|
||||||
m.Render("%s", value["text"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func _share_action_redirect(m *ice.Message, value map[string]interface{}, share string) bool {
|
|
||||||
m.Render("redirect", "/share", "share", share,
|
|
||||||
"title", kit.Format(value["name"]),
|
|
||||||
"river", kit.Value(value, "extra.river"),
|
|
||||||
"storm", kit.Value(value, "extra.storm"),
|
|
||||||
"pod", kit.Value(value, "extra.tool.0.pod"),
|
|
||||||
kit.UnMarshal(kit.Format(kit.Value(value, "extra.tool.0.value"))),
|
|
||||||
)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
func _share_action_page(m *ice.Message, value map[string]interface{}) bool {
|
|
||||||
Render(m, ice.RENDER_DOWNLOAD, m.Conf(ice.WEB_SERVE, "meta.page.share"))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
func _share_action_list(m *ice.Message, value map[string]interface{}, river, storm string) bool {
|
|
||||||
value["count"] = kit.Int(value["count"]) + 1
|
|
||||||
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
|
||||||
m.Push("river", river)
|
|
||||||
m.Push("storm", storm)
|
|
||||||
m.Push("action", index)
|
|
||||||
|
|
||||||
m.Push("node", value["pod"])
|
|
||||||
m.Push("group", value["ctx"])
|
|
||||||
m.Push("index", value["cmd"])
|
|
||||||
m.Push("args", value["args"])
|
|
||||||
m.Push("value", value["value"])
|
|
||||||
|
|
||||||
msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, value["ctx"], value["cmd"])
|
|
||||||
m.Push("name", value["cmd"])
|
|
||||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
|
|
||||||
m.Push("inputs", msg.Append("list"))
|
|
||||||
m.Push("feature", msg.Append("meta"))
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
func _share_action(m *ice.Message, value map[string]interface{}, arg ...string) bool {
|
func _share_action(m *ice.Message, value map[string]interface{}, arg ...string) bool {
|
||||||
if len(arg) == 1 || arg[1] == "" {
|
if len(arg) == 1 || arg[1] == "" {
|
||||||
return _share_action_redirect(m, value, arg[0])
|
return _share_action_redirect(m, value, arg[0])
|
||||||
@ -179,86 +148,119 @@ func _share_action(m *ice.Message, value map[string]interface{}, arg ...string)
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
func _share_action_redirect(m *ice.Message, value map[string]interface{}, share string) bool {
|
||||||
|
m.Render("redirect", "/share", "share", share,
|
||||||
|
"title", kit.Format(value["name"]),
|
||||||
|
"river", kit.Value(value, "extra.river"),
|
||||||
|
"storm", kit.Value(value, "extra.storm"),
|
||||||
|
"pod", kit.Value(value, "extra.tool.0.pod"),
|
||||||
|
kit.UnMarshal(kit.Format(kit.Value(value, "extra.tool.0.value"))),
|
||||||
|
)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func _share_action_page(m *ice.Message, value map[string]interface{}) bool {
|
||||||
|
Render(m, ice.RENDER_DOWNLOAD, m.Conf(ice.WEB_SERVE, "meta.page.share"))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func _share_action_list(m *ice.Message, value map[string]interface{}, river, storm string) bool {
|
||||||
|
value["count"] = kit.Int(value["count"]) + 1
|
||||||
|
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
||||||
|
m.Push("river", river)
|
||||||
|
m.Push("storm", storm)
|
||||||
|
m.Push("action", index)
|
||||||
|
|
||||||
|
m.Push("node", value["pod"])
|
||||||
|
m.Push("group", value["ctx"])
|
||||||
|
m.Push("index", value["cmd"])
|
||||||
|
m.Push("args", value["args"])
|
||||||
|
m.Push("value", value["value"])
|
||||||
|
|
||||||
|
msg := m.Cmd(m.Space(value["pod"]), ice.CTX_COMMAND, value["ctx"], value["cmd"])
|
||||||
|
m.Push("name", value["cmd"])
|
||||||
|
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
|
||||||
|
m.Push("inputs", msg.Append("list"))
|
||||||
|
m.Push("feature", msg.Append("meta"))
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func _share_auth(m *ice.Message, share string, role string) {
|
||||||
|
m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
|
||||||
|
switch value["type"] {
|
||||||
|
case "active":
|
||||||
|
m.Cmdy(ice.WEB_SPACE, value["name"], "sessid", m.Cmdx(ice.AAA_SESS, "create", role))
|
||||||
|
case "user":
|
||||||
|
m.Cmdy(ice.AAA_ROLE, role, value["name"])
|
||||||
|
default:
|
||||||
|
m.Cmdy(ice.AAA_SESS, "auth", value["text"], role)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func _share_check(m *ice.Message, share string) {
|
||||||
|
m.Richs(ice.WEB_SHARE, nil, share, func(key string, value map[string]interface{}) {
|
||||||
|
m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict(
|
||||||
|
kit.MDB_TYPE, "share", kit.MDB_NAME, value["type"], kit.MDB_TEXT, key,
|
||||||
|
)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func _trash(m *ice.Message, arg ...string) {
|
||||||
|
switch arg[0] {
|
||||||
|
case "invite":
|
||||||
|
arg = []string{arg[0], m.Cmdx(ice.WEB_SHARE, "invite", kit.Select("tech", arg, 1), kit.Select("miss", arg, 2))}
|
||||||
|
fallthrough
|
||||||
|
case "check":
|
||||||
|
_share_check(m, arg[1])
|
||||||
|
case "auth":
|
||||||
|
_share_auth(m, arg[1], arg[2])
|
||||||
|
case "add":
|
||||||
|
_share_create(m, arg[1], arg[2], arg[3], arg[4:]...)
|
||||||
|
default:
|
||||||
|
if len(arg) == 1 {
|
||||||
|
_share_list(m, arg[0])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
ice.WEB_SHARE: {Name: "share", Help: "共享链", Value: kit.Data(
|
SHARE: {Name: "share", Help: "共享链", Value: kit.Data(
|
||||||
"index", "usr/volcanos/share.html",
|
"template", share_template, "expire", "72h",
|
||||||
"template", share_template,
|
|
||||||
"expire", "72h",
|
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.WEB_SHARE: {Name: "share share auto", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
SHARE: {Name: "share share=auto auto", Help: "共享链", Action: map[string]*ice.Action{
|
||||||
if len(arg) == 0 {
|
kit.MDB_CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_share_list(m)
|
_share_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
_share_list(m, kit.Select("", arg, 0))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_share_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||||
switch arg[0] {
|
}},
|
||||||
case "invite":
|
"/share/local/": {Name: "/share/local/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
arg = []string{arg[0], m.Cmdx(ice.WEB_SHARE, "add", "invite", kit.Select("tech", arg, 1), kit.Select("miss", arg, 2))}
|
_share_local(m, arg...)
|
||||||
fallthrough
|
|
||||||
case "check":
|
|
||||||
_share_check(m, arg[1])
|
|
||||||
case "auth":
|
|
||||||
_share_auth(m, arg[1], arg[2])
|
|
||||||
case "add":
|
|
||||||
_share_create(m, arg[1], arg[2], arg[3], arg[4:]...)
|
|
||||||
default:
|
|
||||||
if len(arg) == 1 {
|
|
||||||
_share_list(m, arg[0])
|
|
||||||
break
|
|
||||||
}
|
|
||||||
_share_create(m, arg[0], arg[1], arg[2], arg[3:]...)
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %v", arg, arg)
|
m.Richs(ice.WEB_SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
|
||||||
switch arg[0] {
|
m.Log_EXPORT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))
|
||||||
case "local":
|
|
||||||
_share_local(m, arg[1:]...)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Richs(ice.WEB_SHARE, nil, arg[0], func(key string, value map[string]interface{}) {
|
|
||||||
m.Log(ice.LOG_EXPORT, "%s: %v", arg, kit.Format(value))
|
|
||||||
if m.Warn(m.Option(ice.MSG_USERROLE) != ice.ROLE_ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()), "expired") {
|
if m.Warn(m.Option(ice.MSG_USERROLE) != ice.ROLE_ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()), "expired") {
|
||||||
m.Echo("expired")
|
m.Echo("expired")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value["type"] {
|
switch value[kit.MDB_TYPE] {
|
||||||
case ice.TYPE_SPACE:
|
|
||||||
case ice.TYPE_STORY:
|
case ice.TYPE_STORY:
|
||||||
value = _share_story(m, value, arg...)
|
value = _share_story(m, value, arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch kit.Select("", arg, 1) {
|
if _share_show(m, key, value, kit.Select("", arg, 1), kit.Select("", arg, 2)) {
|
||||||
case "download", "下载":
|
|
||||||
_share_download(m, value)
|
|
||||||
return
|
|
||||||
case "detail", "详情":
|
|
||||||
m.Render(kit.Formats(value))
|
|
||||||
return
|
|
||||||
case "share", "共享码":
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Format("%s/share/%s/?share=%s", m.Conf(ice.WEB_SHARE, "meta.domain"), key, key))
|
|
||||||
return
|
|
||||||
case "check", "安全码":
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Format(kit.Dict(
|
|
||||||
kit.MDB_TYPE, "share", kit.MDB_NAME, value["type"], kit.MDB_TEXT, key,
|
|
||||||
)))
|
|
||||||
return
|
|
||||||
case "value", "数据值":
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Format(value), kit.Select("256", arg, 2))
|
|
||||||
return
|
|
||||||
case "text":
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Format(value["text"]))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value["type"] {
|
switch value[kit.MDB_TYPE] {
|
||||||
case ice.TYPE_RIVER:
|
case ice.TYPE_RIVER:
|
||||||
// 共享群组
|
// 共享群组
|
||||||
m.Render("redirect", "/", "share", key, "river", kit.Format(value["text"]))
|
m.Render("redirect", "/", "share", key, "river", kit.Format(value["text"]))
|
||||||
@ -269,12 +271,14 @@ func init() {
|
|||||||
|
|
||||||
case ice.TYPE_ACTION:
|
case ice.TYPE_ACTION:
|
||||||
_share_action(m, value, arg...)
|
_share_action(m, value, arg...)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// 查看数据
|
// 查看数据
|
||||||
m.Option("type", value["type"])
|
m.Option(kit.MDB_VALUE, value)
|
||||||
m.Option("name", value["name"])
|
m.Option(kit.MDB_TYPE, value[kit.MDB_TYPE])
|
||||||
m.Option("text", value["text"])
|
m.Option(kit.MDB_NAME, value[kit.MDB_NAME])
|
||||||
m.Render(ice.RENDER_TEMPLATE, m.Conf(ice.WEB_SHARE, "meta.template.simple"))
|
m.Option(kit.MDB_TEXT, value[kit.MDB_TEXT])
|
||||||
|
m.Render(ice.RENDER_TEMPLATE, m.Conf(SHARE, "meta.template.simple"))
|
||||||
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -165,7 +165,7 @@ func init() {
|
|||||||
// 共享空间
|
// 共享空间
|
||||||
share := m.Option("share")
|
share := m.Option("share")
|
||||||
if m.Richs(ice.WEB_SHARE, nil, share, nil) == nil {
|
if m.Richs(ice.WEB_SHARE, nil, share, nil) == nil {
|
||||||
share = m.Cmdx(ice.WEB_SHARE, "add", m.Option("node"), m.Option("name"), m.Option("user"))
|
share = m.Cmdx(ice.WEB_SHARE, m.Option("node"), m.Option("name"), m.Option("user"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加节点
|
// 添加节点
|
||||||
|
@ -15,10 +15,10 @@ var STORY = ice.Name("story", Index)
|
|||||||
func _story_share(m *ice.Message, story string, list string, arg ...string) {
|
func _story_share(m *ice.Message, story string, list string, arg ...string) {
|
||||||
if m.Echo("share: "); list == "" {
|
if m.Echo("share: "); list == "" {
|
||||||
msg := m.Cmd(STORY, ice.STORY_INDEX, story)
|
msg := m.Cmd(STORY, ice.STORY_INDEX, story)
|
||||||
m.Cmdy(ice.WEB_SHARE, "add", "story", story, msg.Append("list"))
|
m.Cmdy(ice.WEB_SHARE, "story", story, msg.Append("list"))
|
||||||
} else {
|
} else {
|
||||||
msg := m.Cmd(STORY, ice.STORY_INDEX, list)
|
msg := m.Cmd(STORY, ice.STORY_INDEX, list)
|
||||||
m.Cmdy(ice.WEB_SHARE, "add", msg.Append("scene"), msg.Append("story"), msg.Append("text"))
|
m.Cmdy(ice.WEB_SHARE, msg.Append("scene"), msg.Append("story"), msg.Append("text"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func _story_list(m *ice.Message, arg ...string) {
|
func _story_list(m *ice.Message, arg ...string) {
|
||||||
|
@ -50,6 +50,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
|||||||
msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args)
|
msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args)
|
||||||
}
|
}
|
||||||
switch arg := kit.Simple(args...); cmd {
|
switch arg := kit.Simple(args...); cmd {
|
||||||
|
case ice.RENDER_VOID:
|
||||||
case ice.RENDER_OUTPUT:
|
case ice.RENDER_OUTPUT:
|
||||||
case "redirect":
|
case "redirect":
|
||||||
http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), 307)
|
http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), 307)
|
||||||
@ -627,7 +628,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
}) == nil {
|
}) == nil {
|
||||||
m.Rich(ice.WEB_SPIDE, nil, kit.Dict(
|
m.Rich(ice.WEB_SPIDE, nil, kit.Dict(
|
||||||
"cookie", kit.Dict(), "header", kit.Dict(), "client", kit.Dict(
|
"cookie", kit.Dict(), "header", kit.Dict(), "client", kit.Dict(
|
||||||
"share", m.Cmdx(ice.WEB_SHARE, "add", ice.TYPE_SPIDE, arg[1], arg[2]),
|
"share", m.Cmdx(ice.WEB_SHARE, ice.TYPE_SPIDE, arg[1], arg[2]),
|
||||||
// "type", "POST", "name", arg[1], "text", arg[2],
|
// "type", "POST", "name", arg[1], "text", arg[2],
|
||||||
"name", arg[1], "url", arg[2], "method", "POST",
|
"name", arg[1], "url", arg[2], "method", "POST",
|
||||||
"protocol", uri.Scheme, "hostname", uri.Host,
|
"protocol", uri.Scheme, "hostname", uri.Host,
|
||||||
@ -648,7 +649,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
|||||||
}
|
}
|
||||||
if msg.Result() != "" {
|
if msg.Result() != "" {
|
||||||
kit.Value(value, "client.login", msg.Result())
|
kit.Value(value, "client.login", msg.Result())
|
||||||
kit.Value(value, "client.share", m.Cmdx(ice.WEB_SHARE, "add", ice.TYPE_SPIDE, arg[1],
|
kit.Value(value, "client.share", m.Cmdx(ice.WEB_SHARE, ice.TYPE_SPIDE, arg[1],
|
||||||
kit.Format("%s?sessid=%s", kit.Value(value, "client.url"), kit.Value(value, "cookie.sessid"))))
|
kit.Format("%s?sessid=%s", kit.Value(value, "client.url"), kit.Value(value, "cookie.sessid"))))
|
||||||
}
|
}
|
||||||
m.Render(ice.RENDER_QRCODE, kit.Dict(
|
m.Render(ice.RENDER_QRCODE, kit.Dict(
|
||||||
|
2
conf.go
2
conf.go
@ -228,7 +228,7 @@ const ( // STORY
|
|||||||
STORY_DOWNLOAD = "download"
|
STORY_DOWNLOAD = "download"
|
||||||
)
|
)
|
||||||
const ( // RENDER
|
const ( // RENDER
|
||||||
RENDER_VOID = "_output"
|
RENDER_VOID = "_void"
|
||||||
RENDER_OUTPUT = "_output"
|
RENDER_OUTPUT = "_output"
|
||||||
RENDER_TEMPLATE = "_template"
|
RENDER_TEMPLATE = "_template"
|
||||||
RENDER_DOWNLOAD = "_download"
|
RENDER_DOWNLOAD = "_download"
|
||||||
|
@ -5,14 +5,14 @@ import (
|
|||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _action_share_create(m *ice.Message, arg ...string) {
|
func _action_share(m *ice.Message, arg ...string) {
|
||||||
if m.Option("index") != "" {
|
if m.Option("_index") != "" {
|
||||||
m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("name"), m.Option("text"),
|
m.Cmdy(ice.WEB_SHARE, ice.TYPE_ACTION, m.Option("_name"), m.Option("_text"),
|
||||||
"tool.0.pod", kit.Select(m.Option("pod"), m.Option("node")),
|
"tool.0.pod", kit.Select(m.Option("_pod"), m.Option("_node")),
|
||||||
"tool.0.ctx", m.Option("group"),
|
"tool.0.ctx", m.Option("_group"),
|
||||||
"tool.0.cmd", m.Option("index"),
|
"tool.0.cmd", m.Option("_index"),
|
||||||
"tool.0.args", m.Option("args"),
|
"tool.0.args", m.Option("_args"),
|
||||||
"tool.0.value", m.Option("value"),
|
"tool.0.value", m.Option("_value"),
|
||||||
"tool.0.single", "yes",
|
"tool.0.single", "yes",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -26,7 +26,7 @@ func _action_share_create(m *ice.Message, arg ...string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func _action_share_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
func _action_share_list(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
m.Richs(ice.WEB_SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
||||||
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
||||||
m.Push("river", arg[0])
|
m.Push("river", arg[0])
|
||||||
@ -46,7 +46,7 @@ func _action_share_select(m *ice.Message, c *ice.Context, cmd string, arg ...str
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _action_share_update(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
func _action_share_show(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[4], arg[5:]...) {
|
if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[4], arg[5:]...) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -134,21 +134,20 @@ func _action_select(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
"/action": {Name: "/action", Help: "工作台", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
|
||||||
switch arg[0] {
|
kit.MDB_SHARE: {Name: "share arg...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||||
case "share":
|
_action_share(m, arg...)
|
||||||
_action_share_create(m, arg...)
|
}},
|
||||||
return
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}
|
|
||||||
if len(arg) == 0 || arg[0] == "" {
|
if len(arg) == 0 || arg[0] == "" {
|
||||||
if m.Option("share") != "" {
|
if m.Option("share") != "" {
|
||||||
if len(arg) < 3 {
|
if len(arg) < 3 {
|
||||||
_action_share_select(m, c, cmd, arg...)
|
_action_share_list(m, c, cmd, arg...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_action_share_update(m, c, cmd, arg...)
|
_action_share_show(m, c, cmd, arg...)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Warn(m.Option(ice.MSG_RIVER) == "" || m.Option(ice.MSG_STORM) == "", "not join") {
|
if m.Warn(m.Option(ice.MSG_RIVER) == "" || m.Option(ice.MSG_STORM) == "", "not join") {
|
||||||
@ -226,7 +225,7 @@ func init() {
|
|||||||
list = append(list, k, kit.Format(v))
|
list = append(list, k, kit.Format(v))
|
||||||
}
|
}
|
||||||
// 共享命令
|
// 共享命令
|
||||||
m.Cmdy(ice.WEB_SHARE, "add", "action", arg[5], arg[6], list)
|
m.Cmdy(ice.WEB_SHARE, "action", arg[5], arg[6], list)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
|
|||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Cmdy(ice.WEB_SHARE, "add", arg[1], arg[2], arg[3], arg[4:])
|
m.Cmdy(ice.WEB_SHARE, arg[1], arg[2], arg[3], arg[4:])
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package code
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shylinux/icebergs"
|
"github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/toolkits"
|
"github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -39,28 +40,38 @@ func _pprof_list(m *ice.Message, zone string, id string, field ...interface{}) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _pprof_show(m *ice.Message, zone string, seconds string) {
|
func _pprof_show(m *ice.Message, zone string, seconds string) {
|
||||||
|
favor := m.Conf(PPROF, kit.Keys(kit.MDB_META, web.FAVOR))
|
||||||
|
|
||||||
m.Richs(PPROF, nil, zone, func(key string, val map[string]interface{}) {
|
m.Richs(PPROF, nil, zone, func(key string, val map[string]interface{}) {
|
||||||
val = val[kit.MDB_META].(map[string]interface{})
|
val = val[kit.MDB_META].(map[string]interface{})
|
||||||
|
|
||||||
|
// 收藏程序
|
||||||
|
m.Cmd(ice.WEB_FAVOR, favor, "bin", val[BINNARY], m.Cmd(ice.WEB_CACHE, "catch", "bin", val[BINNARY]).Append("data"))
|
||||||
|
|
||||||
|
// 性能分析
|
||||||
|
msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", seconds))
|
||||||
|
m.Cmd(ice.WEB_FAVOR, favor, "pprof", zone+".pd.gz", msg.Append("data"))
|
||||||
|
|
||||||
|
// 结果摘要
|
||||||
|
ls := strings.Split(m.Cmdx(ice.CLI_SYSTEM, "go", "tool", "pprof", "-text", msg.Append("text")), "\n")
|
||||||
|
if len(ls) > 20 {
|
||||||
|
ls = ls[:20]
|
||||||
|
}
|
||||||
|
m.Cmd(ice.WEB_FAVOR, favor, "shell", zone, strings.Join(ls, "\n"))
|
||||||
|
|
||||||
|
// 结果展示
|
||||||
|
p := kit.Format("%s:%s", m.Conf(ice.WEB_SHARE, "meta.host"), m.Cmdx("tcp.getport"))
|
||||||
|
m.Cmd(ice.CLI_DAEMON, "go", "tool", "pprof", "-http="+p, val[BINNARY], msg.Append("text"))
|
||||||
|
m.Cmd(ice.WEB_FAVOR, favor, "spide", msg.Append("text"), "http://"+p)
|
||||||
|
m.Echo(p)
|
||||||
|
|
||||||
|
return
|
||||||
m.Gos(m.Spawn(), func(msg *ice.Message) {
|
m.Gos(m.Spawn(), func(msg *ice.Message) {
|
||||||
m.Sleep("1s").Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
m.Sleep("1s").Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
|
||||||
// 压测命令
|
// 压测命令
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "shell", value[kit.MDB_TEXT], m.Cmdx(kit.Split(kit.Format(value[kit.MDB_TEXT]))))
|
m.Cmd(ice.WEB_FAVOR, favor, "shell", value[kit.MDB_TEXT], m.Cmdx(kit.Split(kit.Format(value[kit.MDB_TEXT]))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 启动监控
|
|
||||||
name := zone + ".pd.gz"
|
|
||||||
msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", seconds))
|
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "shell", "text", m.Cmdx(ice.CLI_SYSTEM, "go", "tool", "pprof", "-text", msg.Append("text")))
|
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "pprof", name, msg.Append("data"))
|
|
||||||
|
|
||||||
// 展示结果
|
|
||||||
p := kit.Format("%s:%s", m.Conf(ice.WEB_SHARE, "meta.host"), m.Cmdx("tcp.getport"))
|
|
||||||
m.Cmd(ice.CLI_DAEMON, "go", "tool", "pprof", "-http="+p, val[BINNARY], msg.Append("text"))
|
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "bin", val[BINNARY], m.Cmd(ice.WEB_CACHE, "catch", "bin", val[BINNARY]).Append("data"))
|
|
||||||
m.Cmd(ice.WEB_FAVOR, "pprof", "spide", msg.Append("text"), "http://"+p)
|
|
||||||
m.Echo(p)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -92,7 +103,8 @@ func _pprof_insert(m *ice.Message, zone, kind, name, text string, arg ...string)
|
|||||||
// 添加信息
|
// 添加信息
|
||||||
kit.MDB_EXTRA, kit.Dict(arg),
|
kit.MDB_EXTRA, kit.Dict(arg),
|
||||||
))
|
))
|
||||||
m.Log_INSERT(kit.MDB_ZONE, zone, kit.MDB_ID, id, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
m.Log_INSERT(kit.MDB_META, PPROF, kit.MDB_ZONE, zone,
|
||||||
|
kit.MDB_ID, id, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
||||||
m.Echo("%d", id)
|
m.Echo("%d", id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -108,7 +120,9 @@ func _pprof_create(m *ice.Message, zone string, binnary, service string, seconds
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
PPROF: {Name: "pprof", Help: "性能分析", Value: kit.Data(kit.MDB_SHORT, kit.MDB_ZONE)},
|
PPROF: {Name: "pprof", Help: "性能分析", Value: kit.Data(kit.MDB_SHORT, kit.MDB_ZONE,
|
||||||
|
web.FAVOR, "pprof",
|
||||||
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
PPROF: {Name: "pprof zone=auto id=auto auto", Help: "性能分析", Action: map[string]*ice.Action{
|
PPROF: {Name: "pprof zone=auto id=auto auto", Help: "性能分析", Action: map[string]*ice.Action{
|
||||||
|
5
meta.go
5
meta.go
@ -79,7 +79,10 @@ func (m *Message) Push(key string, value interface{}, arg ...interface{}) *Messa
|
|||||||
var v interface{}
|
var v interface{}
|
||||||
switch k {
|
switch k {
|
||||||
case kit.MDB_KEY, kit.MDB_ZONE:
|
case kit.MDB_KEY, kit.MDB_ZONE:
|
||||||
v = key
|
if key != "" {
|
||||||
|
v = key
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
if v = kit.Value(value, k); v == nil {
|
if v = kit.Value(value, k); v == nil {
|
||||||
v = kit.Value(value, kit.Keys(kit.MDB_EXTRA, k))
|
v = kit.Value(value, kit.Keys(kit.MDB_EXTRA, k))
|
||||||
|
@ -66,7 +66,7 @@ var Index = &ice.Context{Name: "lark", Help: "机器人",
|
|||||||
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
}},
|
}},
|
||||||
"login": {Name: "login", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
"login": {Name: "login", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
m.Cmdy(ice.WEB_SHARE, "add", "user", m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_SESSID))
|
m.Cmdy(ice.WEB_SHARE, "user", m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_SESSID))
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"app": {Name: "app login|token bot", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
"app": {Name: "app login|token bot", Help: "应用", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user