forked from x/icebergs
opt some
This commit is contained in:
parent
ccf3839fd0
commit
231fd0d857
@ -106,23 +106,24 @@ func _cache_download(m *ice.Message, r *http.Response) (file, size string) {
|
||||
|
||||
total := kit.Int(kit.Select("1", r.Header.Get("Content-Length")))
|
||||
if f, p, e := kit.Create(path.Join("var/tmp", kit.Hashs("uniq"))); m.Assert(e) {
|
||||
size, buf := 0, make([]byte, 81920)
|
||||
size, buf := 0, make([]byte, 1024)
|
||||
for {
|
||||
if n, e := r.Body.Read(buf); e == nil {
|
||||
if n, _ := r.Body.Read(buf); n > 0 {
|
||||
f.Write(buf[0:n])
|
||||
size += n
|
||||
m.Log_IMPORT(kit.MDB_FILE, p, "per", size*100/total, kit.MDB_SIZE, kit.FmtSize(int64(size)), "total", kit.FmtSize(int64(total)))
|
||||
} else if e == io.EOF {
|
||||
f.Close()
|
||||
break
|
||||
} else {
|
||||
f.Close()
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Log_IMPORT(kit.MDB_FILE, p, kit.MDB_SIZE, kit.FmtSize(int64(size)))
|
||||
c := _cache_name(m, kit.Hashs(f))
|
||||
m.Cmd(nfs.LINK, c, p)
|
||||
return c, kit.Format(size)
|
||||
if f, e := os.Open(p); m.Assert(e) {
|
||||
defer f.Close()
|
||||
m.Log_IMPORT(kit.MDB_FILE, p, kit.MDB_SIZE, kit.FmtSize(int64(size)))
|
||||
c := _cache_name(m, kit.Hashs(f))
|
||||
m.Cmd(nfs.LINK, c, p)
|
||||
return c, kit.Format(size)
|
||||
}
|
||||
}
|
||||
return "", "0"
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ const ( // CODE
|
||||
|
||||
var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
Configs: map[string]*ice.Config{
|
||||
INSTALL: {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install",
|
||||
INSTALL: {Name: "install", Help: "安装", Value: kit.Data(
|
||||
"path", "usr/install", "target", "usr/local",
|
||||
"linux", "https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz",
|
||||
"darwin", "https://dl.google.com/go/go1.14.2.darwin-amd64.pkg",
|
||||
"windows", "https://dl.google.com/go/go1.14.2.windows-amd64.msi",
|
||||
"source", "https://dl.google.com/go/go1.14.2.src.tar.gz",
|
||||
"target", "usr/local",
|
||||
"darwin", "https://dl.google.com/go/go1.14.6.darwin-amd64.tar.gz",
|
||||
"windows", "https://golang.google.cn/dl/go1.14.6.windows-amd64.zip",
|
||||
)},
|
||||
PREPARE: {Name: "prepare", Help: "配置", Value: kit.Data("path", "usr/prepare",
|
||||
"script", ".ish/pluged/golang/init.sh", "export", kit.Dict(
|
||||
@ -51,20 +50,17 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
m.Save("login")
|
||||
}},
|
||||
|
||||
INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
INSTALL: {Name: "install url 安装:button", Help: "安装", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
target := m.Conf(INSTALL, kit.Keys("meta", runtime.GOOS))
|
||||
p := path.Join(m.Conf(INSTALL, "meta.path"), path.Base(target))
|
||||
|
||||
p := path.Join(m.Conf(INSTALL, "meta.path"), path.Base(target))
|
||||
if _, e := os.Stat(p); e != nil {
|
||||
// 下载
|
||||
m.Option(cli.CMD_DIR, m.Conf(INSTALL, "meta.path"))
|
||||
msg := m.Cmd(web.SPIDE, web.CACHE, http.MethodGet, target)
|
||||
msg := m.Cmd(web.SPIDE, "dev", web.CACHE, http.MethodGet, target)
|
||||
m.Cmd(web.CACHE, web.WATCH, msg.Append(web.DATA), p)
|
||||
}
|
||||
|
||||
// 安装
|
||||
m.Option(cli.CMD_DIR, "")
|
||||
os.MkdirAll(m.Conf(INSTALL, kit.Keys("meta.target")), 0777)
|
||||
os.MkdirAll(m.Conf(INSTALL, kit.Keys("meta.target")), ice.MOD_DIR)
|
||||
m.Cmdy(cli.SYSTEM, "tar", "xvf", p, "-C", m.Conf(INSTALL, kit.Keys("meta.target")))
|
||||
}},
|
||||
PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user