mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
fbdca73905
commit
46193f5f2f
@ -16,21 +16,7 @@ import (
|
||||
func _cache_name(m *ice.Message, h string) string {
|
||||
return path.Join(ice.VAR_FILE, h[:2], h)
|
||||
}
|
||||
func _cache_save(m *ice.Message, kind, name, text string, arg ...string) { // file size
|
||||
if name == "" {
|
||||
return
|
||||
}
|
||||
if len(text) > 512 || kind == nfs.GO { // 存入文件
|
||||
p := m.Cmdx(nfs.SAVE, _cache_name(m, kit.Hashs(text)), text)
|
||||
text, arg = p, kit.Simple(p, len(text))
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
size := kit.Int(kit.Select(kit.Format(len(text)), arg, 1))
|
||||
file := kit.Select("", arg, 0)
|
||||
text = kit.Select(file, text)
|
||||
h := mdb.HashCreate(m, kit.SimpleKV("", kind, name, text), nfs.FILE, file, nfs.SIZE, size)
|
||||
|
||||
func _cache_type(m *ice.Message, kind, name string) string {
|
||||
if kind == "application/octet-stream" {
|
||||
if kit.ExtIsImage(name) {
|
||||
kind = "image/"+kit.Ext(name)
|
||||
@ -38,14 +24,23 @@ func _cache_save(m *ice.Message, kind, name, text string, arg ...string) { // fi
|
||||
kind = "video/"+kit.Ext(name)
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return kind
|
||||
}
|
||||
func _cache_save(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
m.Assert(name == "", ice.ErrNotValid, mdb.NAME)
|
||||
if len(text) > 512 || kind == nfs.GO {
|
||||
p := m.Cmdx(nfs.SAVE, _cache_name(m, kit.Hashs(text)), text)
|
||||
text, arg = p, kit.Simple(p, len(text))
|
||||
}
|
||||
file, size := kit.Select("", arg, 0), kit.Int(kit.Select(kit.Format(len(text)), arg, 1))
|
||||
kind, text = _cache_type(kind, name), kit.Select(file, text)
|
||||
h := mdb.HashCreate(m, kit.SimpleKV("", kind, name, text), nfs.FILE, file, nfs.SIZE, size)
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(mdb.TYPE, kind)
|
||||
m.Push(mdb.NAME, name)
|
||||
m.Push(mdb.TEXT, text)
|
||||
m.Push(nfs.SIZE, size)
|
||||
m.Push(nfs.FILE, file)
|
||||
m.Push(nfs.SIZE, size)
|
||||
m.Push(mdb.HASH, h)
|
||||
m.Push(mdb.DATA, h)
|
||||
}
|
||||
@ -59,26 +54,18 @@ func _cache_watch(m *ice.Message, key, file string) {
|
||||
})
|
||||
}
|
||||
func _cache_catch(m *ice.Message, name string) (file, size string) {
|
||||
if f, e := nfs.OpenFile(m, name); m.Assert(e) {
|
||||
defer f.Close()
|
||||
|
||||
if s, e := nfs.StatFile(m, name); m.Assert(e) {
|
||||
return m.Cmdx(nfs.LINK, _cache_name(m, kit.Hashs(f)), name), kit.Format(s.Size())
|
||||
}
|
||||
if msg := m.Cmd(nfs.DIR, name, "hash,size"); msg.Length() > 0 {
|
||||
return m.Cmdx(nfs.LINK, _cache_name(m, msg.Append(mdb.HASH)), name), mdb.Append(mdb.SIZE)
|
||||
}
|
||||
return "", "0"
|
||||
}
|
||||
func _cache_upload(m *ice.Message, r *http.Request) (kind, name, file, size string) {
|
||||
if b, h, e := r.FormFile(UPLOAD); m.Assert(e) {
|
||||
if b, h, e := r.FormFile(UPLOAD); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
defer b.Close()
|
||||
|
||||
// 创建文件
|
||||
if f, p, e := miss.CreateFile(_cache_name(m, kit.Hashs(b))); m.Assert(e) {
|
||||
if f, p, e := miss.CreateFile(_cache_name(m, kit.Hashs(b))); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
defer f.Close()
|
||||
|
||||
// 导入数据
|
||||
b.Seek(0, os.SEEK_SET)
|
||||
if n, e := io.Copy(f, b); m.Assert(e) {
|
||||
if n, e := io.Copy(f, b); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
m.Logs(mdb.IMPORT, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n)))
|
||||
return h.Header.Get(ContentType), h.Filename, p, kit.Format(n)
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ func init() {
|
||||
m.Sleep30ms().Cmd(ssh.PRINTF, kit.Dict(nfs.CONTENT, "\r"+ice.Render(m, ice.RENDER_QRCODE, m.Cmdx(SPACE, DOMAIN))+ice.NL))
|
||||
}},
|
||||
SERVE_REWRITE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] != SPIDE_GET {
|
||||
if arg[0] != http.MethodGet {
|
||||
return
|
||||
}
|
||||
switch arg[1] {
|
||||
|
@ -76,25 +76,14 @@ func _share_local(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _share_proxy(m *ice.Message) {
|
||||
switch p := path.Join(ice.VAR_PROXY, m.Option(ice.POD), m.Option(nfs.PATH)); m.R.Method {
|
||||
case http.MethodGet: // 下发文件
|
||||
case http.MethodGet:
|
||||
m.RenderDownload(path.Join(p, m.Option(mdb.NAME)))
|
||||
|
||||
case http.MethodPost: // 上传文件
|
||||
case http.MethodPost:
|
||||
m.Cmdy(CACHE, UPLOAD)
|
||||
m.Cmdy(CACHE, WATCH, m.Option(mdb.DATA), p)
|
||||
m.RenderResult(m.Option(nfs.PATH))
|
||||
}
|
||||
}
|
||||
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
||||
if repos == ice.Info.Make.Module && nfs.ExistsFile(m, path.Join(arg...)) {
|
||||
m.RenderDownload(path.Join(arg...))
|
||||
return
|
||||
}
|
||||
if !nfs.ExistsFile(m, path.Join(ice.ISH_PLUGED, repos)) { // 克隆代码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(ice.ISH_PLUGED, repos))
|
||||
}
|
||||
m.RenderDownload(path.Join(ice.ISH_PLUGED, repos, path.Join(arg...)))
|
||||
}
|
||||
|
||||
const (
|
||||
TOPIC = "topic"
|
||||
@ -118,14 +107,12 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHARE: {Name: "share hash auto prunes", Help: "共享链", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _share_render(m) }},
|
||||
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, arg, aaa.USERROLE, m.Option(ice.MSG_USERROLE), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERNICK, m.Option(ice.MSG_USERNICK))
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, arg, aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
m.Option(mdb.LINK, _share_link(m, PP(SHARE)+m.Result()))
|
||||
}},
|
||||
LOGIN: {Name: "login userrole=void,tech username", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(SHARE, mdb.CREATE, mdb.TYPE, LOGIN, m.OptionSimple(aaa.USERROLE, aaa.USERNAME))
|
||||
m.EchoQRCode(msg.Option(mdb.LINK))
|
||||
m.ProcessInner()
|
||||
LOGIN: {Name: "login userrole=void,tech username", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoQRCode(m.Cmd(SHARE, mdb.CREATE, mdb.TYPE, LOGIN).Option(mdb.LINK)).ProcessInner()
|
||||
}},
|
||||
SERVE_PARSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Select("", arg, 0) != SHARE {
|
||||
@ -134,7 +121,7 @@ func init() {
|
||||
switch arg[1] {
|
||||
case "local":
|
||||
default:
|
||||
m.Logs("refer", arg[0], arg[1])
|
||||
m.Logs("Refer", arg[0], arg[1])
|
||||
m.Option(arg[0], arg[1])
|
||||
}
|
||||
}},
|
||||
@ -173,7 +160,6 @@ func init() {
|
||||
RenderIndex(m, ice.VOLCANOS)
|
||||
}
|
||||
}},
|
||||
|
||||
SHARE_TOAST: {Name: "/share/toast/", Help: "推送流", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(ice.POD), m.Optionv("cmds"))
|
||||
}},
|
||||
@ -184,17 +170,14 @@ func init() {
|
||||
_share_local(m, arg...)
|
||||
}},
|
||||
SHARE_LOCAL_AVATAR: {Name: "avatar", Help: "头像", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.RenderDownload(strings.TrimPrefix(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME)).Append(aaa.AVATAR), SHARE_LOCAL))
|
||||
m.RenderDownload(strings.TrimPrefix(m.CmdAppend(aaa.USER, m.Option(ice.MSG_USERNAME), aaa.AVATAR), SHARE_LOCAL))
|
||||
}},
|
||||
SHARE_LOCAL_BACKGROUND: {Name: "background", Help: "壁纸", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.RenderDownload(strings.TrimPrefix(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME)).Append(aaa.BACKGROUND), SHARE_LOCAL))
|
||||
SHARE_LOCAL_BACKGROUND: {Name: "background", Help: "背景", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.RenderDownload(strings.TrimPrefix(m.CmdAppend(aaa.USER, m.Option(ice.MSG_USERNAME), aaa.BACKGROUND), SHARE_LOCAL))
|
||||
}},
|
||||
SHARE_PROXY: {Name: "/share/proxy/", Help: "文件流", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_proxy(m)
|
||||
}},
|
||||
SHARE_REPOS: {Name: "/share/repos/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_repos(m, path.Join(arg[0], arg[1], arg[2]), arg[3:]...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user