1
0
forked from x/icebergs

add msg.MergeURL2

This commit is contained in:
harveyshao 2021-11-25 19:16:56 +08:00
parent 46b77638a3
commit 5e781b2528
16 changed files with 70 additions and 29 deletions

View File

@ -124,7 +124,7 @@ func _dir_list(m *ice.Message, root string, name string, level int, deep bool, d
case kit.MDB_LINK:
m.PushDownload(kit.MDB_LINK, kit.Select("", f.Name(), !f.IsDir()), path.Join(root, name, f.Name()))
case "show":
p := kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD))
p := m.MergeURL2("/share/local/"+path.Join(name, f.Name()), ice.POD, m.Option(ice.MSG_USERPOD))
switch kit.Ext(f.Name()) {
case "jpg", "png":
m.PushImages(field, p)

View File

@ -184,7 +184,7 @@ func init() {
if m.Append(kit.MDB_FILE) == "" {
m.PushScript("inner", m.Append(kit.MDB_TEXT))
} else {
m.PushDownload(m.Append(kit.MDB_NAME), kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+arg[0]))
m.PushDownload(m.Append(kit.MDB_NAME), m.MergeURL2("/share/cache/"+arg[0]))
}
}},
}})

View File

@ -43,7 +43,7 @@ func _dream_show(m *ice.Message, name string) {
os.MkdirAll(p, ice.MOD_DIR)
}
m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/chat/pod/"+name))
m.ProcessOpen(m.MergeURL2("/chat/pod/" + name))
// 任务模板
if m.Option(kit.MDB_TEMPLATE) != "" {

View File

@ -69,7 +69,7 @@ func init() {
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
ROUTE: {Name: ROUTE, Help: "路由器", Value: kit.Data(kit.MDB_SHORT, kit.SSH_ROUTE)},
}, Commands: map[string]*ice.Command{
ROUTE: {Name: "route route ctx cmd auto invite share", Help: "路由器", Action: map[string]*ice.Action{
ROUTE: {Name: "route route ctx cmd auto invite share spide", Help: "路由器", Action: map[string]*ice.Action{
SHARE: {Name: "share", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
p := kit.MergeURL(m.Option(ice.MSG_USERWEB), SHARE, m.Cmdx(SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN))
m.EchoAnchor(p)
@ -115,6 +115,14 @@ func init() {
m.Debug(m.Option(ROUTE))
m.Cmdy(SPACE, m.Option(ROUTE), kit.Keys(m.Option(ice.CTX), m.Option(ice.CMD)), arg)
}},
"spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 { // 模块列表
m.Cmdy(ROUTE)
m.Display("/plugin/story/spide.js", "root", ice.ICE, "field", "route", "split", ice.PT, "prefix", "spide")
m.StatusTimeCount()
return
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 || arg[0] == "" { // 路由列表
if _route_travel(m, kit.Select("", arg, 0)); m.W != nil {

View File

@ -231,6 +231,16 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr
}
return cmds, true
}
func _serve_spide(m *ice.Message, prefix string, c *ice.Context) {
for k := range c.Commands {
if strings.HasPrefix(k, "/") {
m.Push("path", path.Join(prefix, k)+kit.Select("", "/", strings.HasSuffix(k, "/")))
}
}
for k, v := range c.Contexts {
_serve_spide(m, path.Join(prefix, k), v)
}
}
const (
WEB_LOGIN = "_login"
@ -265,7 +275,7 @@ func init() {
m.Done(value[kit.MDB_STATUS] == tcp.START)
})
}},
SERVE: {Name: "serve name auto start", Help: "服务器", Action: ice.MergeAction(map[string]*ice.Action{
SERVE: {Name: "serve name auto start spide", Help: "服务器", Action: ice.MergeAction(map[string]*ice.Action{
aaa.BLACK: {Name: "black", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
for _, k := range arg {
m.Log_CREATE(aaa.BLACK, k)
@ -291,6 +301,14 @@ func init() {
m.Cmd(SPACE, tcp.DIAL, ice.DEV, k, kit.MDB_NAME, ice.Info.NodeName)
}
}},
"spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 { // 模块列表
_serve_spide(m, "/", m.Target())
m.Display("/plugin/story/spide.js", "root", ice.ICE, "prefix", "spide")
m.StatusTimeCount()
return
}
}},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
mdb.HashSelect(m, arg...)
}},

View File

@ -19,7 +19,7 @@ import (
func _share_link(m *ice.Message, p string, arg ...interface{}) string {
p = kit.Select("", "/share/local/", !strings.HasPrefix(p, "/")) + p
return tcp.ReplaceLocalhost(m, kit.MergeURL2(m.Option(ice.MSG_USERWEB), p, arg...))
return tcp.ReplaceLocalhost(m, m.MergeURL2(p, arg...))
}
func _share_repos(m *ice.Message, repos string, arg ...string) {
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
@ -75,7 +75,7 @@ func _share_local(m *ice.Message, arg ...string) {
}
// 上传文件
m.Cmdy(SPACE, m.Option(ice.POD), SPIDE, ice.DEV, SPIDE_RAW, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy"),
m.Cmdy(SPACE, m.Option(ice.POD), SPIDE, ice.DEV, SPIDE_RAW, m.MergeURL2("/share/proxy"),
SPIDE_PART, m.OptionSimple(ice.POD), kit.MDB_PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p)
if s, e := os.Stat(pp); e == nil && !s.IsDir() {

View File

@ -16,7 +16,7 @@ import (
)
func _space_link(m *ice.Message, pod string, arg ...interface{}) string {
return tcp.ReplaceLocalhost(m, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/chat/pod/"+pod, arg...))
return tcp.ReplaceLocalhost(m, m.MergeURL2("/chat/pod/"+pod, arg...))
}
func _space_domain(m *ice.Message) (link string) {
link = m.Config(kit.MDB_DOMAIN)

View File

@ -52,8 +52,7 @@ func init() {
m.Option(mdb.FIELDS, "time,type,name,share")
m.Cmdy(mdb.SELECT, RIVER, _river_key(m, NODE), mdb.HASH)
m.Table(func(index int, value map[string]string, head []string) {
m.PushAnchor(value[kit.MDB_NAME], kit.MergeURL2(m.Option(ice.MSG_USERWEB),
"/chat/pod/"+kit.Keys(m.Option(ice.POD), value[kit.MDB_NAME])))
m.PushAnchor(value[kit.MDB_NAME], m.MergeURL2("/chat/pod/"+kit.Keys(m.Option(ice.POD), value[kit.MDB_NAME])))
})
m.RenameAppend("name", "pod")
m.PushAction(mdb.REMOVE)

View File

@ -22,7 +22,7 @@ func init() {
TRANS: {Name: "trans from to auto", Help: "传输", Action: ice.MergeAction(map[string]*ice.Action{
SEND: {Name: "send", Help: "发送", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.SPACE, m.Option(TO), web.SPIDE, ice.DEV, web.SPIDE_SAVE, kit.Select(ice.PWD, m.Option("to_path")),
kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/share/local/", m.Option("from_path")), ice.POD, m.Option(FROM),
m.MergeURL2(path.Join("/share/local/", m.Option("from_path")), ice.POD, m.Option(FROM),
web.SHARE, m.Cmdx(web.SHARE, mdb.CREATE, kit.MDB_TYPE, web.LOGIN),
),
)

View File

@ -12,7 +12,7 @@ import (
const PYTHON = "python"
func init() {
Index.Register(&ice.Context{
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
PYTHON: {Name: PYTHON, Help: "脚本命令", Value: kit.Data(
cli.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
@ -40,5 +40,5 @@ func init() {
m.Cmdy(INSTALL, path.Base(m.Conf(PYTHON, kit.META_SOURCE)), arg)
}},
},
}, nil)
})
}

View File

@ -139,6 +139,9 @@ func (m *Message) AppendTrans(cb func(value string, key string, index int) strin
}
}
}
func (m *Message) MergeURL2(url string, arg ...interface{}) string {
return kit.MergeURL2(m.Option(MSG_USERWEB), url, arg...)
}
func (m *Message) cmd(arg ...interface{}) *Message {
opts := map[string]interface{}{}

View File

@ -19,6 +19,7 @@ import (
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
@ -43,6 +44,11 @@ func packetWrite(m *ice.Message, cmd string, str ...string) {
var basicAuthRegex = regexp.MustCompile("^([^:]*):(.*)$")
func _server_login(m *ice.Message) error {
if m.Conf("web.serve", "meta.localhost") != ice.FALSE {
if tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
return nil
}
}
parts := strings.SplitN(m.R.Header.Get("Authorization"), ice.SP, 2)
if len(parts) < 2 {
return fmt.Errorf("Invalid authorization header, not enought parts")
@ -125,7 +131,7 @@ func init() {
}},
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option("go-get") == "1" { // 下载地址
p := kit.Split(kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/x/"+path.Join(arg...)), "?")[0]
p := kit.Split(m.MergeURL2("/x/"+path.Join(arg...)), "?")[0]
m.RenderResult(kit.Format(`<meta name="%s" content="%s">`, "go-import", kit.Format(`%s git %s`, strings.TrimPrefix(p, "https://"), p)))
return
}
@ -148,16 +154,24 @@ func init() {
web.RenderStatus(m, 500, err.Error())
}
}},
SERVER: {Name: "server path auto create", Help: "服务器", Action: map[string]*ice.Action{
SERVER: {Name: "server path auto create import", Help: "服务器", Action: map[string]*ice.Action{
mdb.CREATE: {Name: "create name", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Option(cli.CMD_DIR, path.Join(ice.USR_LOCAL, REPOS))
m.Cmdy(cli.SYSTEM, GIT, INIT, "--bare", m.Option(kit.MDB_NAME))
}},
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(REPOS, ice.OptionFields("time,name,path")).Table(func(index int, value map[string]string, head []string) {
m.Option(cli.CMD_DIR, value[nfs.PATH])
m.Cmd(cli.SYSTEM, "git", "push", m.MergeURL2("/x/"+value[kit.MDB_NAME]), "master")
m.Cmd(cli.SYSTEM, "git", "push", "--tags", m.MergeURL2("/x/"+value[kit.MDB_NAME]), "master")
})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL, REPOS)); len(arg) == 0 {
m.Cmdy(nfs.DIR, "").Table(func(index int, value map[string]string, head []string) {
m.PushScript("git clone " + kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/x/"+value[nfs.PATH]))
m.Cmdy(nfs.DIR, ice.PWD, "time,path,size").Table(func(index int, value map[string]string, head []string) {
m.PushScript("git clone " + m.MergeURL2("/x/"+value[nfs.PATH]))
})
m.StatusTimeCount()
return
}
m.Cmdy("_sum", path.Join(m.Option(nfs.DIR_ROOT), arg[0]))

View File

@ -18,7 +18,7 @@ func init() {
return
}
home := kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/chat/lark/sso")
home := m.MergeURL2("/chat/lark/sso")
if m.Option(kit.MDB_CODE) != "" { // 登录成功
msg := m.Cmd(web.SPIDE, LARK, "/open-apis/authen/v1/access_token", "grant_type", "authorization_code",
kit.MDB_CODE, m.Option(kit.MDB_CODE), "app_access_token", m.Cmdx(APP, TOKEN, m.Cmd(APP).Append(APPID)))

View File

@ -90,7 +90,7 @@ func (m *Message) Upload(dir string) {
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
m.Cmdy("cache", "watch", up[0], p) // 本机文件
} else { // 下发文件
m.Cmdy("spide", DEV, SAVE, p, "GET", kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/cache", up[0])))
m.Cmdy("spide", DEV, SAVE, p, "GET", m.MergeURL2(path.Join("/share/cache", up[0])))
}
}
func (m *Message) Action(arg ...string) {
@ -133,7 +133,7 @@ func (m *Message) PushNotice(arg ...interface{}) {
if m.Option(MSG_USERPOD) == "" {
m.Cmd("space", m.Option(MSG_DAEMON), arg)
} else {
m.Cmd("web.spide", "dev", kit.MergeURL2(m.Option(MSG_USERWEB), "/share/toast/"), kit.Format(kit.Dict("pod", m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
m.Cmd("web.spide", "dev", m.MergeURL2("/share/toast/"), kit.Format(kit.Dict("pod", m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
}
}
func (m *Message) PushNoticeGrow(arg ...interface{}) {

View File

@ -12,13 +12,12 @@ func AddRender(key string, render func(*Message, string, ...interface{}) string)
}
func Render(m *Message, cmd string, args ...interface{}) string {
if render, ok := Info.render[cmd]; ok {
m.Debug("render: %v %v", cmd, kit.FileLine(render, 3))
return render(m, cmd, args...)
}
switch arg := kit.Simple(args...); cmd {
case RENDER_ANCHOR: // [name] link
p := kit.MergeURL2(m.Option(MSG_USERWEB), kit.Select(arg[0], arg, 1))
p := m.MergeURL2(kit.Select(arg[0], arg, 1))
return kit.Format(`<a href="%s" target="_blank">%s</a>`, p, arg[0])
case RENDER_BUTTON: // name...

14
type.go
View File

@ -52,7 +52,7 @@ type Context struct {
Configs map[string]*Config
Commands map[string]*Command
contexts map[string]*Context
Contexts map[string]*Context
context *Context
root *Context
@ -85,10 +85,10 @@ func (c *Context) Register(s *Context, x Server, n ...string) *Context {
name(n, s)
}
if c.contexts == nil {
c.contexts = map[string]*Context{}
if c.Contexts == nil {
c.Contexts = map[string]*Context{}
}
c.contexts[s.Name] = s
c.Contexts[s.Name] = s
s.root = c.root
s.context = c
s.server = x
@ -349,13 +349,13 @@ func (m *Message) Travel(cb interface{}) *Message {
}
ls := []string{}
for k := range list[i].contexts {
for k := range list[i].Contexts {
ls = append(ls, k)
}
sort.Strings(ls)
for _, k := range ls { // 遍历递进
list = append(list, list[i].contexts[k])
list = append(list, list[i].Contexts[k])
}
}
return m
@ -380,7 +380,7 @@ func (m *Message) Search(key string, cb interface{}) *Message {
continue
}
for _, k := range ls[:len(ls)-1] {
if p = p.contexts[k]; p == nil {
if p = p.Contexts[k]; p == nil {
break
}
}