1
0
forked from x/icebergs

add _inner_redirect

This commit is contained in:
shaoying 2020-06-01 14:23:57 +08:00
parent 35e6b6d411
commit 21e4ce710f
4 changed files with 51 additions and 20 deletions

View File

@ -139,7 +139,7 @@ func _share_action_list(m *ice.Message, value map[string]interface{}, river, sto
return true 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 { if len(arg) == 1 || arg[1] == "" {
return _share_action_redirect(m, value, arg[0]) return _share_action_redirect(m, value, arg[0])
} }
if arg[1] == "" { if arg[1] == "" {
@ -217,8 +217,8 @@ func init() {
m.Richs(ice.WEB_SHARE, nil, arg[0], func(key string, value map[string]interface{}) { 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)) m.Log(ice.LOG_EXPORT, "%s: %v", arg, kit.Format(value))
if m.Option(ice.MSG_USERROLE) != ice.ROLE_ROOT && kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Time()) { 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("invalid") m.Echo("expired")
return return
} }

View File

@ -131,6 +131,7 @@ const ( // LOG
LOG_WARN = "warn" LOG_WARN = "warn"
LOG_ERROR = "error" LOG_ERROR = "error"
LOG_TRACE = "trace" LOG_TRACE = "trace"
LOG_DEBUG = "debug"
) )
const ( // SSH const ( // SSH
SSH_SOURCE = "source" SSH_SOURCE = "source"

View File

@ -14,19 +14,36 @@ const INNER = "inner"
const QRCODE = "qrcode" const QRCODE = "qrcode"
const VEDIO = "vedio" const VEDIO = "vedio"
func _inner_list(m *ice.Message, name string) { func _inner_protect(m *ice.Message, name string) bool {
if ls := strings.Split(name, "/"); m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true" { if ls := strings.Split(name, "/"); m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true" {
return true
}
return false
}
func _inner_list(m *ice.Message, name string) {
if _inner_protect(m, name) {
m.Push("file", "../") m.Push("file", "../")
return return
} }
if m.Cmdy(kit.Keys(strings.TrimPrefix(path.Ext(name), "."), "list"), name); len(m.Resultv()) > 0 { p := strings.TrimPrefix(path.Ext(name), ".")
if m.Cmdy(kit.Keys(p, "list"), name); len(m.Resultv()) > 0 {
return return
} }
if strings.HasSuffix(name, "/") || m.Conf(INNER, kit.Keys("meta.source", p)) == "true" {
m.Cmdy("nfs.dir", name, "file size time") m.Cmdy("nfs.dir", name, "file size time")
} else {
m.Echo(name)
}
} }
func _inner_save(m *ice.Message, name, text string) { func _inner_save(m *ice.Message, name, text string) {
if _inner_protect(m, name) {
m.Echo("no right")
return
}
if m.Cmdy(kit.Keys(strings.TrimPrefix(path.Ext(name), "."), "save"), name, text); len(m.Resultv()) > 0 { if m.Cmdy(kit.Keys(strings.TrimPrefix(path.Ext(name), "."), "save"), name, text); len(m.Resultv()) > 0 {
return return
} }
@ -53,6 +70,11 @@ func _inner_plug(m *ice.Message, name string) {
m.Echo("{}") m.Echo("{}")
} }
func _inner_show(m *ice.Message, name string) { func _inner_show(m *ice.Message, name string) {
if _inner_protect(m, name) {
m.Push("file", "../")
return
}
p := strings.TrimPrefix(path.Ext(name), ".") p := strings.TrimPrefix(path.Ext(name), ".")
if msg := m.Cmd(kit.Keys(p, "show"), name); m != msg && msg.Hand { if msg := m.Cmd(kit.Keys(p, "show"), name); m != msg && msg.Hand {
m.Copy(msg) m.Copy(msg)
@ -80,6 +102,10 @@ func init() {
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
INNER: {Name: "inner", Help: "编辑器", Value: kit.Data( INNER: {Name: "inner", Help: "编辑器", Value: kit.Data(
"protect", kit.Dict("etc", "true", "var", "true", "usr", "true"), "protect", kit.Dict("etc", "true", "var", "true", "usr", "true"),
"source", kit.Dict(
"sh", "true", "shy", "true", "py", "true",
"js", "true", "go", "true", "c", "true",
),
"plug", kit.Dict( "plug", kit.Dict(
"py", kit.Dict("display", true, "profile", true), "py", kit.Dict("display", true, "profile", true),
"md", kit.Dict("display", true, "profile", true), "md", kit.Dict("display", true, "profile", true),
@ -121,7 +147,7 @@ func init() {
web.StoryWatch(m, m.Option("data"), path.Join(m.Option("path"), m.Option("name"))) web.StoryWatch(m, m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
}}, }},
"project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) { "project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) {
_inner_list(m, path.Join("./", kit.Select("", arg, 0))) _inner_list(m, path.Join("./", kit.Select("", arg, 0))+"/")
}}, }},
}, 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) > 0 && arg[0] == "action" { if len(arg) > 0 && arg[0] == "action" {

30
info.go
View File

@ -9,17 +9,6 @@ import (
"strings" "strings"
) )
func (m *Message) Logs(level string, arg ...interface{}) *Message {
list := []string{}
for i := 0; i < len(arg)-1; i += 2 {
list = append(list, fmt.Sprintf("%v: %v", arg[i], arg[i+1]))
}
m.log(level, strings.Join(list, " "))
return m
}
func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
return m.log(level, str, arg...)
}
func (m *Message) log(level string, str string, arg ...interface{}) *Message { func (m *Message) log(level string, str string, arg ...interface{}) *Message {
if str = strings.TrimSpace(fmt.Sprintf(str, arg...)); Log != nil { if str = strings.TrimSpace(fmt.Sprintf(str, arg...)); Log != nil {
// 日志模块 // 日志模块
@ -63,8 +52,17 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
} }
return m return m
} }
func (m *Message) Cost(str string, arg ...interface{}) *Message {
return m.log(LOG_COST, "%s: %s", m.Format("cost"), kit.Format(str, arg...)) func (m *Message) Log(level string, str string, arg ...interface{}) *Message {
return m.log(level, str, arg...)
}
func (m *Message) Logs(level string, arg ...interface{}) *Message {
list := []string{}
for i := 0; i < len(arg)-1; i += 2 {
list = append(list, fmt.Sprintf("%v: %v", arg[i], arg[i+1]))
}
m.log(level, strings.Join(list, " "))
return m
} }
func (m *Message) Info(str string, arg ...interface{}) *Message { func (m *Message) Info(str string, arg ...interface{}) *Message {
return m.log(LOG_INFO, str, arg...) return m.log(LOG_INFO, str, arg...)
@ -87,6 +85,9 @@ func (m *Message) Error(err bool, str string, arg ...interface{}) bool {
} }
return false return false
} }
func (m *Message) Debug(str string, arg ...interface{}) {
m.log(LOG_DEBUG, str, arg...)
}
func (m *Message) Trace(key string, str string, arg ...interface{}) *Message { func (m *Message) Trace(key string, str string, arg ...interface{}) *Message {
if m.Options(key) { if m.Options(key) {
m.Echo("trace: ").Echo(str, arg...) m.Echo("trace: ").Echo(str, arg...)
@ -94,3 +95,6 @@ func (m *Message) Trace(key string, str string, arg ...interface{}) *Message {
} }
return m return m
} }
func (m *Message) Cost(str string, arg ...interface{}) *Message {
return m.log(LOG_COST, "%s: %s", m.Format("cost"), kit.Format(str, arg...))
}