From 405bd641f36121c25e8d48acff8123fdc8504531 Mon Sep 17 00:00:00 2001 From: shylinux Date: Sat, 11 Mar 2023 17:20:44 +0800 Subject: [PATCH] opt some --- base/mdb/hash.go | 5 +++++ misc.go | 2 -- misc/git/server.go | 5 ++--- misc/git/token.go | 12 +++++++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/base/mdb/hash.go b/base/mdb/hash.go index 1a4da7ab..eb70d083 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -133,6 +133,11 @@ func _hash_import(m *ice.Message, prefix, chain, file string) { } } +const ( + MONTH = "720h" + WEEK = "24h" + HOUR = "1h" +) const ( HASH_FIELD = "time,hash,type,name,text" ) diff --git a/misc.go b/misc.go index 36c0e78c..6b03a363 100644 --- a/misc.go +++ b/misc.go @@ -424,8 +424,6 @@ func SplitCmd(name string, actions Actions) (list []Any) { push(TEXTAREA, ls[i]) case PASSWORD: push(PASSWORD, ls[i]) - case "image": - push(TEXT, ls[i], "img") case "time": push(TEXT, ls[i], "date") case "*": diff --git a/misc/git/server.go b/misc/git/server.go index b82d5bd8..35b0465c 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -185,9 +185,7 @@ func init() { ctx.ProcessField(m, "", arg, arg...) }}, TOKEN: {Hand: func(m *ice.Message, arg ...string) { - token := kit.Hashs("uniq") - m.Cmd(TOKEN, mdb.CREATE, aaa.USERNAME, m.Option(ice.MSG_USERNAME), TOKEN, token) - m.EchoScript(kit.Format("echo %s >> ~/.git-credentials", strings.Replace(m.Option(ice.MSG_USERHOST), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), token), 1))) + m.Echo(m.Cmdx(TOKEN, mdb.CREATE, aaa.USERNAME, m.Option(ice.MSG_USERNAME), TOKEN, kit.Hashs("uniq"))) }}, }, gdb.EventAction(web.DREAM_INPUTS)), Hand: func(m *ice.Message, arg ...string) { if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 { @@ -196,6 +194,7 @@ func init() { m.PushScript("git clone " + _git_url(m, value[mdb.NAME])) }).Cut("time,name,size,script,action").RenameAppend(mdb.NAME, nfs.REPOS).SortTimeR(mdb.TIME) m.Echo(strings.ReplaceAll(m.Cmdx("web.code.publish", ice.CONTEXTS), "app username", "dev username")) + m.Echo(m.Cmdx(TOKEN, m.Option(ice.MSG_USERNAME))) } else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 { _repos_branch(m, dir) } else if len(arg) == 2 { diff --git a/misc/git/token.go b/misc/git/token.go index 2560be81..c3bc0cd5 100644 --- a/misc/git/token.go +++ b/misc/git/token.go @@ -1,17 +1,23 @@ package git import ( + "strings" + ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + kit "shylinux.com/x/toolkits" ) const TOKEN = "token" func init() { Index.MergeCommands(ice.Commands{ - TOKEN: {Name: "token username auto", Actions: ice.MergeActions(mdb.HashAction( - mdb.SHORT, aaa.USERNAME, mdb.EXPIRE, "720h", mdb.FIELD, "time,username,token", - ))}, + TOKEN: {Name: "token username auto prunes", Actions: mdb.HashAction(mdb.EXPIRE, mdb.MONTH, mdb.SHORT, aaa.USERNAME, mdb.FIELD, "time,username,token"), Hand: func(m *ice.Message, arg ...string) { + if mdb.HashSelect(m, arg...); len(arg) > 0 && m.Length() > 0 { + m.EchoScript(nfs.Template(m, "echo.sh", strings.Replace(m.Option(ice.MSG_USERHOST), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), m.Append(TOKEN)), 1))) + } + }}, }) }