diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go
index 3666fd90..2f1a669d 100644
--- a/base/nfs/nfs.go
+++ b/base/nfs/nfs.go
@@ -93,6 +93,14 @@ func _file_list(m *ice.Message, root string, name string, level int, deep bool,
}
case "name":
m.Push("name", f.Name())
+ case "link":
+ if f.IsDir() {
+ m.Push("link", "")
+ } else {
+ m.Push("link", m.Cmdx("mdb.render", "download",
+ kit.MergeURL(path.Join("/share/local/", root, name, f.Name()), "pod", m.Option("user.pod")), f.Name()))
+ }
+
case "tree":
if level == 0 {
m.Push("tree", f.Name())
@@ -200,6 +208,7 @@ func _file_copy(m *ice.Message, name string, from ...string) {
}
func _file_link(m *ice.Message, name string, from string) {
os.MkdirAll(path.Dir(name), 0760)
+ os.Remove(name)
os.Link(from, name)
m.Echo(name)
}
@@ -321,7 +330,16 @@ var Index = &ice.Context{Name: "nfs", Help: "存储模块",
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
}},
- DIR: {Name: "dir path field...", Help: "目录", Action: map[string]*ice.Action{
+ DIR: {Name: "dir path=auto field... 查看:button=auto 返回 上传", Help: "目录", Action: map[string]*ice.Action{
+ "upload": {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
+ if m.Cmdy("cache", "upload"); m.Option("pod") == "" {
+ m.Cmdy("cache", "watch", m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
+ return
+ }
+ m.Cmdy("space", m.Option("pod"), "spide", "dev", "save", path.Join(m.Option("path"), m.Option("name")),
+ kit.MergeURL2(m.Option(ice.MSG_USERWEB), path.Join("/share/local/", m.Option("data"))))
+
+ }},
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_file_search(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
diff --git a/base/web/cache.go b/base/web/cache.go
index ea1023e5..2e253025 100644
--- a/base/web/cache.go
+++ b/base/web/cache.go
@@ -32,6 +32,9 @@ func _cache_list(m *ice.Message, key string) {
})
}
func _cache_save(m *ice.Message, kind, name, text string, arg ...string) { // file size
+ if name == "" {
+ return
+ }
if len(text) > 512 {
// 存入文件
p := m.Cmdx(nfs.SAVE, _cache_name(m, kit.Hashs(text)), text)
@@ -84,7 +87,7 @@ func _cache_catch(m *ice.Message, name string) (file, size string) {
return "", "0"
}
func _cache_upload(m *ice.Message, r *http.Request) (kind, name, file, size string) {
- if buf, h, e := r.FormFile(UPLOAD); m.Assert(e) {
+ if buf, h, e := r.FormFile(UPLOAD); e == nil {
defer buf.Close()
// 创建文件
diff --git a/base/web/render.go b/base/web/render.go
index df3f1f8b..471d1500 100644
--- a/base/web/render.go
+++ b/base/web/render.go
@@ -147,8 +147,7 @@ func init() {
m.Echo(``, arg[0])
}},
RENDER.Download: {Hand: func(m *ice.Message, arg ...string) {
- u := kit.Select(arg[0], arg, 1)
- m.Echo(`%s`, u, path.Base(arg[0]), arg[0])
+ m.Echo(`%s`, arg[0], kit.Select(path.Base(arg[0]), arg, 1), kit.Select(arg[0], arg, 1))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == mdb.RENDER {
diff --git a/base/web/share.go b/base/web/share.go
index eab8e2cb..dcd83558 100644
--- a/base/web/share.go
+++ b/base/web/share.go
@@ -12,6 +12,7 @@ import (
"os"
"path"
"strings"
+ "time"
)
func _share_list(m *ice.Message, key string, fields ...string) {
@@ -70,8 +71,16 @@ func _share_local(m *ice.Message, arg ...string) {
p := path.Join(arg...)
if m.Option("pod") != "" {
// 远程文件
- m.Cmdy(SPACE, m.Option("pod"), "nfs.cat", p)
- m.Render(ice.RENDER_RESULT)
+
+ pp := path.Join("var/proxy", m.Option("pod"), p)
+ cache := time.Now().Add(-time.Hour * 240000)
+ if s, e := os.Stat(pp); e == nil {
+ cache = s.ModTime()
+ }
+ m.Cmdy(SPACE, m.Option("pod"), SPIDE, "dev", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
+ "part", "pod", m.Option("pod"), "path", p, "cache", cache.Format(ice.MOD_TIME), "upload", "@"+p)
+
+ m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", m.Option("pod"), p))
return
}
@@ -83,6 +92,10 @@ func _share_local(m *ice.Message, arg ...string) {
// 本地文件
m.Render(ice.RENDER_DOWNLOAD, p)
}
+func _share_proxy(m *ice.Message, arg ...string) {
+ m.Cmdy(CACHE, UPLOAD)
+ m.Cmdy(CACHE, WATCH, m.Option("data"), path.Join("var/proxy", m.Option("pod"), m.Option("path")))
+}
func _share_remote(m *ice.Message, pod string, arg ...string) {
m.Cmdy(SPACE, pod, "web./publish/", arg)
m.Render(ice.RENDER_RESULT)
@@ -255,6 +268,9 @@ func init() {
"/share/local/": {Name: "/share/local/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_local(m, arg...)
}},
+ "/share/proxy/": {Name: "/share/proxy/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
+ _share_proxy(m, arg...)
+ }},
"/share/": {Name: "/share/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Richs(SHARE, nil, kit.Select(m.Option(kit.MDB_SHARE), arg, 0), func(key string, value map[string]interface{}) {
m.Log_SELECT(kit.MDB_META, SHARE, "arg", arg, "value", kit.Format(value))
diff --git a/base/web/spide.go b/base/web/spide.go
index 98ee4eeb..ea77e512 100644
--- a/base/web/spide.go
+++ b/base/web/spide.go
@@ -17,6 +17,7 @@ import (
"os"
"path"
"strings"
+ "time"
)
func _spide_list(m *ice.Message, name string) {
@@ -110,6 +111,7 @@ const (
SPIDE_MSG = "msg"
SPIDE_RAW = "raw"
+ SPIDE_SAVE = "save"
SPIDE_CACHE = "cache"
SPIDE_GET = "GET"
@@ -163,12 +165,14 @@ func init() {
m.Richs(SPIDE, nil, arg[0], func(key string, value map[string]interface{}) {
client := value[SPIDE_CLIENT].(map[string]interface{})
// 缓存数据
- cache := ""
+ cache, save := "", ""
switch arg[1] {
case SPIDE_MSG:
cache, arg = arg[1], arg[1:]
case SPIDE_RAW:
cache, arg = arg[1], arg[1:]
+ case SPIDE_SAVE:
+ cache, save, arg = arg[1], arg[2], arg[2:]
case SPIDE_CACHE:
cache, arg = arg[1], arg[1:]
}
@@ -206,8 +210,19 @@ func init() {
case SPIDE_PART:
buf := &bytes.Buffer{}
mp := multipart.NewWriter(buf)
+ cache := time.Now().Add(-time.Hour * 240000)
for i := 1; i < len(arg)-1; i += 2 {
+ if arg[i] == "cache" {
+ if t, e := time.ParseInLocation(ice.MOD_TIME, arg[i+1], time.Local); e == nil {
+ cache = t
+ }
+ }
if strings.HasPrefix(arg[i+1], "@") {
+ if s, e := os.Stat(arg[i+1][1:]); e == nil {
+ if s.ModTime().Before(cache) {
+ return
+ }
+ }
if f, e := os.Open(arg[i+1][1:]); m.Assert(e) {
defer f.Close()
if p, e := mp.CreateFormFile(arg[i], path.Base(arg[i+1][1:])); m.Assert(e) {
@@ -296,12 +311,19 @@ func init() {
m.Log(ice.LOG_IMPORT, "%s: %s", v.Name, v.Value)
}
+ defer res.Body.Close()
+
// 解析引擎
switch cache {
case SPIDE_CACHE:
m.Optionv("response", res)
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri)
m.Echo(m.Append(DATA))
+ case SPIDE_SAVE:
+ if f, p, e := kit.Create(save); m.Assert(e) {
+ io.Copy(f, res.Body)
+ m.Echo(p)
+ }
case SPIDE_RAW:
if b, e := ioutil.ReadAll(res.Body); m.Assert(e) {
m.Echo(string(b))