mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt chat
This commit is contained in:
parent
0fdfe06c23
commit
c8545920df
@ -74,7 +74,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
PathName = m.Conf(RUNTIME, "boot.pathname")
|
||||
|
||||
// 启动记录
|
||||
count := m.Confi(RUNTIME, "boot.count") + 1
|
||||
count := kit.Int(m.Conf(RUNTIME, "boot.count")) + 1
|
||||
m.Conf(RUNTIME, "boot.count", count)
|
||||
|
||||
// 节点信息
|
||||
|
@ -1,63 +0,0 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"math"
|
||||
)
|
||||
|
||||
func distance(lat1, long1, lat2, long2 float64) float64 {
|
||||
lat1 = lat1 * math.Pi / 180
|
||||
long1 = long1 * math.Pi / 180
|
||||
lat2 = lat2 * math.Pi / 180
|
||||
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 init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
"location": {Name: "location", Help: "定位", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"location": {Name: "location", Help: "location", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Grows("location", nil, "", "", func(index int, value map[string]interface{}) {
|
||||
m.Push("", value)
|
||||
})
|
||||
return
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
m.Richs("location", nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
m.Info("what %v", value)
|
||||
m.Push("detail", value)
|
||||
})
|
||||
return
|
||||
}
|
||||
if len(arg) == 2 {
|
||||
m.Richs("aaa.location", nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push("name", value["name"])
|
||||
m.Push("distance", kit.Int(distance(
|
||||
float64(kit.Int(arg[0]))/100000,
|
||||
float64(kit.Int(arg[1]))/100000,
|
||||
float64(kit.Int(value["latitude"]))/100000,
|
||||
float64(kit.Int(value["longitude"]))/100000,
|
||||
)*1000))
|
||||
})
|
||||
m.Sort("distance", "int")
|
||||
return
|
||||
}
|
||||
|
||||
data := m.Richs("location", nil, arg[0], nil)
|
||||
if data != nil {
|
||||
data["count"] = kit.Int(data["count"]) + 1
|
||||
} else {
|
||||
data = kit.Dict("name", arg[0], "address", arg[1], "latitude", arg[2], "longitude", arg[3], "count", 1)
|
||||
m.Rich("location", nil, data)
|
||||
}
|
||||
m.Grow("location", nil, data)
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
263
base/mdb/mdb.go
263
base/mdb/mdb.go
@ -3,23 +3,21 @@ package mdb
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/task"
|
||||
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _file_name(m *ice.Message, arg ...string) string {
|
||||
return kit.Select(path.Join("usr/export", kit.Select(arg[0], arg[0]+"/"+arg[1], arg[1] != ""), arg[2]), arg, 3)
|
||||
}
|
||||
|
||||
func _hash_insert(m *ice.Message, prefix, key string, arg ...string) string {
|
||||
func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
m.Log_INSERT("prefix", prefix, arg[0], arg[1])
|
||||
return m.Rich(prefix, key, kit.Data(arg))
|
||||
m.Echo(m.Rich(prefix, chain, kit.Data(arg)))
|
||||
|
||||
}
|
||||
func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
|
||||
@ -28,30 +26,27 @@ func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
|
||||
m.Conf(prefix, kit.Keys(chain, kit.MDB_HASH, key), "")
|
||||
})
|
||||
}
|
||||
func _hash_select(m *ice.Message, prefix, key, field, value string) {
|
||||
if field == "hash" && value == "random" {
|
||||
func _hash_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
if field == kit.MDB_HASH && value == "random" {
|
||||
value = kit.MDB_RANDOMS
|
||||
}
|
||||
fields := strings.Split(kit.Select("time,hash,type,name,text", m.Option(FIELDS)), ",")
|
||||
m.Richs(prefix, key, value, func(key string, val map[string]interface{}) {
|
||||
fields := kit.Split(kit.Select("time,hash,type,name,text", m.Option(FIELDS)))
|
||||
m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) {
|
||||
if val[kit.MDB_META] != nil {
|
||||
val = val[kit.MDB_META].(map[string]interface{})
|
||||
}
|
||||
if field != "" && field != kit.MDB_HASH && value != val[field] && value != kit.MDB_FOREACH {
|
||||
return
|
||||
}
|
||||
if m.Option(FIELDS) == "detail" {
|
||||
m.Push("detail", val)
|
||||
if m.Option(FIELDS) == DETAIL {
|
||||
m.Push(DETAIL, val)
|
||||
} else {
|
||||
m.Push(key, val, fields, val[kit.MDB_META])
|
||||
m.Push(key, val, fields)
|
||||
}
|
||||
})
|
||||
if m.Option(FIELDS) != "detail" {
|
||||
if m.Option(FIELDS) != DETAIL {
|
||||
m.Sort(kit.MDB_TIME, "time_r")
|
||||
}
|
||||
}
|
||||
func _hash_modify(m *ice.Message, prefix, key string, field, value string, arg ...string) {
|
||||
m.Richs(prefix, key, value, func(key string, value map[string]interface{}) {
|
||||
func _hash_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
|
||||
m.Richs(prefix, chain, value, func(key string, value map[string]interface{}) {
|
||||
if value[kit.MDB_META] != nil {
|
||||
value = value[kit.MDB_META].(map[string]interface{})
|
||||
}
|
||||
@ -61,10 +56,22 @@ func _hash_modify(m *ice.Message, prefix, key string, field, value string, arg .
|
||||
}
|
||||
kit.Value(value, arg[i], arg[i+1])
|
||||
}
|
||||
m.Log_MODIFY("prefix", prefix, field, value, arg)
|
||||
})
|
||||
m.Log_MODIFY("prefix", prefix, field, value, arg)
|
||||
}
|
||||
func _hash_import(m *ice.Message, prefix, key, file string) {
|
||||
func _hash_export(m *ice.Message, prefix, chain, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
en := json.NewEncoder(f)
|
||||
en.SetIndent("", " ")
|
||||
en.Encode(m.Confv(prefix, kit.Keys(chain, HASH)))
|
||||
|
||||
m.Log_EXPORT(kit.MDB_FILE, p)
|
||||
m.Echo(p)
|
||||
}
|
||||
func _hash_import(m *ice.Message, prefix, chain, file string) {
|
||||
f, e := os.Open(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
@ -73,49 +80,23 @@ func _hash_import(m *ice.Message, prefix, key, file string) {
|
||||
de := json.NewDecoder(f)
|
||||
de.Decode(&list)
|
||||
|
||||
if m.Conf(prefix, kit.Keys(key, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
||||
m.Conf(prefix, kit.Keys(key, kit.MDB_META, kit.MDB_SHORT), m.Conf(prefix, kit.Keys(kit.MDB_META, kit.MDB_SHORT)))
|
||||
}
|
||||
|
||||
count := 0
|
||||
if m.Conf(prefix, kit.Keys(key, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
||||
if m.Conf(prefix, kit.Keys(chain, kit.MDB_META, kit.MDB_SHORT)) == "" {
|
||||
for k, data := range list {
|
||||
// 导入数据
|
||||
m.Conf(prefix, kit.Keys(key, kit.MDB_HASH, k), data)
|
||||
m.Conf(prefix, kit.Keys(chain, kit.MDB_HASH, k), data)
|
||||
count++
|
||||
}
|
||||
} else {
|
||||
for _, data := range list {
|
||||
// 导入数据
|
||||
m.Rich(prefix, key, data)
|
||||
m.Rich(prefix, chain, data)
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, key), kit.MDB_COUNT, count)
|
||||
m.Echo(kit.Keys(file, JSON))
|
||||
}
|
||||
func _hash_export(m *ice.Message, prefix, key, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
en := json.NewEncoder(f)
|
||||
en.SetIndent("", " ")
|
||||
en.Encode(m.Confv(prefix, kit.Keys(key, HASH)))
|
||||
m.Log_EXPORT(kit.MDB_FILE, p)
|
||||
m.Echo(p)
|
||||
}
|
||||
func _hash_inputs(m *ice.Message, prefix, key string, field, value string) {
|
||||
list := map[string]int{}
|
||||
m.Richs(prefix, key, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
list[kit.Format(val[field])]++
|
||||
})
|
||||
for k, i := range list {
|
||||
m.Push("key", k)
|
||||
m.Push("count", i)
|
||||
}
|
||||
m.Sort("count", "int_r")
|
||||
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, chain), kit.MDB_COUNT, count)
|
||||
m.Echo("%d", count)
|
||||
}
|
||||
func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
m.Richs(prefix, chain, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
@ -127,44 +108,50 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Push(key, val)
|
||||
_hash_delete(m, prefix, chain, kit.MDB_HASH, key)
|
||||
m.Push(key, val)
|
||||
})
|
||||
}
|
||||
func _hash_search(m *ice.Message, prefix, key, field, value string) {
|
||||
m.Richs(prefix, key, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
if field != "" && value != val[field] {
|
||||
return
|
||||
func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
list := map[string]int{}
|
||||
m.Richs(prefix, chain, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
if val[kit.MDB_META] != nil {
|
||||
val = val[kit.MDB_META].(map[string]interface{})
|
||||
}
|
||||
m.Push(key, value)
|
||||
list[kit.Format(val[field])]++
|
||||
})
|
||||
for k, i := range list {
|
||||
m.Push(field, k)
|
||||
m.Push(kit.MDB_COUNT, i)
|
||||
}
|
||||
m.Sort(kit.MDB_COUNT, "int_r")
|
||||
}
|
||||
|
||||
func _list_insert(m *ice.Message, prefix, key string, arg ...string) int {
|
||||
func _list_insert(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
m.Log_INSERT("prefix", prefix, arg[0], arg[1])
|
||||
return m.Grow(prefix, key, kit.Dict(arg))
|
||||
m.Echo("%d", m.Grow(prefix, chain, kit.Dict(arg)))
|
||||
}
|
||||
func _list_delete(m *ice.Message, prefix, chain, field, value string) {
|
||||
}
|
||||
func _list_select(m *ice.Message, prefix, key, field, value string) {
|
||||
fields := strings.Split(kit.Select("time,type,name,text", m.Option(FIELDS)), ",")
|
||||
m.Grows(prefix, key, field, value, func(index int, val map[string]interface{}) {
|
||||
func _list_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
fields := kit.Split(kit.Select("time,id,type,name,text", m.Option(FIELDS)), ",")
|
||||
m.Grows(prefix, chain, field, value, func(index int, val map[string]interface{}) {
|
||||
if val[kit.MDB_META] != nil {
|
||||
val = val[kit.MDB_META].(map[string]interface{})
|
||||
}
|
||||
|
||||
if m.Option(FIELDS) == "detail" {
|
||||
m.Push("detail", val)
|
||||
if m.Option(FIELDS) == DETAIL {
|
||||
m.Push(DETAIL, val)
|
||||
} else {
|
||||
m.Push(key, val, fields, val[kit.MDB_META])
|
||||
m.Push(kit.Format(index), val, fields)
|
||||
}
|
||||
})
|
||||
if m.Option(FIELDS) != "detail" {
|
||||
if m.Option(FIELDS) != DETAIL {
|
||||
m.Sort(kit.MDB_ID, "int_r")
|
||||
}
|
||||
}
|
||||
func _list_modify(m *ice.Message, prefix, key string, field, value string, arg ...string) {
|
||||
m.Grows(prefix, key, field, value, func(index int, value map[string]interface{}) {
|
||||
func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
|
||||
m.Grows(prefix, chain, field, value, func(index int, value map[string]interface{}) {
|
||||
if value[kit.MDB_META] != nil {
|
||||
value = value[kit.MDB_META].(map[string]interface{})
|
||||
}
|
||||
@ -174,10 +161,42 @@ func _list_modify(m *ice.Message, prefix, key string, field, value string, arg .
|
||||
}
|
||||
kit.Value(value, arg[i], arg[i+1])
|
||||
}
|
||||
m.Log_MODIFY("prefix", prefix, field, value, kit.Format(arg))
|
||||
m.Log_MODIFY("prefix", prefix, field, value, arg)
|
||||
})
|
||||
}
|
||||
func _list_import(m *ice.Message, prefix, key, file string) {
|
||||
func _list_export(m *ice.Message, prefix, chain, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
w := csv.NewWriter(f)
|
||||
defer w.Flush()
|
||||
|
||||
count := 0
|
||||
head := []string{}
|
||||
m.Grows(prefix, chain, "", "", func(index int, value map[string]interface{}) {
|
||||
if index == 0 {
|
||||
// 输出表头
|
||||
for k := range value {
|
||||
head = append(head, k)
|
||||
}
|
||||
sort.Strings(head)
|
||||
w.Write(head)
|
||||
}
|
||||
|
||||
// 输出数据
|
||||
data := []string{}
|
||||
for _, k := range head {
|
||||
data = append(data, kit.Format(value[k]))
|
||||
}
|
||||
w.Write(data)
|
||||
count++
|
||||
})
|
||||
|
||||
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count)
|
||||
m.Echo(p)
|
||||
}
|
||||
func _list_import(m *ice.Message, prefix, chain, file string) {
|
||||
f, e := os.Open(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
@ -202,74 +221,14 @@ func _list_import(m *ice.Message, prefix, key, file string) {
|
||||
}
|
||||
|
||||
// 导入数据
|
||||
m.Grow(prefix, key, data)
|
||||
m.Grow(prefix, chain, data)
|
||||
count++
|
||||
}
|
||||
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, key), kit.MDB_COUNT, count)
|
||||
m.Echo(kit.Keys(file, CSV))
|
||||
}
|
||||
func _list_export(m *ice.Message, prefix, key, file string) {
|
||||
f, p, e := kit.Create(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
|
||||
w := csv.NewWriter(f)
|
||||
defer w.Flush()
|
||||
|
||||
count := 0
|
||||
head := []string{}
|
||||
m.Grows(prefix, key, "", "", func(index int, value map[string]interface{}) {
|
||||
if index == 0 {
|
||||
// 输出表头
|
||||
for k := range value {
|
||||
head = append(head, k)
|
||||
}
|
||||
sort.Strings(head)
|
||||
w.Write(head)
|
||||
}
|
||||
|
||||
// 输出数据
|
||||
data := []string{}
|
||||
for _, k := range head {
|
||||
data = append(data, kit.Format(value[k]))
|
||||
}
|
||||
w.Write(data)
|
||||
count++
|
||||
})
|
||||
m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count)
|
||||
m.Echo(p)
|
||||
}
|
||||
func _list_search(m *ice.Message, prefix, key, field, value string) {
|
||||
list := []interface{}{}
|
||||
files := map[string]bool{}
|
||||
m.Richs(prefix, key, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(kit.Value(value, "meta.record"), func(index int, value map[string]interface{}) {
|
||||
file := value["file"].(string)
|
||||
if _, ok := files[file]; ok {
|
||||
list = append(list, file)
|
||||
} else {
|
||||
files[file] = true
|
||||
}
|
||||
})
|
||||
})
|
||||
defer m.Cost("search")
|
||||
|
||||
task.Wait(list, func(task *task.Task, lock *task.Lock) error {
|
||||
kit.CSV(kit.Format(task.Arg), 100000, func(index int, line map[string]string, head []string) {
|
||||
if line[field] != value {
|
||||
return
|
||||
}
|
||||
|
||||
defer lock.WLock()()
|
||||
m.Push("", line)
|
||||
})
|
||||
return nil
|
||||
})
|
||||
m.Log_IMPORT(kit.MDB_KEY, kit.Keys(prefix, chain), kit.MDB_COUNT, count)
|
||||
m.Echo("%d", count)
|
||||
}
|
||||
|
||||
const (
|
||||
ErrDenyModify = "deny modify "
|
||||
)
|
||||
const (
|
||||
CSV = "csv"
|
||||
JSON = "json"
|
||||
@ -283,19 +242,19 @@ const (
|
||||
const (
|
||||
FIELDS = "fields"
|
||||
DETAIL = "detail"
|
||||
CREATE = "create"
|
||||
RENAME = "rename"
|
||||
REMOVE = "remove"
|
||||
COMMIT = "commit"
|
||||
INVITE = "invite"
|
||||
|
||||
INVITE = "invite"
|
||||
COMMIT = "commit"
|
||||
|
||||
CREATE = "create"
|
||||
INSERT = "insert"
|
||||
DELETE = "delete"
|
||||
SELECT = "select"
|
||||
MODIFY = "modify"
|
||||
DELETE = "delete"
|
||||
REMOVE = "remove"
|
||||
|
||||
IMPORT = "import"
|
||||
EXPORT = "export"
|
||||
IMPORT = "import"
|
||||
PRUNES = "prunes"
|
||||
INPUTS = "inputs"
|
||||
SCRIPT = "script"
|
||||
@ -306,12 +265,12 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
INSERT: {Name: "insert conf key type arg...", Help: "添加", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case HASH:
|
||||
m.Echo(_hash_insert(m, arg[0], arg[1], arg[3:]...))
|
||||
_hash_insert(m, arg[0], arg[1], arg[3:]...)
|
||||
case LIST:
|
||||
m.Echo("%d", _list_insert(m, arg[0], arg[1], arg[3:]...))
|
||||
_list_insert(m, arg[0], arg[1], arg[3:]...)
|
||||
}
|
||||
}},
|
||||
DELETE: {Name: "delete conf key type field value arg...", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
DELETE: {Name: "delete conf key type field value", Help: "删除", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case HASH:
|
||||
_hash_delete(m, arg[0], arg[1], arg[3], arg[4])
|
||||
@ -335,6 +294,14 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
_list_modify(m, arg[0], arg[1], arg[3], arg[4], arg[5:]...)
|
||||
}
|
||||
}},
|
||||
EXPORT: {Name: "export conf key type file", Help: "导出数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch file := _file_name(m, arg...); arg[2] {
|
||||
case HASH:
|
||||
_hash_export(m, arg[0], arg[1], file)
|
||||
case LIST:
|
||||
_list_export(m, arg[0], arg[1], file)
|
||||
}
|
||||
}},
|
||||
IMPORT: {Name: "import conf key type file", Help: "导入数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch file := _file_name(m, arg...); arg[2] {
|
||||
case HASH:
|
||||
@ -343,14 +310,6 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
_list_import(m, arg[0], arg[1], file)
|
||||
}
|
||||
}},
|
||||
EXPORT: {Name: "export conf key type [name]", Help: "导出数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch file := _file_name(m, arg...); arg[2] {
|
||||
case HASH:
|
||||
_hash_export(m, arg[0], arg[1], file)
|
||||
case LIST:
|
||||
_list_export(m, arg[0], arg[1], file)
|
||||
}
|
||||
}},
|
||||
PRUNES: {Name: "prunes conf key type [field value]...", Help: "清理数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case HASH:
|
||||
@ -361,7 +320,7 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
INPUTS: {Name: "inputs conf key type field value", Help: "输入补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[2] {
|
||||
case HASH:
|
||||
_hash_inputs(m, arg[0], arg[1], arg[3], kit.Select("", arg, 4))
|
||||
_hash_inputs(m, arg[0], arg[1], kit.Select("", arg, 3), kit.Select("", arg, 4))
|
||||
case LIST:
|
||||
}
|
||||
}},
|
||||
@ -371,7 +330,7 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块",
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil,
|
||||
INSERT, DELETE, SELECT, MODIFY,
|
||||
IMPORT, EXPORT, PRUNES, INPUTS,
|
||||
EXPORT, IMPORT, PRUNES, INPUTS,
|
||||
PLUGIN, RENDER, SEARCH, ENGINE,
|
||||
)
|
||||
}
|
||||
|
@ -30,15 +30,12 @@ func init() {
|
||||
if strings.Contains(arg[1], ";") {
|
||||
arg = strings.Split(arg[1], ";")
|
||||
}
|
||||
m.Option(FIELDS, "pod,ctx,cmd,time,size,type,name,text")
|
||||
for _, k := range strings.Split(arg[0], ",") {
|
||||
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
})
|
||||
}
|
||||
|
||||
m.Richs(SEARCH, nil, "alpha", func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], strings.ToLower(arg[1]), kit.Select("", arg, 2))
|
||||
})
|
||||
}},
|
||||
}}, nil)
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ func init() {
|
||||
}},
|
||||
|
||||
"/space/": {Name: "/space/ type name", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if s, e := websocket.Upgrade(m.W, m.R, nil, m.Confi(SPACE, "meta.buffer.r"), m.Confi(SPACE, "meta.buffer.w")); m.Assert(e) {
|
||||
if s, e := websocket.Upgrade(m.W, m.R, nil, kit.Int(m.Conf(SPACE, "meta.buffer.r")), kit.Int(m.Conf(SPACE, "meta.buffer.w"))); m.Assert(e) {
|
||||
name := m.Option(kit.MDB_NAME, strings.Replace(kit.Select(m.Option(ice.MSG_USERADDR), m.Option(kit.MDB_NAME)), ".", "_", -1))
|
||||
kind := kit.Select(WORKER, m.Option(kit.MDB_TYPE))
|
||||
share := m.Option("share")
|
||||
|
@ -6,117 +6,8 @@ import (
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _action_share_create(m *ice.Message, name, text string, arg ...string) {
|
||||
list := []string{}
|
||||
for i := 0; i < len(arg)-3; i += 5 {
|
||||
p := kit.Format("tool.%d.", i/5)
|
||||
list = append(list, p+POD, arg[i])
|
||||
list = append(list, p+CTX, arg[i+1])
|
||||
list = append(list, p+CMD, arg[i+2])
|
||||
list = append(list, p+ARG, arg[i+3])
|
||||
list = append(list, p+VAL, arg[i+4])
|
||||
}
|
||||
m.Cmdy(web.SHARE, ACTION, name, text, list)
|
||||
}
|
||||
func _action_share_list(m *ice.Message, key string) {
|
||||
m.Richs(web.SHARE, nil, key, func(key string, value map[string]interface{}) {
|
||||
m.Option(ice.MSG_USERNAME, kit.Value(value, "extra.username"))
|
||||
m.Option(ice.MSG_USERROLE, kit.Value(value, "extra.userrole"))
|
||||
m.Log_AUTH(aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
kit.Fetch(kit.Value(value, "extra.tool"), func(index int, value map[string]interface{}) {
|
||||
m.Push(RIVER, "")
|
||||
m.Push(STORM, "")
|
||||
m.Push(ACTION, index)
|
||||
|
||||
m.Push("node", value[POD])
|
||||
m.Push("group", value[CTX])
|
||||
m.Push("index", value[CMD])
|
||||
m.Push("args", value[ARG])
|
||||
|
||||
msg := m.Cmd(m.Space(value[POD]), ctx.COMMAND, kit.Keys(value[CTX], value[CMD]))
|
||||
ls := strings.Split(kit.Format(value[CMD]), ".")
|
||||
m.Push("name", ls[len(ls)-1])
|
||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
})
|
||||
})
|
||||
}
|
||||
func _action_order_list(m *ice.Message, river, storm string, arg ...string) {
|
||||
for _, v := range arg {
|
||||
m.Push(RIVER, river)
|
||||
m.Push(STORM, storm)
|
||||
m.Push(ACTION, v)
|
||||
|
||||
m.Push("node", "")
|
||||
m.Push("group", "")
|
||||
m.Push("index", v)
|
||||
m.Push("args", "[]")
|
||||
|
||||
msg := m.Cmd(m.Space(m.Option(POD)), ctx.COMMAND, v)
|
||||
m.Push("name", msg.Append("name"))
|
||||
m.Push("help", msg.Append("help"))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
}
|
||||
}
|
||||
func _action_list(m *ice.Message, river, storm string) {
|
||||
m.Option(ice.MSG_RIVER, river)
|
||||
m.Cmd(TOOL, storm).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(RIVER, river)
|
||||
m.Push(STORM, storm)
|
||||
m.Push(ACTION, value[kit.MDB_ID])
|
||||
|
||||
m.Push("node", value[POD])
|
||||
m.Push("group", value[CTX])
|
||||
m.Push("index", value[CMD])
|
||||
|
||||
msg := m.Cmd(m.Space(value[POD]), ctx.COMMAND, kit.Keys(value[CTX], value[CMD]))
|
||||
ls := strings.Split(kit.Format(value[CMD]), ".")
|
||||
m.Push("name", ls[len(ls)-1])
|
||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(value["help"])))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
})
|
||||
return
|
||||
if p := m.Option(POD); p != "" {
|
||||
m.Option(POD, "")
|
||||
// 代理列表
|
||||
m.Cmdy(web.SPACE, p, "web.chat./action")
|
||||
}
|
||||
if m.Option("share") != "" {
|
||||
// 共享列表
|
||||
_action_share_list(m, m.Option("share"))
|
||||
}
|
||||
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
m.Grows(RIVER, prefix, "", "", func(index int, value map[string]interface{}) {
|
||||
if meta, ok := kit.Value(value, kit.MDB_META).(map[string]interface{}); ok {
|
||||
m.Push(RIVER, river)
|
||||
m.Push(STORM, storm)
|
||||
m.Push(ACTION, index)
|
||||
|
||||
m.Push("node", meta[POD])
|
||||
m.Push("group", meta[CTX])
|
||||
m.Push("index", meta[CMD])
|
||||
m.Push("args", kit.Select("[]", kit.Format(meta["args"])))
|
||||
|
||||
msg := m.Cmd(m.Space(meta[POD]), ctx.COMMAND, kit.Keys(meta[CTX], meta[CMD]))
|
||||
ls := strings.Split(kit.Format(meta["cmd"]), ".")
|
||||
m.Push("name", ls[len(ls)-1])
|
||||
m.Push("help", kit.Select(msg.Append("help"), kit.Format(meta["help"])))
|
||||
m.Push("feature", msg.Append("meta"))
|
||||
m.Push("inputs", msg.Append("list"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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{}) {
|
||||
@ -127,7 +18,12 @@ func _action_right(m *ice.Message, river string, storm string) (ok bool) {
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
func _action_list(m *ice.Message, river, storm string) {
|
||||
m.Option(ice.MSG_RIVER, river)
|
||||
m.Cmdy(TOOL, storm).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmdy(m.Space(value[POD]), ctx.COMMAND, kit.Keys(value[CTX], value[CMD]))
|
||||
})
|
||||
}
|
||||
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)
|
||||
@ -136,71 +32,10 @@ func _action_show(m *ice.Message, river, storm, index string, arg ...string) {
|
||||
m.Option(POD, value[POD])
|
||||
}
|
||||
}) == nil && m.Warn(!m.Right(cmds), ice.ErrNotAuth) {
|
||||
m.Debug("what %v", prefix)
|
||||
return
|
||||
}
|
||||
|
||||
m.Cmdy(_action_proxy(m), cmds, arg)
|
||||
return
|
||||
|
||||
if i, e := strconv.Atoi(index); e == nil {
|
||||
m.Richs(web.SHARE, nil, m.Option("share"), func(key string, value map[string]interface{}) {
|
||||
m.Option(ice.MSG_USERNAME, kit.Value(value, "extra.username"))
|
||||
m.Option(ice.MSG_USERROLE, kit.Value(value, "extra.userrole"))
|
||||
m.Log_AUTH(aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
kit.Fetch(kit.Value(value, kit.Keys("extra.tool", i)), func(value map[string]interface{}) {
|
||||
// 共享命令
|
||||
if value[POD] != "" {
|
||||
m.Option(POD, value[POD])
|
||||
}
|
||||
cmds = kit.Simple(kit.Keys(value[CTX], value[CMD]), arg)
|
||||
})
|
||||
})
|
||||
m.Grows(RIVER, prefix, kit.MDB_ID, kit.Format(i+1), func(index int, value map[string]interface{}) {
|
||||
if value, ok := kit.Value(value, kit.MDB_META).(map[string]interface{}); ok {
|
||||
// 群组命令
|
||||
if value[POD] != "" {
|
||||
m.Option(POD, value[POD])
|
||||
}
|
||||
cmds = kit.Simple(kit.Keys(value[CTX], value[CMD]), arg)
|
||||
}
|
||||
})
|
||||
} else if !m.Warn(!m.Right(index), ice.ErrNotAuth) {
|
||||
// 定制命令
|
||||
cmds = kit.Simple(index, arg)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
if len(cmds) == 0 {
|
||||
if p := m.Option(POD); p != "" {
|
||||
m.Option(POD, "")
|
||||
// 代理列表
|
||||
m.Cmdy(web.SPACE, p, "web.chat./action", index, arg)
|
||||
return
|
||||
}
|
||||
m.Render("status", 404, "not found")
|
||||
return
|
||||
}
|
||||
if m.Warn(!m.Right(cmds), ice.ErrNotAuth) {
|
||||
m.Render("status", 403, "not auth")
|
||||
return
|
||||
}
|
||||
|
||||
if p := m.Option(POD); p != "" {
|
||||
if len(cmds) > 1 && cmds[1] == "action" {
|
||||
switch cmds[2] {
|
||||
case "upload":
|
||||
msg := m.Cmd(web.CACHE, web.UPLOAD)
|
||||
file := path.Join("var/proxy", p, msg.Option("path"), msg.Option("name"))
|
||||
m.Cmd("cache", "watch", msg.Option("data"), file)
|
||||
m.Cmdy(_action_proxy(m), cmds[0], "action", "upload", msg.Append("name"), msg.Option("path"),
|
||||
kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/", "pod", p))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Cmdy(_action_proxy(m), cmds)
|
||||
}
|
||||
func _action_proxy(m *ice.Message) (proxy []string) {
|
||||
if p := m.Option(POD); p != "" {
|
||||
@ -210,29 +45,11 @@ func _action_proxy(m *ice.Message) (proxy []string) {
|
||||
return proxy
|
||||
}
|
||||
|
||||
const (
|
||||
ORDER = "order"
|
||||
)
|
||||
const ACTION = "action"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
ACTION: {Name: "action hash auto 添加", Help: "群组", Action: map[string]*ice.Action{
|
||||
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(ctx.COMMAND, arg[0])
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
_action_list(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM))
|
||||
return
|
||||
}
|
||||
_action_show(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), arg[0], arg[1:]...)
|
||||
}},
|
||||
|
||||
"/action": {Name: "/action", Help: "工作台", Action: map[string]*ice.Action{
|
||||
web.SHARE: {Name: "share name text [pod ctx cmd arg]...", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_action_share_create(m, arg[0], arg[1], arg[2:]...)
|
||||
}},
|
||||
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))
|
||||
@ -240,33 +57,24 @@ func init() {
|
||||
_action_show(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), m.Option(ice.MSG_ACTION),
|
||||
append([]string{ACTION, web.UPLOAD}, arg...)...)
|
||||
}},
|
||||
ORDER: {Name: "order cmd...", Help: "定制", Hand: func(m *ice.Message, arg ...string) {
|
||||
_action_order_list(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), arg...)
|
||||
}},
|
||||
|
||||
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(ctx.COMMAND, arg[0])
|
||||
for _, k := range arg {
|
||||
m.Cmdy(ctx.COMMAND, k)
|
||||
}
|
||||
}},
|
||||
}, 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 m.Warn(!_action_right(m, m.Option(ice.MSG_RIVER, arg[0]), m.Option(ice.MSG_STORM, arg[1])), ice.ErrNotAuth) {
|
||||
return
|
||||
return // 没有授权
|
||||
}
|
||||
|
||||
if len(arg) == 2 {
|
||||
_action_list(m, arg[0], arg[1])
|
||||
return
|
||||
}
|
||||
if len(arg) > 2 && arg[2] == "order" {
|
||||
for _, k := range arg[3:] {
|
||||
m.Cmdy(ctx.COMMAND, k)
|
||||
m.Push("action", k)
|
||||
m.Push("index", k)
|
||||
}
|
||||
return
|
||||
}
|
||||
_action_show(m, arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
}}, nil)
|
||||
|
@ -16,7 +16,7 @@ func init() {
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + FOOTER: {Name: "/footer", Help: "状态栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"/footer": {Name: "/footer", Help: "状态栏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
kit.Fetch(m.Confv(FOOTER, LEGAL), func(index int, value string) { m.Echo(value) })
|
||||
}},
|
||||
},
|
||||
|
@ -11,46 +11,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
CHECK = "check"
|
||||
LOGIN = "login"
|
||||
TITLE = "title"
|
||||
LOGIN = "login"
|
||||
CHECK = "check"
|
||||
)
|
||||
const HEADER = "header"
|
||||
const _pack = `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=no">
|
||||
<title>volcanos</title>
|
||||
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>Volcanos.meta.webpack = true</script>
|
||||
</body>
|
||||
`
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
HEADER: {Name: "header", Help: "标题栏", Value: kit.Dict(
|
||||
TITLE, "github.com/shylinux/contexts",
|
||||
)},
|
||||
HEADER: {Name: HEADER, Help: "标题栏", Value: kit.Dict(TITLE, "github.com/shylinux/contexts")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + HEADER: {Name: "/header", Help: "标题栏", Action: map[string]*ice.Action{
|
||||
"userrole": {Name: "userrole", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(aaa.UserRole(m, m.Option("who")))
|
||||
}},
|
||||
|
||||
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
"/header": {Name: "/header", Help: "标题栏", Action: map[string]*ice.Action{
|
||||
LOGIN: {Name: "login", Help: "用户登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
if aaa.UserLogin(m, arg[0], arg[1]) {
|
||||
m.Option(ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)))
|
||||
@ -58,6 +31,13 @@ func init() {
|
||||
}
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
|
||||
"userrole": {Name: "userrole", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(aaa.UserRole(m, m.Option("who")))
|
||||
}},
|
||||
|
||||
"pack": {Name: "pack", Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("web.code.webpack", "pack")
|
||||
@ -88,3 +68,22 @@ func init() {
|
||||
},
|
||||
}, nil)
|
||||
}
|
||||
|
||||
const _pack = `
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=no">
|
||||
<title>volcanos</title>
|
||||
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
|
||||
<style type="text/css">%s</style>
|
||||
<style type="text/css">%s</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>%s</script>
|
||||
<script>Volcanos.meta.webpack = true</script>
|
||||
</body>
|
||||
`
|
||||
|
@ -6,16 +6,26 @@ import (
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"math"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func distance(lat1, long1, lat2, long2 float64) float64 {
|
||||
lat1 = lat1 * math.Pi / 180
|
||||
long1 = long1 * math.Pi / 180
|
||||
lat2 = lat2 * math.Pi / 180
|
||||
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)))
|
||||
}
|
||||
|
||||
const (
|
||||
LOCATION = "location"
|
||||
LONGITUDE = "longitude"
|
||||
LATITUDE = "latitude"
|
||||
LONGITUDE = "longitude"
|
||||
)
|
||||
|
||||
const LOCATION = "location"
|
||||
|
||||
func init() {
|
||||
Index.Register(&ice.Context{Name: LOCATION, Help: "地理位置",
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -3,26 +3,24 @@ package chat
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/core/wiki"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const PASTE = "paste"
|
||||
|
||||
func init() {
|
||||
Index.Register(&ice.Context{Name: PASTE, Help: "粘贴板",
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
PASTE: {Name: "paste", Help: "粘贴板", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
PASTE: {Name: PASTE, Help: "粘贴板", Value: kit.Data(kit.MDB_SHORT, kit.MDB_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) { m.Save(PASTE) }},
|
||||
|
||||
PASTE: {Name: "paste hash=auto auto 添加 导出 导入", Help: "粘贴板", Action: map[string]*ice.Action{
|
||||
PASTE: {Name: "paste hash auto 添加 导出 导入", Help: "粘贴板", Action: map[string]*ice.Action{
|
||||
mdb.INSERT: {Name: "insert text:textarea=hi", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.INSERT, m.Prefix(PASTE), m.Option(ice.MSG_DOMAIN), mdb.HASH, arg)
|
||||
}},
|
||||
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, m.Prefix(PASTE), m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_TEXT, m.Option("text"))
|
||||
m.Cmdy(mdb.DELETE, m.Prefix(PASTE), 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(PASTE), m.Option(ice.MSG_DOMAIN), mdb.HASH)
|
||||
@ -32,9 +30,9 @@ func init() {
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
text := m.Cmd(mdb.SELECT, m.Prefix(PASTE), m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_HASH, arg[0]).Append("text")
|
||||
m.Cmdy("web.wiki.spark", "inner", text)
|
||||
m.Cmdy("web.wiki.image", "qrcode", text)
|
||||
text := m.Cmd(mdb.SELECT, m.Prefix(PASTE), m.Option(ice.MSG_DOMAIN), mdb.HASH, kit.MDB_HASH, arg[0]).Append(kit.MDB_TEXT)
|
||||
m.Cmdy(wiki.SPARK, "inner", text)
|
||||
m.Cmdy(wiki.IMAGE, "qrcode", text)
|
||||
m.Render("")
|
||||
return
|
||||
}
|
||||
|
@ -45,6 +45,11 @@ func _river_proxy(m *ice.Message, pod string) (proxy []string) {
|
||||
return proxy
|
||||
}
|
||||
|
||||
const (
|
||||
POD = "pod"
|
||||
CTX = "ctx"
|
||||
CMD = "cmd"
|
||||
)
|
||||
const (
|
||||
INFO = "info"
|
||||
AUTH = "auth"
|
||||
@ -52,6 +57,7 @@ const (
|
||||
TOOL = "tool"
|
||||
USER = "user"
|
||||
)
|
||||
const STORM = "storm"
|
||||
const RIVER = "river"
|
||||
|
||||
func init() {
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + mdb.SEARCH: {Name: "/search", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"/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:])
|
||||
return
|
||||
|
@ -1,116 +0,0 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _storm_list(m *ice.Message, river string) {
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_KEY)
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_NAME)
|
||||
m.Set(ice.MSG_OPTION, kit.MDB_COUNT)
|
||||
|
||||
if p := m.Option(POD); p != "" {
|
||||
m.Option(POD, "")
|
||||
// 代理列表
|
||||
m.Cmdy(web.SPACE, p, "web.chat./storm")
|
||||
}
|
||||
ok := true
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river, USER), m.Option(ice.MSG_USERNAME), func(k string, val map[string]interface{}) {
|
||||
ok = true
|
||||
})
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river), m.Option(ice.MSG_RIVER), func(k string, val map[string]interface{}) {
|
||||
ok = true
|
||||
})
|
||||
if ok {
|
||||
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, river, TOOL), kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value[kit.MDB_META], []string{kit.MDB_KEY, kit.MDB_NAME, kit.MDB_COUNT})
|
||||
})
|
||||
m.Sort(kit.MDB_NAME)
|
||||
}
|
||||
}
|
||||
func _storm_tool(m *ice.Message, river, storm string, arg ...string) { // pod ctx cmd help
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
for i := 0; i < len(arg)-3; i += 4 {
|
||||
m.Grow(RIVER, kit.Keys(prefix), kit.Data(
|
||||
POD, arg[i], CTX, arg[i+1], CMD, arg[i+2], "help", arg[i+3],
|
||||
))
|
||||
m.Log_INSERT(RIVER, river, STORM, storm, TOOL, arg[i:i+4])
|
||||
}
|
||||
}
|
||||
func _storm_share(m *ice.Message, river, storm, name string, arg ...string) {
|
||||
m.Cmdy(web.SHARE, STORM, name, storm, RIVER, river, arg)
|
||||
}
|
||||
func _storm_remove(m *ice.Message, river string, storm string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL)
|
||||
m.Richs(RIVER, kit.Keys(prefix), storm, func(value map[string]interface{}) {
|
||||
m.Log_REMOVE(RIVER, river, STORM, storm, kit.MDB_VALUE, kit.Format(value))
|
||||
})
|
||||
m.Conf(RIVER, kit.Keys(prefix, kit.MDB_HASH, storm), "")
|
||||
}
|
||||
func _storm_rename(m *ice.Message, river, storm string, name string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, river, TOOL, kit.MDB_HASH, storm)
|
||||
old := m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME))
|
||||
m.Log_MODIFY(RIVER, river, STORM, storm, kit.MDB_VALUE, name, "old", old)
|
||||
m.Conf(RIVER, kit.Keys(prefix, kit.MDB_META, kit.MDB_NAME), name)
|
||||
}
|
||||
func _storm_create(m *ice.Message, river string, kind, name, text string, arg ...string) string {
|
||||
h := m.Rich(RIVER, kit.Keys(kit.MDB_HASH, river, TOOL), kit.Dict(
|
||||
kit.MDB_META, kit.Dict(
|
||||
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
|
||||
kit.MDB_EXTRA, kit.Dict(arg),
|
||||
),
|
||||
))
|
||||
m.Log_CREATE(kit.MDB_META, STORM, RIVER, river, kit.MDB_TYPE, kind, kit.MDB_NAME, name)
|
||||
m.Echo(h)
|
||||
return h
|
||||
}
|
||||
|
||||
const (
|
||||
POD = "pod"
|
||||
CTX = "ctx"
|
||||
CMD = "cmd"
|
||||
ARG = "arg"
|
||||
VAL = "val"
|
||||
)
|
||||
|
||||
const STORM = "storm"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
STORM: {Name: "storm", Help: "应用", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/" + STORM: {Name: "/storm", Help: "暴风雨", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create type name text arg...", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_create(m, m.Option(ice.MSG_RIVER), arg[0], arg[1], arg[2], arg[3:]...)
|
||||
}},
|
||||
mdb.RENAME: {Name: "rename name", Help: "更名", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_rename(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), arg[0])
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_remove(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM))
|
||||
}},
|
||||
web.SHARE: {Name: "share name", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_share(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), arg[0])
|
||||
}},
|
||||
"save": {Name: "save", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||
prefix := kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), TOOL, kit.MDB_HASH, m.Option(ice.MSG_STORM))
|
||||
for i, v := range arg {
|
||||
args := kit.Parse(nil, "", kit.Split(v)...)
|
||||
m.Conf(RIVER, kit.Keys(prefix, kit.MDB_LIST, i, kit.MDB_META, "args"), args)
|
||||
m.Debug("fuck %v %v", kit.Keys(prefix, kit.MDB_LIST, i), args)
|
||||
}
|
||||
}},
|
||||
TOOL: {Name: "tool [pod ctx cmd help]...", Help: "添加工具", Hand: func(m *ice.Message, arg ...string) {
|
||||
_storm_tool(m, m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM), arg...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_storm_list(m, m.Option(ice.MSG_RIVER))
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
"/ocean": {Name: "/ocean", Help: "大海洋", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
// 用户列表
|
||||
m.Richs(aaa.USER, nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value, []string{"username", "usernode"})
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "spawn":
|
||||
// 创建群组
|
||||
river := m.Rich(RIVER, nil, kit.Dict(
|
||||
kit.MDB_META, kit.Dict(kit.MDB_NAME, arg[1]),
|
||||
"user", kit.Data(kit.MDB_SHORT, "username"),
|
||||
"tool", kit.Data(),
|
||||
))
|
||||
m.Log(ice.LOG_CREATE, "river: %v name: %v", river, arg[1])
|
||||
// 添加用户
|
||||
m.Cmd("/river", river, "add", m.Option(ice.MSG_USERNAME), arg[2:])
|
||||
m.Echo(river)
|
||||
}
|
||||
}},
|
||||
"/steam": {Name: "/steam", Help: "大气层", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Warn(m.Option(ice.MSG_RIVER) == "", "not join") {
|
||||
m.Render("status", 402, "not join")
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) < 2 {
|
||||
if list := []string{}; m.Option("pod") != "" {
|
||||
// 远程空间
|
||||
m.Cmdy(web.SPACE, m.Option("pod"), "web.chat./steam").Table(func(index int, value map[string]string, head []string) {
|
||||
list = append(list, kit.Keys(m.Option("pod"), value["name"]))
|
||||
})
|
||||
m.Append("name", list)
|
||||
} else {
|
||||
// 本地空间
|
||||
m.Richs(web.SPACE, nil, "*", func(key string, value map[string]interface{}) {
|
||||
switch value[kit.MDB_TYPE] {
|
||||
case web.SERVER, web.WORKER:
|
||||
m.Push(key, value, []string{"type", "name", "user"})
|
||||
}
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if m.Warn(!m.Right(cmd, arg[1])) {
|
||||
m.Render("status", 403, "not auth")
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[1] {
|
||||
case "spawn":
|
||||
// 创建应用
|
||||
storm := m.Rich(RIVER, kit.Keys(kit.MDB_HASH, arg[0], "tool"), kit.Dict(
|
||||
kit.MDB_META, kit.Dict(kit.MDB_NAME, arg[2]),
|
||||
))
|
||||
m.Log(ice.LOG_CREATE, "storm: %s name: %v", storm, arg[2])
|
||||
// 添加命令
|
||||
m.Cmd("/storm", arg[0], storm, "add", arg[3:])
|
||||
m.Echo(storm)
|
||||
|
||||
case "append":
|
||||
// 追加命令
|
||||
m.Cmd("/storm", arg[0], arg[2], "add", arg[3:])
|
||||
|
||||
default:
|
||||
// 命令列表
|
||||
m.Cmdy(web.SPACE, arg[2], ctx.COMMAND)
|
||||
}
|
||||
}},
|
||||
},
|
||||
}, nil)
|
||||
}
|
@ -82,7 +82,7 @@ func _bench_modify(m *ice.Message, zone, id, k, v, old string) {
|
||||
m.Richs(BENCH, nil, zone, func(key string, val map[string]interface{}) {
|
||||
switch k {
|
||||
case kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME:
|
||||
m.Warn(true, mdb.ErrDenyModify, k)
|
||||
// m.Warn(true, mdb.ErrDenyModify, k)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func _pprof_modify(m *ice.Message, zone, id, k, v, old string) {
|
||||
m.Richs(PPROF, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
|
||||
switch k {
|
||||
case kit.MDB_ZONE, kit.MDB_ID, kit.MDB_TIME:
|
||||
m.Warn(true, mdb.ErrDenyModify, k)
|
||||
// m.Warn(true, mdb.ErrDenyModify, k)
|
||||
return
|
||||
case BINNARY, SERVICE, SECONDS:
|
||||
// 修改信息
|
||||
|
95
type.go
95
type.go
@ -127,6 +127,7 @@ func (c *Context) Cmd(m *Message, cmd string, key string, arg ...string) *Messag
|
||||
func (c *Context) Server() Server {
|
||||
return c.server
|
||||
}
|
||||
|
||||
func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
||||
for _, n := range name {
|
||||
Name(n, s)
|
||||
@ -143,7 +144,44 @@ func (c *Context) Register(s *Context, x Server, name ...string) *Context {
|
||||
s.server = x
|
||||
return s
|
||||
}
|
||||
func (c *Context) Merge(s *Context, x Server) *Context {
|
||||
if c.Commands == nil {
|
||||
c.Commands = map[string]*Command{}
|
||||
}
|
||||
if c.Configs == nil {
|
||||
c.Configs = map[string]*Config{}
|
||||
}
|
||||
if c.Caches == nil {
|
||||
c.Caches = map[string]*Cache{}
|
||||
}
|
||||
for k, v := range s.Commands {
|
||||
c.Commands[k] = v
|
||||
if v.List == nil {
|
||||
v.List = c._split(v.Name)
|
||||
}
|
||||
if v.Meta == nil {
|
||||
v.Meta = kit.Dict()
|
||||
}
|
||||
|
||||
for k, a := range v.Action {
|
||||
if a.List == nil {
|
||||
a.List = c._split(a.Name)
|
||||
}
|
||||
if len(a.List) > 0 {
|
||||
v.Meta[a.Help] = a.List
|
||||
v.Meta[k] = a.List
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range s.Configs {
|
||||
c.Configs[k] = v
|
||||
}
|
||||
for k, v := range s.Caches {
|
||||
c.Caches[k] = v
|
||||
}
|
||||
s.server = x
|
||||
return c
|
||||
}
|
||||
func (c *Context) _split(name string) []interface{} {
|
||||
button, list := false, []interface{}{}
|
||||
for _, v := range kit.Split(kit.Select("key", name), " ", " ")[1:] {
|
||||
@ -191,44 +229,6 @@ func (c *Context) _split(name string) []interface{} {
|
||||
}
|
||||
return list
|
||||
}
|
||||
func (c *Context) Merge(s *Context, x Server) *Context {
|
||||
if c.Commands == nil {
|
||||
c.Commands = map[string]*Command{}
|
||||
}
|
||||
if c.Configs == nil {
|
||||
c.Configs = map[string]*Config{}
|
||||
}
|
||||
if c.Caches == nil {
|
||||
c.Caches = map[string]*Cache{}
|
||||
}
|
||||
for k, v := range s.Commands {
|
||||
c.Commands[k] = v
|
||||
if v.List == nil {
|
||||
v.List = c._split(v.Name)
|
||||
}
|
||||
if v.Meta == nil {
|
||||
v.Meta = kit.Dict()
|
||||
}
|
||||
|
||||
for k, a := range v.Action {
|
||||
if a.List == nil {
|
||||
a.List = c._split(a.Name)
|
||||
}
|
||||
if len(a.List) > 0 {
|
||||
v.Meta[a.Help] = a.List
|
||||
v.Meta[k] = a.List
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, v := range s.Configs {
|
||||
c.Configs[k] = v
|
||||
}
|
||||
for k, v := range s.Caches {
|
||||
c.Caches[k] = v
|
||||
}
|
||||
s.server = x
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Context) Spawn(m *Message, name string, help string, arg ...string) *Context {
|
||||
s := &Context{Name: name, Help: help, Caches: map[string]*Cache{}, Configs: map[string]*Config{}}
|
||||
@ -645,6 +645,14 @@ func (m *Message) Cmd(arg ...interface{}) *Message {
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *Message) Confm(key string, chain interface{}, cbs ...interface{}) map[string]interface{} {
|
||||
val := m.Confv(key, chain)
|
||||
if len(cbs) > 0 {
|
||||
kit.Fetch(val, cbs[0])
|
||||
}
|
||||
value, _ := val.(map[string]interface{})
|
||||
return value
|
||||
}
|
||||
func (m *Message) Confv(arg ...interface{}) (val interface{}) {
|
||||
m.Search(arg[0], func(p *Context, s *Context, key string, conf *Config) {
|
||||
if len(arg) == 1 {
|
||||
@ -666,17 +674,6 @@ func (m *Message) Confv(arg ...interface{}) (val interface{}) {
|
||||
})
|
||||
return
|
||||
}
|
||||
func (m *Message) Confm(key string, chain interface{}, cbs ...interface{}) map[string]interface{} {
|
||||
val := m.Confv(key, chain)
|
||||
if len(cbs) > 0 {
|
||||
kit.Fetch(val, cbs[0])
|
||||
}
|
||||
value, _ := val.(map[string]interface{})
|
||||
return value
|
||||
}
|
||||
func (m *Message) Confi(arg ...interface{}) int {
|
||||
return kit.Int(m.Confv(arg...))
|
||||
}
|
||||
func (m *Message) Conf(arg ...interface{}) string {
|
||||
return kit.Format(m.Confv(arg...))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user