forked from x/icebergs
opt share
This commit is contained in:
parent
7481bb0fb9
commit
da6498a52e
@ -151,6 +151,18 @@ func HashAction(fields ...string) map[string]*ice.Action {
|
||||
REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(DELETE, m.PrefixKey(), "", HASH, m.OptionSimple(kit.MDB_HASH))
|
||||
}},
|
||||
PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []string{}
|
||||
m.Richs(m.PrefixKey(), "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Option("before")) {
|
||||
list = append(list, key)
|
||||
}
|
||||
})
|
||||
m.OptionFields(m.Conf(m.PrefixKey(), kit.META_FIELD))
|
||||
for _, v := range list {
|
||||
m.Cmdy(DELETE, m.PrefixKey(), "", HASH, kit.MDB_HASH, v)
|
||||
}
|
||||
}},
|
||||
EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(EXPORT, m.PrefixKey(), "", HASH)
|
||||
}},
|
||||
|
@ -183,9 +183,9 @@ func init() {
|
||||
"/cache/": {Name: "/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(CACHE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
if kit.Format(value[kit.MDB_FILE]) == "" {
|
||||
m.Render(ice.RENDER_DOWNLOAD, value[kit.MDB_FILE])
|
||||
m.RenderDownload(value[kit.MDB_FILE])
|
||||
} else {
|
||||
m.Render(ice.RENDER_RESULT, value[kit.MDB_TEXT])
|
||||
m.RenderResult(value[kit.MDB_TEXT])
|
||||
}
|
||||
})
|
||||
}},
|
||||
|
@ -273,10 +273,10 @@ func init() {
|
||||
}},
|
||||
|
||||
"/volcanos/": {Name: "/volcanos/", Help: "浏览器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.RenderDownload(path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), path.Join(arg...)))
|
||||
m.RenderIndex(SERVE, ice.VOLCANOS, arg...)
|
||||
}},
|
||||
"/intshell/": {Name: "/intshell/", Help: "命令行", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.RenderDownload(path.Join(m.Conf(SERVE, kit.Keym(ice.INTSHELL, kit.MDB_PATH)), path.Join(arg...)))
|
||||
m.RenderIndex(SERVE, ice.INTSHELL, arg...)
|
||||
}},
|
||||
"/publish/": {Name: "/publish/", Help: "私有云", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_share_local(m, m.Conf(SERVE, kit.Keym(ice.PUBLISH)), path.Join(arg...))
|
||||
|
@ -12,37 +12,27 @@ import (
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/ssh"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _share_domain(m *ice.Message) string {
|
||||
link := m.Conf(SHARE, kit.Keym(kit.MDB_DOMAIN))
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, SPIDE_DEV, cli.PWD).Append(kit.MDB_LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, SPIDE_SHY, cli.PWD).Append(kit.MDB_LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = kit.Format("http://%s:%s", m.Cmd(tcp.HOST).Append(tcp.IP), m.Cmd(SERVE).Append(tcp.PORT))
|
||||
}
|
||||
return link
|
||||
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...))
|
||||
}
|
||||
func _share_cache(m *ice.Message, arg ...string) {
|
||||
if pod := m.Option(cli.POD); pod != "" {
|
||||
m.Option(cli.POD, "")
|
||||
msg := m.Cmd(SPACE, pod, CACHE, arg[0])
|
||||
if msg.Append(kit.MDB_FILE) == "" {
|
||||
m.Render(ice.RENDER_RESULT, msg.Append(kit.MDB_TEXT))
|
||||
if pod := m.Option(cli.POD); m.PodCmd(CACHE, arg[0]) {
|
||||
if m.Append(kit.MDB_FILE) == "" {
|
||||
m.RenderResult(m.Append(kit.MDB_TEXT))
|
||||
} else {
|
||||
m.Option(cli.POD, pod)
|
||||
_share_local(m, msg.Append(kit.MDB_FILE))
|
||||
_share_local(m, m.Append(kit.MDB_FILE))
|
||||
}
|
||||
return
|
||||
}
|
||||
msg := m.Cmd(CACHE, arg[0])
|
||||
m.Render(ice.RENDER_DOWNLOAD, msg.Append(kit.MDB_FILE), msg.Append(kit.MDB_TYPE), msg.Append(kit.MDB_NAME))
|
||||
m.RenderDownload(msg.Append(kit.MDB_FILE), msg.Append(kit.MDB_TYPE), msg.Append(kit.MDB_NAME))
|
||||
}
|
||||
func _share_local(m *ice.Message, arg ...string) {
|
||||
p := path.Join(arg...)
|
||||
@ -66,39 +56,39 @@ func _share_local(m *ice.Message, arg ...string) {
|
||||
cache = s.ModTime()
|
||||
}
|
||||
|
||||
m.Cmdy(SPACE, m.Option(cli.POD), SPIDE, SPIDE_DEV, SPIDE_RAW, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
|
||||
SPIDE_PART, cli.POD, m.Option(cli.POD), kit.MDB_PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p)
|
||||
// 上传文件
|
||||
m.Cmdy(SPACE, m.Option(cli.POD), SPIDE, SPIDE_DEV, SPIDE_RAW, _share_link(m, "/share/proxy/"),
|
||||
SPIDE_PART, m.OptionSimple(cli.POD), kit.MDB_PATH, p, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, "@"+p)
|
||||
|
||||
if s, e := os.Stat(pp); e == nil && !s.IsDir() {
|
||||
p = pp
|
||||
}
|
||||
}
|
||||
|
||||
if p == path.Join(ice.USR_PUBLISH, ice.ORDER_JS) {
|
||||
if _, e := os.Stat(p); os.IsNotExist(e) {
|
||||
m.Render(ice.RENDER_RESULT, "")
|
||||
m.RenderResult("")
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Render(ice.RENDER_DOWNLOAD, p)
|
||||
m.RenderDownload(p)
|
||||
}
|
||||
func _share_proxy(m *ice.Message, arg ...string) {
|
||||
switch m.R.Method {
|
||||
switch p := path.Join(ice.VAR_PROXY, m.Option(cli.POD), m.Option(kit.MDB_PATH)); m.R.Method {
|
||||
case http.MethodGet: // 下发文件
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(ice.VAR_PROXY, path.Join(m.Option(cli.POD), m.Option(kit.MDB_PATH), m.Option(kit.MDB_NAME))))
|
||||
m.RenderDownload(path.Join(p, m.Option(kit.MDB_NAME)))
|
||||
|
||||
case http.MethodPost: // 上传文件
|
||||
m.Cmdy(CACHE, UPLOAD)
|
||||
m.Cmdy(CACHE, WATCH, m.Option(kit.MDB_DATA), path.Join(ice.VAR_PROXY, m.Option(cli.POD), m.Option(kit.MDB_PATH)))
|
||||
m.Render(ice.RENDER_RESULT, m.Option(kit.MDB_PATH))
|
||||
m.Cmdy(CACHE, WATCH, m.Option(kit.MDB_DATA), p)
|
||||
m.RenderResult(m.Option(kit.MDB_PATH))
|
||||
}
|
||||
}
|
||||
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
||||
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
|
||||
if _, e := os.Stat(path.Join(prefix, repos)); e != nil {
|
||||
if _, e := os.Stat(path.Join(prefix, repos)); e != nil { // 克隆代码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, kit.SSH_REPOS, "https://"+repos, kit.MDB_PATH, path.Join(prefix, repos))
|
||||
}
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(prefix, repos, path.Join(arg...)))
|
||||
m.RenderDownload(path.Join(prefix, repos, path.Join(arg...)))
|
||||
}
|
||||
|
||||
const (
|
||||
@ -112,106 +102,60 @@ const SHARE = "share"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SHARE: {Name: SHARE, Help: "共享链", Value: kit.Data(kit.MDB_EXPIRE, "72h")},
|
||||
SHARE: {Name: SHARE, Help: "共享链", Value: kit.Data(
|
||||
kit.MDB_EXPIRE, "72h", kit.MDB_FIELD, "time,hash,userrole,username,river,storm,type,name,text",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_DOWNLOAD, func(m *ice.Message, cmd string, args ...interface{}) string {
|
||||
arg := kit.Simple(args...)
|
||||
if arg[0] == "" {
|
||||
return ""
|
||||
}
|
||||
list := []string{}
|
||||
if m.Option(ice.MSG_USERPOD) != "" {
|
||||
list = append(list, "pod", m.Option(ice.MSG_USERPOD))
|
||||
list = append(list, cli.POD, m.Option(ice.MSG_USERPOD))
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
arg[0] = kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join(kit.Select("", "/share/local",
|
||||
!strings.HasPrefix(arg[0], "/")), arg[0]), list)
|
||||
} else {
|
||||
arg[1] = kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join(kit.Select("", "/share/local",
|
||||
!strings.HasPrefix(arg[1], "/")), arg[1]), list, "filename", arg[0])
|
||||
|
||||
arg := kit.Simple(args...)
|
||||
if len(arg) > 1 {
|
||||
list = append(list, "filename", arg[0])
|
||||
}
|
||||
arg[0] = m.ReplaceLocalhost(arg[0])
|
||||
return fmt.Sprintf(`<a href="%s" download="%s">%s</a>`, m.ReplaceLocalhost(kit.Select(arg[0], arg, 1)), path.Base(arg[0]), arg[0])
|
||||
return fmt.Sprintf(`<a href="%s" download="%s">%s</a>`,
|
||||
_share_link(m, kit.Select(arg[0], arg, 1), list), path.Base(arg[0]), arg[0])
|
||||
})
|
||||
}},
|
||||
SHARE: {Name: "share hash auto prunes", Help: "共享链", Action: map[string]*ice.Action{
|
||||
SHARE: {Name: "share hash auto prunes", Help: "共享链", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.INSERT, SHARE, "", mdb.HASH, kit.MDB_TIME, m.Time(m.Conf(SHARE, kit.Keym(kit.MDB_EXPIRE))),
|
||||
m.Cmdy(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, kit.MDB_TIME, m.Time(m.Conf(SHARE, kit.Keym(kit.MDB_EXPIRE))),
|
||||
aaa.USERROLE, m.Option(ice.MSG_USERROLE), aaa.USERNAME, m.Option(ice.MSG_USERNAME),
|
||||
RIVER, m.Option(ice.MSG_RIVER), STORM, m.Option(ice.MSG_STORM), arg)
|
||||
m.Option(kit.MDB_LINK, _share_link(m, "/share/"+m.Result()))
|
||||
}},
|
||||
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.MODIFY, SHARE, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH), arg)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, SHARE, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
mdb.SELECT: {Name: "select hash", Help: "查询", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.FIELDS, "time,userrole,username,river,storm,type,name,text")
|
||||
m.Cmdy(mdb.SELECT, SHARE, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {}},
|
||||
mdb.PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []string{}
|
||||
m.Richs(SHARE, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Option("before")) {
|
||||
list = append(list, key)
|
||||
}
|
||||
})
|
||||
m.Option(mdb.FIELDS, "time,userrole,username,river,storm,type,name,text")
|
||||
for _, v := range list {
|
||||
m.Cmdy(mdb.DELETE, SHARE, "", mdb.HASH, kit.MDB_HASH, v)
|
||||
}
|
||||
}},
|
||||
|
||||
LOGIN: {Name: "login userrole=void,tech username", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoQRCode(kit.MergeURL(_share_domain(m),
|
||||
SHARE, m.Cmdx(SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN,
|
||||
aaa.USERNAME, kit.Select(m.Option(ice.MSG_USERNAME), m.Option(aaa.USERNAME)),
|
||||
aaa.USERROLE, m.Option(aaa.USERROLE),
|
||||
)))
|
||||
m.Cmdy(SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN, m.OptionSimple(aaa.USERROLE, aaa.USERNAME))
|
||||
m.EchoQRCode(m.Option(kit.MDB_LINK))
|
||||
m.ProcessInner()
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), "time,hash,type,name,text,userrole,username,river,storm")
|
||||
m.Cmdy(mdb.SELECT, SHARE, "", mdb.HASH, kit.MDB_HASH, arg)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
|
||||
if len(arg) > 0 {
|
||||
link := kit.MergeURL(m.Option(ice.MSG_USERWEB), SHARE, arg[0])
|
||||
if strings.Contains(link, tcp.LOCALHOST) {
|
||||
link = strings.Replace(link, tcp.LOCALHOST, m.Cmd(tcp.HOST, ice.OptionFields(tcp.IP)).Append(tcp.IP), 1)
|
||||
}
|
||||
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), m.Conf(SHARE, kit.META_FIELD))
|
||||
if m.Cmdy(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, kit.MDB_HASH, arg); len(arg) > 0 {
|
||||
link := _share_link(m, "/share/"+arg[0])
|
||||
m.PushQRCode(cli.QRCODE, link)
|
||||
m.PushScript(ssh.SCRIPT, link)
|
||||
m.PushAnchor(link)
|
||||
m.PushScript("shell", link)
|
||||
m.PushQRCode("scan", link)
|
||||
} else {
|
||||
m.Action(LOGIN)
|
||||
}
|
||||
m.PushAction(mdb.REMOVE)
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(0, "time,hash,userrole,username,river,storm,type,name,text")
|
||||
msg := m.Cmd(mdb.SELECT, SHARE, "", mdb.HASH, kit.MDB_HASH, kit.Select(m.Option(SHARE), arg, 0))
|
||||
|
||||
list := []string{SHARE, kit.Select(m.Option(SHARE), arg, 0)}
|
||||
for _, k := range []string{RIVER, STORM} {
|
||||
if msg.Append(k) != "" {
|
||||
list = append(list, k, msg.Append(k))
|
||||
}
|
||||
}
|
||||
|
||||
switch msg.Append(kit.MDB_TYPE) {
|
||||
case LOGIN, RIVER:
|
||||
m.RenderRedirect("/", list)
|
||||
|
||||
case STORM:
|
||||
m.RenderRedirect("/page/share.html", SHARE, m.Option(SHARE))
|
||||
|
||||
case FIELD:
|
||||
m.RenderDownload(path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), "/page/index.html"))
|
||||
m.OptionFields(m.Conf(SHARE, kit.META_FIELD))
|
||||
m.Option(SHARE, kit.Select(m.Option(SHARE), arg, 0))
|
||||
msg := m.Cmd(mdb.SELECT, m.Prefix(SHARE), "", mdb.HASH, kit.MDB_HASH, m.Option(SHARE))
|
||||
if kit.Int(msg.Append(kit.MDB_TIME)) < kit.Int(msg.FormatTime()) {
|
||||
m.RenderResult("共享超时")
|
||||
return
|
||||
}
|
||||
m.RenderIndex(SERVE, ice.VOLCANOS)
|
||||
}},
|
||||
|
||||
"/share/cache/": {Name: "/share/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
@ -17,7 +17,20 @@ import (
|
||||
)
|
||||
|
||||
func _space_link(m *ice.Message, pod string, arg ...interface{}) string {
|
||||
return kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/chat/pod/"+pod, arg...)
|
||||
return _share_link(m, "/chat/pod/"+pod, arg...)
|
||||
}
|
||||
func _space_domain(m *ice.Message) string {
|
||||
link := m.Conf(SHARE, kit.Keym(kit.MDB_DOMAIN))
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, SPIDE_DEV, cli.PWD).Append(kit.MDB_LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, SPIDE_SHY, cli.PWD).Append(kit.MDB_LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = kit.Format("http://localhost:%s", m.Cmd(SERVE).Append(tcp.PORT))
|
||||
}
|
||||
return tcp.ReplaceLocalhost(m, link)
|
||||
}
|
||||
func _space_list(m *ice.Message, space string) {
|
||||
if space == "" {
|
||||
@ -148,7 +161,7 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
|
||||
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe {
|
||||
msg.Go(func() { _space_exec(msg, source, target, c, name) })
|
||||
} else {
|
||||
msg.Push(kit.MDB_LINK, kit.MergePOD(_share_domain(msg), name))
|
||||
msg.Push(kit.MDB_LINK, kit.MergePOD(_space_domain(msg), name))
|
||||
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
|
||||
}
|
||||
|
||||
@ -288,7 +301,7 @@ func init() {
|
||||
}
|
||||
|
||||
m.Go(func(msg *ice.Message) {
|
||||
link := kit.MergeURL(_share_domain(msg), "grant", name)
|
||||
link := kit.MergeURL(_space_domain(msg), "grant", name)
|
||||
msg.Sleep("100ms").Cmd(SPACE, name, "pwd", name, link, msg.Cmdx(cli.QRCODE, link))
|
||||
})
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func init() {
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if strings.HasSuffix(m.R.URL.Path, "/") {
|
||||
m.RenderDownload(path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), m.Conf(CMD, kit.Keym(kit.MDB_INDEX))))
|
||||
m.RenderIndex(web.SERVE, ice.VOLCANOS)
|
||||
return // 目录
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
@ -31,14 +30,12 @@ func _header_check(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _header_share(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_LINK) == "" {
|
||||
share := m.Cmdx(web.SHARE, mdb.CREATE, kit.MDB_TYPE, web.LOGIN, arg)
|
||||
m.Option(kit.MDB_LINK, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/"+share))
|
||||
m.Cmdy(web.SHARE, mdb.CREATE, kit.MDB_TYPE, web.LOGIN, arg)
|
||||
}
|
||||
link := tcp.ReplaceLocalhost(m, m.Option(kit.MDB_LINK))
|
||||
|
||||
m.Set(kit.MDB_NAME, kit.MDB_TEXT)
|
||||
m.PushQRCode(kit.MDB_TEXT, link)
|
||||
m.Push(kit.MDB_NAME, link)
|
||||
m.Push(kit.MDB_NAME, m.Option(kit.MDB_LINK))
|
||||
m.PushQRCode(kit.MDB_TEXT, m.Option(kit.MDB_LINK))
|
||||
}
|
||||
func _header_grant(m *ice.Message, arg ...string) {
|
||||
if m.PodCmd(m.Prefix("/header"), ctx.ACTION, GRANT, arg) {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
@ -28,7 +26,7 @@ func init() {
|
||||
m.Cmdy(arg)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.RenderDownload(path.Join(m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), m.Conf(web.SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_INDEX))))
|
||||
m.RenderIndex(web.SERVE, ice.VOLCANOS)
|
||||
}},
|
||||
},
|
||||
Configs: map[string]*ice.Config{
|
||||
|
@ -98,7 +98,7 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, "./", "time,size,line,path,link")
|
||||
}},
|
||||
ice.CONTEXTS: {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) {
|
||||
u := kit.ParseURL(m.ReplaceLocalhost(m.Option(ice.MSG_USERWEB)))
|
||||
u := kit.ParseURL(tcp.ReplaceLocalhost(m, m.Option(ice.MSG_USERWEB)))
|
||||
host := u.Host
|
||||
|
||||
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(host, ":"), 1)))
|
||||
@ -109,7 +109,7 @@ func init() {
|
||||
m.Option("hostpath", kit.Path("./.ish/pluged"))
|
||||
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "tmux", "base", "miss", "binary", "source", "module")
|
||||
arg = append(arg, "tmux", "base", "miss", "binary", "source", "project")
|
||||
}
|
||||
for _, k := range arg {
|
||||
if buf, err := kit.Render(m.Conf(PUBLISH, kit.Keym(ice.CONTEXTS, k)), m); m.Assert(err) {
|
||||
@ -152,8 +152,8 @@ echo "hello world"
|
||||
}
|
||||
|
||||
var _contexts = kit.Dict(
|
||||
"module", `# 创建模块
|
||||
export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp module
|
||||
"project", `# 创建项目
|
||||
export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp project
|
||||
`,
|
||||
"source", `# 源码安装
|
||||
export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp source
|
||||
|
3
misc.go
3
misc.go
@ -159,6 +159,9 @@ func (m *Message) FormatChain() string {
|
||||
}
|
||||
return strings.Join(meta, "")
|
||||
}
|
||||
func (m *Message) FormatTime() string {
|
||||
return m.Format("time")
|
||||
}
|
||||
func (m *Message) Format(key interface{}) string {
|
||||
switch key := key.(type) {
|
||||
case []byte:
|
||||
|
@ -36,7 +36,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
switch m.Render(ice.RENDER_RESULT); m.R.URL.String() {
|
||||
switch m.RenderResult(); m.R.URL.String() {
|
||||
case "/qrcode", "/sess": // 登录入口
|
||||
return
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func init() {
|
||||
|
||||
switch _lark_parse(m); m.Option("msg.type") {
|
||||
case "url_verification": // 绑定验证
|
||||
m.Render(ice.RENDER_RESULT, kit.Format(kit.Dict("challenge", m.Option("msg.challenge"))))
|
||||
m.RenderResult(kit.Format(kit.Dict("challenge", m.Option("msg.challenge"))))
|
||||
|
||||
case "event_callback": // 事件回调
|
||||
m.Cmd(EVENT, m.Option(kit.MDB_TYPE))
|
||||
|
@ -39,7 +39,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
switch m.Render(ice.RENDER_RESULT); m.R.URL.String() {
|
||||
switch m.RenderResult(); m.R.URL.String() {
|
||||
case "/qrcode", "/input", "/sess": // 登录入口
|
||||
return
|
||||
}
|
||||
|
@ -42,8 +42,7 @@ func _wx_reply(m *ice.Message, tmpl string) {
|
||||
}
|
||||
}
|
||||
func _wx_action(m *ice.Message) {
|
||||
m.Option(ice.MSG_OUTPUT, ice.RENDER_RESULT)
|
||||
m.Set(ice.MSG_RESULT)
|
||||
m.RenderResult().Set(ice.MSG_RESULT)
|
||||
|
||||
m.Echo(`<xml>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
@ -98,7 +97,7 @@ func init() {
|
||||
return // 验证失败
|
||||
}
|
||||
if m.Option("echostr") != "" {
|
||||
m.Render(ice.RENDER_RESULT, m.Option("echostr"))
|
||||
m.RenderResult(m.Option("echostr"))
|
||||
return // 绑定验证
|
||||
}
|
||||
|
||||
|
12
render.go
12
render.go
@ -1,6 +1,7 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
kit "github.com/shylinux/toolkits"
|
||||
@ -104,12 +105,6 @@ func (m *Message) IsCliUA() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func (m *Message) ReplaceLocalhost(url string) string {
|
||||
if strings.Contains(url, "://localhost") {
|
||||
return strings.Replace(url, "localhost", m.Cmd("tcp.host").Append("ip"), 1)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
func (m *Message) Render(cmd string, args ...interface{}) *Message {
|
||||
m.Optionv(MSG_OUTPUT, cmd)
|
||||
@ -130,7 +125,6 @@ func (m *Message) RenderResult(args ...interface{}) *Message {
|
||||
return m.Render(RENDER_RESULT, args...)
|
||||
}
|
||||
func (m *Message) RenderTemplate(args ...interface{}) *Message {
|
||||
|
||||
return m.Render(RENDER_TEMPLATE, args...)
|
||||
}
|
||||
func (m *Message) RenderDownload(args ...interface{}) *Message {
|
||||
@ -139,6 +133,6 @@ func (m *Message) RenderDownload(args ...interface{}) *Message {
|
||||
func (m *Message) RenderRedirect(args ...interface{}) *Message {
|
||||
return m.Render(RENDER_REDIRECT, args...)
|
||||
}
|
||||
func (m *Message) RenderIndex(serve, repos string) *Message {
|
||||
return m.RenderDownload(kit.Path(m.Conf(serve, kit.Keym(repos, kit.SSH_PATH)), m.Conf(serve, kit.Keym(repos, kit.SSH_INDEX))))
|
||||
func (m *Message) RenderIndex(serve, repos string, file ...string) *Message {
|
||||
return m.RenderDownload(kit.Path(m.Conf(serve, kit.Keym(repos, kit.SSH_PATH)), kit.Select(m.Conf(serve, kit.Keym(repos, kit.SSH_INDEX)), path.Join(file...))))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user