1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-10-27 00:19:06 +08:00
parent d9a44bedc5
commit adbf04964e
8 changed files with 58 additions and 19 deletions

View File

@ -248,7 +248,7 @@ func HashSelectValue(m *ice.Message, cb Any) *ice.Message {
} }
func HashSelectUpdate(m *ice.Message, key string, cb Any) *ice.Message { func HashSelectUpdate(m *ice.Message, key string, cb Any) *ice.Message {
defer Lock(m, m.PrefixKey())() defer Lock(m, m.PrefixKey())()
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) }) Richs(m, m.PrefixKey(), nil, kit.Select(FOREACH, key), func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) })
return m return m
} }
func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) { func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {

View File

@ -101,11 +101,12 @@ const (
IMAGE = "image" IMAGE = "image"
PNG = "png" PNG = "png"
JPG = "jpg" JPEG = "jpeg"
MP4 = "mp4" JPG = "jpg"
MOV = "mov" MP4 = "mp4"
PDF = "pdf" MOV = "mov"
PDF = "pdf"
DF = ice.DF DF = ice.DF
PS = ice.PS PS = ice.PS

View File

@ -261,7 +261,7 @@ func Show(m *ice.Message, file string) bool {
p += "?" + kit.JoinKV("=", "&", ice.POD, pod) p += "?" + kit.JoinKV("=", "&", ice.POD, pod)
}) })
switch strings.ToLower(kit.Ext(file)) { switch strings.ToLower(kit.Ext(file)) {
case PNG, JPG: case PNG, JPG, JPEG:
m.EchoImages(p) m.EchoImages(p)
case MP4, MOV: case MP4, MOV:
m.EchoVideos(p) m.EchoVideos(p)

View File

@ -115,13 +115,13 @@ func init() {
ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) { ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), nfs.FILENAME, kit.Select("", arg[0], len(arg) > 1))) m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), nfs.FILENAME, kit.Select("", arg[0], len(arg) > 1)))
}}, }},
WATCH: {Name: "watch hash* path*", Hand: func(m *ice.Message, arg ...string) { WATCH: {Name: "watch hash* path*", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
_cache_watch(m, m.Option(mdb.HASH), m.Option(nfs.PATH)) _cache_watch(m, m.Option(mdb.HASH), m.Option(nfs.PATH))
}}, }},
WRITE: {Name: "write type name* text*", Hand: func(m *ice.Message, arg ...string) { WRITE: {Name: "write type name* text*", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), m.Option(mdb.TEXT)) _cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), m.Option(mdb.TEXT))
}}, }},
CATCH: {Name: "catch path* type", Hand: func(m *ice.Message, arg ...string) { CATCH: {Name: "catch path* type", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
file, size := _cache_catch(m, m.Option(nfs.PATH)) file, size := _cache_catch(m, m.Option(nfs.PATH))
_cache_save(m, m.Option(mdb.TYPE), m.Option(nfs.PATH), "", file, size) _cache_save(m, m.Option(mdb.TYPE), m.Option(nfs.PATH), "", file, size)
}}, }},
@ -131,14 +131,24 @@ func init() {
}}, }},
DOWNLOAD: {Name: "download type name*", Hand: func(m *ice.Message, arg ...string) { DOWNLOAD: {Name: "download type name*", Hand: func(m *ice.Message, arg ...string) {
if res, ok := m.Optionv(RESPONSE).(*http.Response); !m.Warn(!ok, ice.ErrNotValid, RESPONSE) { if res, ok := m.Optionv(RESPONSE).(*http.Response); !m.Warn(!ok, ice.ErrNotValid, RESPONSE) {
file, size := _cache_catch(m, _cache_download(m, res, path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ)), m.OptionCB(""))) p := path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ))
defer os.Remove(p)
file, size := _cache_catch(m, _cache_download(m, res, p, m.OptionCB("")))
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size) _cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size)
} }
}}, }},
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { nfs.PS: {Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelectDetail(m, arg[0], func(value ice.Map) { if mdb.HashSelectDetail(m, arg[0], func(value ice.Map) {
kit.If(kit.Format(value[nfs.FILE]), func() { m.RenderDownload(value[nfs.FILE]) }, func() { m.RenderResult(value[mdb.TEXT]) }) kit.If(kit.Format(value[nfs.FILE]), func() { m.RenderDownload(value[nfs.FILE]) }, func() { m.RenderResult(value[mdb.TEXT]) })
}) }) {
return
}
if pod := m.Option(ice.POD); pod != "" {
msg := m.Options(ice.POD, "").Cmd(SPACE, pod, CACHE, arg[0])
kit.If(kit.Format(msg.Append(nfs.FILE)), func() {
m.RenderDownload(path.Join(ice.USR_LOCAL_WORK, pod, msg.Append(nfs.FILE)))
}, func() { m.RenderResult(msg.Append(mdb.TEXT)) })
}
}}, }},
}, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file", ctx.ACTION, WATCH), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file", ctx.ACTION, WATCH), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) {
if mdb.HashSelect(m, arg...); len(arg) == 0 || m.R != nil && m.R.Method == http.MethodGet { if mdb.HashSelect(m, arg...); len(arg) == 0 || m.R != nil && m.R.Method == http.MethodGet {

View File

@ -23,10 +23,19 @@ func _share_link(m *ice.Message, p string, arg ...ice.Any) string {
return tcp.PublishLocalhost(m, MergeLink(m, kit.Select("", PP(SHARE, LOCAL), !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, HTTP))+p, arg...)) return tcp.PublishLocalhost(m, MergeLink(m, kit.Select("", PP(SHARE, LOCAL), !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, HTTP))+p, arg...))
} }
func _share_cache(m *ice.Message, arg ...string) { func _share_cache(m *ice.Message, arg ...string) {
if m.Cmdy(CACHE, arg[0]); m.Append(nfs.FILE) == "" { if m.Cmdy(CACHE, arg[0]); m.Length() == 0 {
m.RenderResult(m.Append(mdb.TEXT)) if pod := m.Option(ice.POD); pod != "" {
} else { msg := m.Options(ice.POD, "").Cmd(SPACE, pod, CACHE, arg[0])
kit.If(kit.Format(msg.Append(nfs.FILE)), func() {
m.RenderDownload(path.Join(ice.USR_LOCAL_WORK, pod, msg.Append(nfs.FILE)))
}, func() {
m.RenderResult(msg.Append(mdb.TEXT))
})
}
} else if m.Append(nfs.FILE) != "" {
m.RenderDownload(m.Append(nfs.FILE), m.Append(mdb.TYPE), m.Append(mdb.NAME)) m.RenderDownload(m.Append(nfs.FILE), m.Append(mdb.TYPE), m.Append(mdb.NAME))
} else {
m.RenderResult(m.Append(mdb.TEXT))
} }
} }
func _share_proxy(m *ice.Message) { func _share_proxy(m *ice.Message) {

View File

@ -29,7 +29,7 @@ Volcanos(chat.ONIMPORT, {
sub.onaction._close = function() { can.onmotion.hidden(can, sub._target) }, can.onmotion.hidden(can, sub._target) sub.onaction._close = function() { can.onmotion.hidden(can, sub._target) }, can.onmotion.hidden(can, sub._target)
sub.onexport.record = function(sub, value, key, item) { can.onimport._window(can, item) } sub.onexport.record = function(sub, value, key, item) { can.onimport._window(can, item) }
}) }, }) },
_searchs: function(can) { can.onappend.plugin(can, {index: "web.chat.macos.searchs"}, function(sub) { can.ui.searchs = sub _searchs: function(can) { can.onappend.plugin(can, {index: "web.chat.macos.searchs"}, function(sub) { can.ui.searchs = sub, can.onmotion.hidden(can, sub._target)
can.page.style(can, sub._target, html.LEFT, can.ConfWidth()/4, html.TOP, can.ConfHeight()/4), sub.onimport.size(sub, can.ConfHeight()/2, can.ConfWidth()/2, true) can.page.style(can, sub._target, html.LEFT, can.ConfWidth()/4, html.TOP, can.ConfHeight()/4), sub.onimport.size(sub, can.ConfHeight()/2, can.ConfWidth()/2, true)
sub.onaction._close = function() { can.onmotion.hidden(can, sub._target) }, can.onmotion.hidden(can, sub._target) sub.onaction._close = function() { can.onmotion.hidden(can, sub._target) }, can.onmotion.hidden(can, sub._target)
sub.onexport.record = function(sub, value, key, item, event) { switch (item.type) { sub.onexport.record = function(sub, value, key, item, event) { switch (item.type) {

View File

@ -6,7 +6,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg) {
target.onclick = function(event) { can.sup.onexport.record(can.sup, item.index, ctx.INDEX, item) target.onclick = function(event) { can.sup.onexport.record(can.sup, item.index, ctx.INDEX, item)
can.runAction(can.request(event, item), "read", [], function() { can.onappend.style(can, "read", target) }) can.runAction(can.request(event, item), "read", [], function() { can.onappend.style(can, "read", target) })
} }
}} })), msg.Length() == 0 && can.onmotion.hidden(can, can._fields), can.onappend._action(can), can.page.style(can, can._action, html.DISPLAY, html.BLOCK) }} })), can.onmotion.hidden(can, can._fields), can.onappend._action(can), can.page.style(can, can._action, html.DISPLAY, html.BLOCK)
}}) }})
Volcanos(chat.ONACTION, { Volcanos(chat.ONACTION, {
list: [web.REFRESH, mdb.PRUNES, html.TOGGLE], _trans: {refresh: "刷新", toggle: "隐藏"}, list: [web.REFRESH, mdb.PRUNES, html.TOGGLE], _trans: {refresh: "刷新", toggle: "隐藏"},

View File

@ -1,6 +1,8 @@
package mall package mall
import ( import (
"path"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
@ -17,9 +19,26 @@ const GOODS = "goods"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
GOODS: {Name: "goods list", Icon: "mall.png", Help: "商品", Meta: kit.Dict( GOODS: {Name: "goods list what", Icon: "mall.png", Help: "商品", Meta: kit.Dict(
ctx.TRANS, kit.Dict(html.INPUT, kit.Dict(mdb.TYPE, "单位", PRICE, "价格", AMOUNT, "总价")), ctx.TRANS, kit.Dict(html.INPUT, kit.Dict(mdb.TYPE, "单位", PRICE, "价格", AMOUNT, "总价")),
), Actions: ice.MergeActions(ice.Actions{ ), Actions: ice.MergeActions(ice.Actions{
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m.Spawn(kit.Dict(ice.MSG_FIELDS, nfs.IMAGE))).Table(func(value ice.Maps) {
kit.For(kit.Split(value[nfs.IMAGE]), func(h string) {
msg := m.Cmd(web.CACHE, h)
m.Cmd(nfs.LINK, kit.Keys(path.Join(ice.USR_LOCAL_EXPORT, m.PrefixKey(), nfs.IMAGE, h), kit.Select("", kit.Split(msg.Append(mdb.TYPE), nfs.PS), -1)), msg.Append(nfs.FILE))
})
})
}},
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
list := map[string]string{}
m.Cmd(nfs.DIR, path.Join(ice.USR_LOCAL_EXPORT, m.PrefixKey(), nfs.IMAGE), func(value ice.Maps) {
list[kit.TrimExt(value[nfs.PATH])] = m.Cmd(web.CACHE, web.CATCH, value[nfs.PATH]).Append(mdb.HASH)
})
mdb.HashSelectUpdate(m, "", func(value ice.Map) {
value[nfs.IMAGE] = kit.Join(kit.Simple(kit.For(kit.Split(kit.Format(value[nfs.IMAGE])), func(p string) string { return kit.Select(p, list[p]) })))
})
}},
mdb.CREATE: {Name: "create zone* name* text price* count*=1 type*=件,个,份,斤 image*=4@img"}, mdb.CREATE: {Name: "create zone* name* text price* count*=1 type*=件,个,份,斤 image*=4@img"},
mdb.MODIFY: {Name: "modify zone* name* text price* count*=1 type*=件,个,份,斤 image*=4@img"}, mdb.MODIFY: {Name: "modify zone* name* text price* count*=1 type*=件,个,份,斤 image*=4@img"},
nfs.IMAGE: {Name: "image image*=4@img", Help: "图片", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, arg) }}, nfs.IMAGE: {Name: "image image*=4@img", Help: "图片", Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, arg) }},