mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 18:22:02 +08:00
opt iml
This commit is contained in:
parent
debdfaae1c
commit
e69f39a8af
@ -3,7 +3,6 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -80,7 +79,7 @@ func _system_find(m *ice.Message, bin string, dir ...string) string {
|
|||||||
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
|
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
|
||||||
}
|
}
|
||||||
for _, p := range dir {
|
for _, p := range dir {
|
||||||
if _, err := os.Stat(path.Join(p, bin)); err == nil {
|
if kit.FileExists(path.Join(p, bin)) {
|
||||||
return kit.Path(path.Join(p, bin))
|
return kit.Path(path.Join(p, bin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,8 @@ const (
|
|||||||
SH = ice.SH
|
SH = ice.SH
|
||||||
CSV = ice.CSV
|
CSV = ice.CSV
|
||||||
JSON = ice.JSON
|
JSON = ice.JSON
|
||||||
|
YML = "yml"
|
||||||
|
IML = "iml"
|
||||||
TXT = "txt"
|
TXT = "txt"
|
||||||
SHY = "shy"
|
SHY = "shy"
|
||||||
SVG = "svg"
|
SVG = "svg"
|
||||||
@ -162,8 +164,8 @@ func init() {
|
|||||||
SOURCE, kit.Dict(
|
SOURCE, kit.Dict(
|
||||||
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
HTML, ice.TRUE, CSS, ice.TRUE, JS, ice.TRUE, GO, ice.TRUE, SH, ice.TRUE, CSV, ice.TRUE, JSON, ice.TRUE,
|
||||||
"md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
|
"md", ice.TRUE, "shy", ice.TRUE, "makefile", ice.TRUE, "license", ice.TRUE,
|
||||||
"conf", ice.TRUE, "yaml", ice.TRUE, "yml", ice.TRUE,
|
"conf", ice.TRUE, YML, ice.TRUE, IML, ice.TRUE, "txt", ice.TRUE,
|
||||||
"py", ice.TRUE, "txt", ice.TRUE,
|
"py", ice.TRUE,
|
||||||
),
|
),
|
||||||
)},
|
)},
|
||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
|
@ -11,13 +11,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _defs_file(m *ice.Message, name string, text ...string) {
|
func _defs_file(m *ice.Message, name string, text ...string) {
|
||||||
if _, e := os.Stat(path.Join(m.Option(DIR_ROOT), name)); os.IsNotExist(e) {
|
if kit.FileExists(path.Join(m.Option(DIR_ROOT), name)) {
|
||||||
for i, v := range text {
|
return
|
||||||
b, _ := kit.Render(v, m)
|
|
||||||
text[i] = string(b)
|
|
||||||
}
|
|
||||||
_save_file(m, name, text...)
|
|
||||||
}
|
}
|
||||||
|
for i, v := range text {
|
||||||
|
b, _ := kit.Render(v, m)
|
||||||
|
text[i] = string(b)
|
||||||
|
}
|
||||||
|
_save_file(m, name, text...)
|
||||||
}
|
}
|
||||||
func _save_file(m *ice.Message, name string, text ...string) {
|
func _save_file(m *ice.Message, name string, text ...string) {
|
||||||
if f, p, e := kit.Create(path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
if f, p, e := kit.Create(path.Join(m.Option(DIR_ROOT), name)); m.Assert(e) {
|
||||||
@ -105,7 +106,7 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
COPY: {Name: "copy file from...", Help: "复制", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
COPY: {Name: "copy file from...", Help: "复制", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
for _, file := range arg[1:] {
|
for _, file := range arg[1:] {
|
||||||
if _, e := os.Stat(file); e == nil {
|
if kit.FileExists(file) {
|
||||||
_copy_file(m, arg[0], arg[1:]...)
|
_copy_file(m, arg[0], arg[1:]...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package tcp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
@ -27,7 +26,7 @@ func _port_right(m *ice.Message, arg ...string) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), kit.Format(i))
|
p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), kit.Format(i))
|
||||||
if _, e := os.Stat(p); e == nil {
|
if kit.FileExists(p) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
nfs.MkdirAll(m, p)
|
nfs.MkdirAll(m, p)
|
||||||
|
@ -28,7 +28,7 @@ func _share_repos(m *ice.Message, repos string, arg ...string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
|
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
|
||||||
if _, e := os.Stat(path.Join(prefix, repos)); e != nil { // 克隆代码
|
if !kit.FileExists(path.Join(prefix, repos)) { // 克隆代码
|
||||||
m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos))
|
m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos))
|
||||||
}
|
}
|
||||||
m.RenderDownload(path.Join(prefix, repos, path.Join(arg...)))
|
m.RenderDownload(path.Join(prefix, repos, path.Join(arg...)))
|
||||||
|
@ -26,14 +26,16 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int
|
|||||||
if text == "" {
|
if text == "" {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option(nfs.CAT_CONTENT, text)
|
m.Option(nfs.CAT_CONTENT, text)
|
||||||
river, storm, last := kit.Dict(
|
river, storm, last := kit.Dict(
|
||||||
"Header", kit.Dict("menus", kit.List(), "style", kit.Dict("display", "none")),
|
"Header", kit.Dict("menus", kit.List(), "style", kit.Dict("display", "none")),
|
||||||
"River", kit.Dict("menus", kit.List(), "action", kit.List()),
|
"River", kit.Dict("menus", kit.List(), "action", kit.List()),
|
||||||
"Action", kit.Dict("menus", kit.List(), "action", kit.List(), "legend_event", "onclick"),
|
"Action", kit.Dict("menus", kit.List(), "action", kit.List(), "legend_event", "onclick"),
|
||||||
"Footer", kit.Dict("style", kit.Dict("display", "none")),
|
"Footer", kit.Dict("style", kit.Dict("display", "none")), args,
|
||||||
args,
|
|
||||||
), kit.Dict(), kit.Dict()
|
), kit.Dict(), kit.Dict()
|
||||||
|
prefix := ""
|
||||||
|
|
||||||
m.Cmd(lex.SPLIT, "", mdb.KEY, mdb.NAME, func(deep int, ls []string, meta map[string]interface{}) []string {
|
m.Cmd(lex.SPLIT, "", mdb.KEY, mdb.NAME, func(deep int, ls []string, meta map[string]interface{}) []string {
|
||||||
data := kit.Dict()
|
data := kit.Dict()
|
||||||
switch display := ice.DisplayRequire(1, ls[0])[ctx.DISPLAY]; kit.Ext(ls[0]) {
|
switch display := ice.DisplayRequire(1, ls[0])[ctx.DISPLAY]; kit.Ext(ls[0]) {
|
||||||
@ -71,11 +73,27 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int
|
|||||||
}
|
}
|
||||||
data[ctx.ARGS] = kit.List(ls[0])
|
data[ctx.ARGS] = kit.List(ls[0])
|
||||||
ls[0] = key
|
ls[0] = key
|
||||||
|
case nfs.SHY:
|
||||||
|
data[ctx.ARGS] = kit.List(ls[0])
|
||||||
|
data[mdb.NAME] = kit.TrimExt(ls[0], ".shy")
|
||||||
|
if data[mdb.NAME] == "main" {
|
||||||
|
data[mdb.NAME] = strings.TrimSuffix(strings.Split(ls[0], ice.PS)[1], "-story")
|
||||||
|
}
|
||||||
|
ls[0] = "web.wiki.word"
|
||||||
|
case "~":
|
||||||
|
prefix = ls[1]
|
||||||
|
ls = ls[1:]
|
||||||
|
fallthrough
|
||||||
|
case "-":
|
||||||
|
for _, v := range ls[1:] {
|
||||||
|
last[mdb.LIST] = append(last[mdb.LIST].([]interface{}), kit.Dict(mdb.INDEX, kit.Keys(prefix, v), "order", len(last)))
|
||||||
|
}
|
||||||
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
if ls[0] == "" {
|
if ls[0] == "" {
|
||||||
return ls
|
return ls
|
||||||
} else if len(ls) == 1 && deep == 3 {
|
} else if len(ls) == 1 && deep > 2 {
|
||||||
ls = append(ls, m.Cmd(ctx.COMMAND, ls[0]).Append(mdb.HELP))
|
ls = append(ls, m.Cmd(ctx.COMMAND, ls[0]).Append(mdb.HELP))
|
||||||
} else if len(ls) == 1 {
|
} else if len(ls) == 1 {
|
||||||
ls = append(ls, ls[0])
|
ls = append(ls, ls[0])
|
||||||
@ -96,16 +114,18 @@ func _website_parse(m *ice.Message, text string, args ...string) (map[string]int
|
|||||||
data[ls[i]] = ls[i+1]
|
data[ls[i]] = ls[i+1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch deep {
|
switch deep {
|
||||||
case 1:
|
case 1:
|
||||||
storm = kit.Dict()
|
storm = kit.Dict()
|
||||||
river[ls[0]] = kit.Dict(mdb.NAME, ls[1], STORM, storm, data)
|
river[ls[0]] = kit.Dict(mdb.NAME, ls[1], STORM, storm, data, "order", len(river))
|
||||||
case 2:
|
case 2:
|
||||||
last = kit.Dict(mdb.NAME, ls[1], mdb.LIST, kit.List(), data)
|
last = kit.Dict(mdb.NAME, ls[1], mdb.LIST, kit.List(), data, "order", len(storm))
|
||||||
storm[ls[0]] = last
|
storm[ls[0]] = last
|
||||||
|
prefix = ""
|
||||||
default:
|
default:
|
||||||
last[mdb.LIST] = append(last[mdb.LIST].([]interface{}),
|
last[mdb.LIST] = append(last[mdb.LIST].([]interface{}),
|
||||||
kit.Dict(mdb.NAME, ls[0], mdb.HELP, ls[1], mdb.INDEX, ls[0], data))
|
kit.Dict(mdb.NAME, kit.Select(ls[0], data[mdb.NAME]), mdb.HELP, ls[1], mdb.INDEX, ls[0], "order", len(last), data))
|
||||||
}
|
}
|
||||||
return ls
|
return ls
|
||||||
})
|
})
|
||||||
@ -123,7 +143,7 @@ func _website_render(m *ice.Message, w http.ResponseWriter, r *http.Request, kin
|
|||||||
r.URL.Path = "/chat/cmd/web.chat.div"
|
r.URL.Path = "/chat/cmd/web.chat.div"
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case nfs.TXT:
|
case nfs.IML, nfs.TXT:
|
||||||
res, _ := _website_parse(msg, text)
|
res, _ := _website_parse(msg, text)
|
||||||
msg.RenderResult(_website_template2, kit.Format(res))
|
msg.RenderResult(_website_template2, kit.Format(res))
|
||||||
case nfs.JSON:
|
case nfs.JSON:
|
||||||
@ -151,6 +171,8 @@ func init() {
|
|||||||
}, Commands: map[string]*ice.Command{
|
}, Commands: map[string]*ice.Command{
|
||||||
WEBSITE: {Name: "website path auto create import", Help: "网站", Action: ice.MergeAction(map[string]*ice.Action{
|
WEBSITE: {Name: "website path auto create import", Help: "网站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.IML, m.PrefixKey())
|
||||||
|
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.IML, m.PrefixKey())
|
||||||
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
m.Cmd(mdb.RENDER, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
||||||
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
m.Cmd(mdb.ENGINE, mdb.CREATE, nfs.TXT, m.PrefixKey())
|
||||||
|
|
||||||
@ -191,11 +213,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
mdb.CREATE: {Name: "create path type=txt,json,js,html name text", Help: "创建"},
|
mdb.CREATE: {Name: "create path type=iml,json,js,html name text", Help: "创建"},
|
||||||
mdb.IMPORT: {Name: "import path=src/website/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
mdb.IMPORT: {Name: "import path=src/website/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
|
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
|
||||||
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) {
|
switch name := strings.TrimPrefix(p, m.Option(nfs.PATH)); kit.Ext(p) {
|
||||||
case nfs.HTML, nfs.JS, nfs.JSON, nfs.TXT:
|
case nfs.HTML, nfs.JS, nfs.JSON, nfs.IML, nfs.TXT:
|
||||||
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
|
m.Cmd(m.PrefixKey(), mdb.CREATE, nfs.PATH, ice.PS+name,
|
||||||
mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, m.Cmdx(nfs.CAT, p))
|
mdb.TYPE, kit.Ext(p), mdb.NAME, name, mdb.TEXT, m.Cmdx(nfs.CAT, p))
|
||||||
default:
|
default:
|
||||||
|
@ -71,8 +71,8 @@ func init() {
|
|||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
ice.Dump = func(w io.Writer, name string, cb func(string)) bool {
|
ice.Dump = func(w io.Writer, name string, cb func(string)) bool {
|
||||||
for _, key := range []string{name, strings.TrimPrefix(name, ice.USR_VOLCANOS)} {
|
for _, key := range []string{name, strings.TrimPrefix(name, ice.USR_VOLCANOS)} {
|
||||||
if key == "/page/index.html" && kit.FileExists("src/website/index.txt") {
|
if key == "/page/index.html" && kit.FileExists("src/website/index.iml") {
|
||||||
if s := m.Cmdx("web.chat.website", "show", "index.txt", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" {
|
if s := m.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" {
|
||||||
fmt.Fprint(w, s)
|
fmt.Fprint(w, s)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -91,8 +91,8 @@ func init() {
|
|||||||
if kit.FileExists(path.Join(ice.USR_VOLCANOS, ice.PROTO_JS)) {
|
if kit.FileExists(path.Join(ice.USR_VOLCANOS, ice.PROTO_JS)) {
|
||||||
m.Cmd(BINPACK, mdb.REMOVE)
|
m.Cmd(BINPACK, mdb.REMOVE)
|
||||||
}
|
}
|
||||||
if kit.FileExists("src/website/index.txt") {
|
if kit.FileExists("src/website/index.iml") {
|
||||||
if s := m.Cmdx("web.chat.website", "show", "index.txt", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" {
|
if s := m.Cmdx("web.chat.website", "show", "index.iml", "Header", "", "River", "", "Action", "", "Footer", ""); s != "" {
|
||||||
ice.Info.Pack["/page/index.html"] = []byte(s)
|
ice.Info.Pack["/page/index.html"] = []byte(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _c_tags(m *ice.Message, key string) {
|
func _c_tags(m *ice.Message, key string) {
|
||||||
if _, e := os.Stat(path.Join(m.Option(cli.CMD_DIR), TAGS)); e != nil {
|
if !kit.FileExists(path.Join(m.Option(cli.CMD_DIR), TAGS)) {
|
||||||
m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", TAGS, nfs.PWD)
|
m.Cmd(cli.SYSTEM, "ctags", "-R", "-f", TAGS, nfs.PWD)
|
||||||
}
|
}
|
||||||
_go_tags(m, key)
|
_go_tags(m, key)
|
||||||
|
@ -48,7 +48,6 @@ func _publish_bin_list(m *ice.Message, dir string) {
|
|||||||
m.Push(nfs.SIZE, kit.FmtSize(s.Size()))
|
m.Push(nfs.SIZE, kit.FmtSize(s.Size()))
|
||||||
m.Push(nfs.FILE, file)
|
m.Push(nfs.FILE, file)
|
||||||
m.PushDownload(mdb.LINK, file, path.Join(p, file))
|
m.PushDownload(mdb.LINK, file, path.Join(p, file))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func init() {
|
|||||||
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
||||||
m.Cmdy(TEMPLATE, nfs.DEFS)
|
m.Cmdy(TEMPLATE, nfs.DEFS)
|
||||||
}},
|
}},
|
||||||
"website": {Name: "script file=hi.txt text=", Help: "网页", Hand: func(m *ice.Message, arg ...string) {
|
"website": {Name: "script file=hi.iml text=", Help: "网页", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(nfs.FILE, path.Join("website", m.Option(nfs.FILE)))
|
m.Option(nfs.FILE, path.Join("website", m.Option(nfs.FILE)))
|
||||||
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
m.Option(mdb.TEXT, strings.TrimSpace(m.Option(mdb.TEXT)))
|
||||||
m.Cmdy(TEMPLATE, nfs.DEFS)
|
m.Cmdy(TEMPLATE, nfs.DEFS)
|
||||||
|
@ -78,12 +78,12 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.OptionFields(mdb.ZONE, "time,id,type,name,text,level,status,score,begin_time,close_time")
|
m.OptionFields(mdb.ZONE, "time,id,type,name,text,level,status,score,begin_time,close_time")
|
||||||
m.Cmdy(mdb.EXPORT, m.PrefixKey(), "", mdb.ZONE)
|
m.Cmdy(mdb.EXPORT, m.Prefix(TASK), "", mdb.ZONE)
|
||||||
m.ProcessRefresh30ms()
|
m.ProcessRefresh30ms()
|
||||||
}},
|
}},
|
||||||
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.OptionFields(mdb.ZONE)
|
m.OptionFields(mdb.ZONE)
|
||||||
m.Cmdy(mdb.IMPORT, m.PrefixKey(), "", mdb.ZONE)
|
m.Cmdy(mdb.IMPORT, m.Prefix(TASK), "", mdb.ZONE)
|
||||||
m.ProcessRefresh30ms()
|
m.ProcessRefresh30ms()
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
5
misc.go
5
misc.go
@ -16,10 +16,7 @@ func (m *Message) Length() (max int) {
|
|||||||
max = l
|
max = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if max > 0 {
|
return max
|
||||||
return max
|
|
||||||
}
|
|
||||||
return len(m.Resultv())
|
|
||||||
}
|
}
|
||||||
func (m *Message) CSV(text string, head ...string) *Message {
|
func (m *Message) CSV(text string, head ...string) *Message {
|
||||||
bio := bytes.NewBufferString(text)
|
bio := bytes.NewBufferString(text)
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -122,13 +121,28 @@ func init() {
|
|||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||||
if p := r.URL.Path; strings.HasPrefix(p, "/x/") {
|
if p := r.URL.Path; strings.HasPrefix(p, "/x/") {
|
||||||
r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", -1)
|
if ls := strings.Split(p, ice.PS); m.Cmd(web.DREAM, ls[2]).Length() > 0 {
|
||||||
|
if m.IsCliUA() {
|
||||||
|
r.URL.RawQuery += kit.Select("", "&", len(r.URL.RawQuery) > 1) + "pod=" + ls[2]
|
||||||
|
r.URL.Path = "/share/local/bin/ice.bin"
|
||||||
|
} else {
|
||||||
|
r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/chat/pod/", 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", 1)
|
||||||
|
}
|
||||||
|
|
||||||
m.Info("rewrite %v -> %v", p, r.URL.Path)
|
m.Info("rewrite %v -> %v", p, r.URL.Path)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
if !m.IsCliUA() {
|
||||||
|
p := kit.Split(m.MergeURL2("/x/"+path.Join(arg...)), "?")[0]
|
||||||
|
m.RenderResult("git clone %v", p)
|
||||||
|
return
|
||||||
|
}
|
||||||
if m.Option("go-get") == "1" { // 下载地址
|
if m.Option("go-get") == "1" { // 下载地址
|
||||||
p := kit.Split(m.MergeURL2("/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)))
|
m.RenderResult(kit.Format(`<meta name="%s" content="%s">`, "go-import", kit.Format(`%s git %s`, strings.TrimPrefix(p, "https://"), p)))
|
||||||
@ -142,11 +156,14 @@ func init() {
|
|||||||
web.RenderStatus(m, 401, err.Error())
|
web.RenderStatus(m, 401, err.Error())
|
||||||
return // 没有权限
|
return // 没有权限
|
||||||
}
|
}
|
||||||
if _, e := os.Stat(path.Join(repos)); os.IsNotExist(e) {
|
if !kit.FileExists(path.Join(repos)) {
|
||||||
m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", repos) // 创建仓库
|
m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", repos) // 创建仓库
|
||||||
m.Log_CREATE(REPOS, repos)
|
m.Log_CREATE(REPOS, repos)
|
||||||
}
|
}
|
||||||
case "upload-pack": // 下载代码
|
case "upload-pack": // 下载代码
|
||||||
|
if !kit.FileExists(path.Join(repos)) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := _server_repos(m, arg...); err != nil {
|
if err := _server_repos(m, arg...); err != nil {
|
||||||
|
@ -45,7 +45,7 @@ func _ssh_open(m *ice.Message, arg ...string) {
|
|||||||
}
|
}
|
||||||
func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) {
|
func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) {
|
||||||
p := path.Join(kit.Env(cli.HOME), ".ssh/", fmt.Sprintf("%s@%s:%s", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
p := path.Join(kit.Env(cli.HOME), ".ssh/", fmt.Sprintf("%s@%s:%s", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||||
if _, e := os.Stat(p); e == nil {
|
if kit.FileExists(p) {
|
||||||
if c, e := net.Dial("unix", p); e == nil {
|
if c, e := net.Dial("unix", p); e == nil {
|
||||||
cb(c) // 会话连接
|
cb(c) // 会话连接
|
||||||
return
|
return
|
||||||
|
@ -157,7 +157,7 @@ func (m *Message) PushNotice(arg ...interface{}) {
|
|||||||
if m.Option(MSG_USERPOD) == "" {
|
if m.Option(MSG_USERPOD) == "" {
|
||||||
m.Cmd(SPACE, m.Option(MSG_DAEMON), arg)
|
m.Cmd(SPACE, m.Option(MSG_DAEMON), arg)
|
||||||
} else {
|
} else {
|
||||||
m.Cmd(SPIDE, DEV, m.MergeURL2("/share/toast/"), kit.Format(kit.Dict(POD, m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
|
m.Cmd("web.spide", OPS, m.MergeURL2("/share/toast/"), kit.Format(kit.Dict(POD, m.Option(MSG_DAEMON), "cmds", kit.Simple(arg...))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (m *Message) PushNoticeGrow(arg ...interface{}) {
|
func (m *Message) PushNoticeGrow(arg ...interface{}) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user