From a77ddbe902ce3e5b410b8188327924214868fa45 Mon Sep 17 00:00:00 2001 From: shy Date: Sat, 11 Nov 2023 00:07:04 +0800 Subject: [PATCH] add some --- base/aaa/email.go | 5 +++- base/web/dream.go | 2 +- core/chat/header.go | 11 ++++---- core/chat/oauth/client.go | 4 +-- misc/disk/client.go | 58 ++++++++++++++++++++++----------------- misc/wx/access.go | 12 ++++++-- misc/wx/agent.go | 2 +- misc/wx/scan.go | 7 +++-- misc/wx/wx.shy | 16 +---------- 9 files changed, 63 insertions(+), 54 deletions(-) diff --git a/base/aaa/email.go b/base/aaa/email.go index 55cb4aa8..cf791f4c 100644 --- a/base/aaa/email.go +++ b/base/aaa/email.go @@ -47,6 +47,9 @@ func init() { auth := smtp.PlainAuth("", msg.Append(USERNAME), msg.Append(PASSWORD), kit.Split(msg.Append(SERVICE), ice.DF)[0]) m.Logs(EMAIL, SEND, string(content)).Warn(smtp.SendMail(msg.Append(SERVICE), auth, msg.Append(USERNAME), kit.Split(m.Option(TO)), content)) }}, - }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username", ice.ACTION, SEND))}, + LOGIN: {Hand: func(m *ice.Message, arg ...string) { + m.Echo("input email: ") + }}, + }, RoleAction(LOGIN), mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username", ice.ACTION, SEND))}, }) } diff --git a/base/web/dream.go b/base/web/dream.go index 0354a8f4..9715ef01 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -246,7 +246,7 @@ func init() { DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) { kit.Switch(m.Option(mdb.TYPE), []string{WORKER, SERVER}, func() { m.PushButton(OPEN, ice.MAIN) }) }}, - }, DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) { + }, aaa.RoleAction(), DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) { if ice.Info.NodeType == WORKER { return } diff --git a/core/chat/header.go b/core/chat/header.go index 94871174..9378ea69 100644 --- a/core/chat/header.go +++ b/core/chat/header.go @@ -93,19 +93,20 @@ func init() { m.Options(ice.MSG_USERWEB, kit.MergeURL(m.Option(ice.MSG_USERWEB), web.SHARE, m.Cmdx(web.SHARE, mdb.CREATE, mdb.TYPE, web.LOGIN))) m.Cmdy(aaa.EMAIL, aaa.SEND, arg, aaa.CONTENT, nfs.Template(m, "email.html")) }}, - mdb.CREATE: {Name: "create name icon url", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m, m.OptionSimple()) }}, + mdb.CREATE: {Name: "create type*=oauth,plugin name* icons link order space index args", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m, m.OptionSimple()) }}, mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { mdb.HashRemove(m, m.OptionSimple(mdb.NAME)) }}, - }, web.ApiAction(), ctx.ConfAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,url")), Hand: func(m *ice.Message, arg ...string) { + }, web.ApiAction(), ctx.ConfAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icons,type,link,order,space,index,args")), Hand: func(m *ice.Message, arg ...string) { m.Option("language.list", m.Cmd(nfs.DIR, nfs.TemplatePath(m, aaa.LANGUAGE)+nfs.PS, nfs.FILE).Appendv(nfs.FILE)) m.Option("theme.list", m.Cmd(nfs.DIR, nfs.TemplatePath(m, aaa.THEME)+nfs.PS, nfs.FILE).Appendv(nfs.FILE)) m.Option(nfs.REPOS, m.Cmdv(web.SPIDE, nfs.REPOS, web.CLIENT_URL)) - m.Option("icons", mdb.Conf(m, ICON, kit.Keym(nfs.PATH))) + m.Option("icon.lib", mdb.Conf(m, ICON, kit.Keym(nfs.PATH))) m.Option(MENUS, mdb.Config(m, MENUS)) m.Echo(mdb.Config(m, TITLE)) - if mdb.HashSelect(m); m.Length() == 0 { + if mdb.HashSelect(m, arg...); m.Length() == 0 { kit.If(GetSSO(m), func(p string) { - m.Push(mdb.TIME, m.Time()).Push(mdb.NAME, web.SERVE).Push(mdb.ICON, nfs.USR_ICONS_ICEBERGS).Push(web.URL, p) + m.Push(mdb.TIME, m.Time()).Push(mdb.NAME, web.SERVE).Push(mdb.ICONS, nfs.USR_ICONS_ICEBERGS).Push(mdb.TYPE, "oauth").Push(web.LINK, p) }) + m.Sort("order", "int") } if gdb.Event(m, HEADER_AGENT); !_header_check(m, arg...) { return diff --git a/core/chat/oauth/client.go b/core/chat/oauth/client.go index f75fb845..034e11d4 100644 --- a/core/chat/oauth/client.go +++ b/core/chat/oauth/client.go @@ -42,7 +42,7 @@ type Client struct { ice.Hash short string `data:"domain,client_id"` field string `data:"time,hash,domain,client_id,client_secret,oauth_url,grant_url,token_url,users_url,scope,user_key,nick_key,api_prefix,token_prefix"` - sso string `name:"sso name* icon*@icon" help:"登录"` + sso string `name:"sso name* icons*" help:"登录"` auth string `name:"auth" help:"授权"` user string `name:"user" help:"用户"` orgs string `name:"orgs" help:"组织"` @@ -86,7 +86,7 @@ func (s Client) Inputs(m *ice.Message, arg ...string) { } } func (s Client) Sso(m *ice.Message, arg ...string) { - m.Cmd(web.CHAT_HEADER, mdb.CREATE, m.Option(mdb.NAME), m.Option(mdb.ICON), s.OAuthURL(m)) + m.Cmd(web.CHAT_HEADER, mdb.CREATE, "oauth", m.Option(mdb.NAME), m.Option(mdb.ICONS), s.OAuthURL(m)) } func (s Client) Auth(m *ice.Message, arg ...string) { m.ProcessOpen(s.OAuthURL(m)) diff --git a/misc/disk/client.go b/misc/disk/client.go index 735d21db..4805b822 100644 --- a/misc/disk/client.go +++ b/misc/disk/client.go @@ -9,44 +9,44 @@ import ( kit "shylinux.com/x/toolkits" ) +const ( + BAIDU = "baidu" + AUTH_URL = "http://openapi.baidu.com" + API_URL = "https://pan.baidu.com/rest/2.0/xpan/" + USER_INFO = "nas?method=uinfo" + FILE_LIST = "file?method=list" + FILE_META = "multimedia?method=filemetas" +) + type Client struct { oauth.Client - list string `name:"list hash path orgs:text repo:text auto" help:"仓库" icon:"gitea.png"` + list string `name:"list hash path orgs:text repo:text auto" help:"仓库" icon:"netdisk.png"` } func init() { - oauth.Inputs["baidu"] = map[string]string{ - oauth.OAUTH_URL: "/oauth/2.0/authorize", - oauth.GRANT_URL: "/oauth/2.0/token", - oauth.TOKEN_URL: "/oauth/2.0/token", - oauth.USERS_URL: "https://pan.baidu.com/rest/2.0/xpan/nas?method=uinfo", - oauth.NICK_KEY: "baidu_name", - oauth.USER_KEY: "uk", - oauth.SCOPE: "basic,netdisk", - oauth.API_PREFIX: "/api/v1/", - oauth.TOKEN_PREFIX: "", + oauth.Inputs[BAIDU] = map[string]string{ + oauth.OAUTH_URL: "/oauth/2.0/authorize", + oauth.GRANT_URL: "/oauth/2.0/token", + oauth.TOKEN_URL: "/oauth/2.0/token", + oauth.USERS_URL: API_URL + USER_INFO, + oauth.NICK_KEY: "baidu_name", + oauth.USER_KEY: "uk", + oauth.SCOPE: "basic,netdisk", } } +func (s Client) Init(m *ice.Message, arg ...string) { + m.Cmd(web.SPIDE, mdb.CREATE, BAIDU, AUTH_URL) + s.Hash.Init(m, arg...) +} func (s Client) Login(m *ice.Message, arg ...string) { s.Client.Login2(m, arg...) } -func (s Client) Show(m *ice.Message, arg ...string) { - res := s.Client.Get(m, m.Option(mdb.HASH), "https://pan.baidu.com/rest/2.0/xpan/multimedia?method=filemetas", "dlink", "1", "fsids", kit.Format("%v", []string{m.Option(mdb.ID)})) - // 1 视频、2 音频、3 图片、4 文档、5 应用、6 其他、7 种子 - p := "usr/local/disk/" + m.Option(mdb.ID) - s.Save(m, m.Option(mdb.HASH), p, kit.Format(kit.Value(res, "list.0.dlink"))) - web.ToastSuccess(m.Message) - switch kit.Format(kit.Value(res, "list.0.category")) { - case "4": - m.Cmdy(nfs.CAT, p) - } -} func (s Client) List(m *ice.Message, arg ...string) { if len(arg) == 0 { s.Client.List(m, arg...) return } - res := s.Client.Get(m, arg[0], "https://pan.baidu.com/rest/2.0/xpan/file?method=list", "dir", kit.Select("", arg, 1)) + res := s.Client.Get(m, arg[0], API_URL+FILE_LIST, nfs.DIR, kit.Select("", arg, 1)) kit.For(kit.Value(res, mdb.LIST), func(value ice.Map) { m.Push(mdb.TIME, kit.TimeUnix(value["server_mtime"])) m.Push(nfs.PATH, kit.Format(value[nfs.PATH])+kit.Select("", nfs.PS, kit.Format(value["isdir"]) == "1")) @@ -54,7 +54,15 @@ func (s Client) List(m *ice.Message, arg ...string) { m.Push(mdb.ID, value["fs_id"]) }) m.PushAction("show") - m.Echo(kit.Formats(res)) } - +func (s Client) Show(m *ice.Message, arg ...string) { + res := s.Client.Get(m, m.Option(mdb.HASH), API_URL+FILE_META, "dlink", "1", "fsids", kit.Format("%v", []string{m.Option(mdb.ID)})) + p := "usr/local/disk/" + m.Option(mdb.ID) + s.Save(m, m.Option(mdb.HASH), p, kit.Format(kit.Value(res, "list.0.dlink"))) + defer web.ToastSuccess(m.Message) + switch kit.Format(kit.Value(res, "list.0.category")) { // 1 视频、2 音频、3 图片、4 文档、5 应用、6 其他、7 种子 + case "4": + m.Cmdy(nfs.CAT, p) + } +} func init() { ice.WikiCtxCmd(Client{}) } diff --git a/misc/wx/access.go b/misc/wx/access.go index 03869806..ddf5c5d7 100644 --- a/misc/wx/access.go +++ b/misc/wx/access.go @@ -82,8 +82,16 @@ func init() { } m.Echo(msg.Append(TICKET)).Status(msg.AppendSimple(EXPIRE)) }}, - }, mdb.ImportantHashAction(mdb.SHORT, ACCESS, mdb.FIELD, "time,access,icons,usernick,appid", tcp.SERVER, CGI_BIN)), Hand: func(m *ice.Message, arg ...string) { - mdb.HashSelect(m, arg...).StatusTimeCount(mdb.ConfigSimple(m, ACCESS, APPID), web.SERVE, web.MergeLink(m, "/chat/wx/login/")) + web.SSO: {Name: "sso name*=微信授权", Help: "登录", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(web.CHAT_HEADER, mdb.CREATE, mdb.TYPE, mdb.PLUGIN, m.OptionSimple(mdb.NAME), + ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.Join(kit.Simple(aaa.LOGIN, m.Option(ACCESS)))) + }}, + aaa.LOGIN: {Hand: func(m *ice.Message, arg ...string) { + m.Options(ACCESS, arg[0]).Cmdy(SCAN, mdb.CREATE, mdb.TYPE, "QR_STR_SCENE", + mdb.NAME, "授权登录", mdb.TEXT, m.Option(web.SPACE), ctx.INDEX, "web.chat.grant", ctx.ARGS, m.Option(web.SPACE)) + }}, + }, aaa.RoleAction(aaa.LOGIN), mdb.ImportantHashAction(mdb.SHORT, ACCESS, mdb.FIELD, "time,access,icons,usernick,appid", tcp.SERVER, CGI_BIN)), Hand: func(m *ice.Message, arg ...string) { + mdb.HashSelect(m, arg...).PushAction(web.SSO, mdb.REMOVE).StatusTimeCount(mdb.ConfigSimple(m, ACCESS, APPID), web.SERVE, web.MergeLink(m, "/chat/wx/login/")) m.RewriteAppend(func(value, key string, index int) string { kit.If(key == cli.QRCODE, func() { value = ice.Render(m, ice.RENDER_QRCODE, value) }) return value diff --git a/misc/wx/agent.go b/misc/wx/agent.go index 2764bd9d..aa381ba3 100644 --- a/misc/wx/agent.go +++ b/misc/wx/agent.go @@ -35,7 +35,7 @@ const AGENT = "agent" func init() { Index.MergeCommands(ice.Commands{ - AGENT: {Name: "agent auto", Actions: ice.MergeActions(ice.Actions{ + AGENT: {Name: "agent auto", Help: "代理", Actions: ice.MergeActions(ice.Actions{ chat.HEADER_AGENT: {Hand: func(m *ice.Message, arg ...string) { kit.If(strings.Index(m.Option(ice.MSG_USERUA), "MicroMessenger") > -1, func() { m.Option(mdb.PLUGIN, m.PrefixKey()) }) }}, diff --git a/misc/wx/scan.go b/misc/wx/scan.go index dcfadc26..dbd64442 100644 --- a/misc/wx/scan.go +++ b/misc/wx/scan.go @@ -17,17 +17,20 @@ const SCAN = "scan" func init() { Index.MergeCommands(ice.Commands{ SCAN: {Name: "scan access hash auto", Help: "桌牌", Meta: kit.Merge(Meta(), kit.Dict(ice.CTX_TRANS, kit.Dict(html.VALUE, kit.Dict( - "QR_STR_SCENE", "临时码", "QR_LIMIT_STR_SCENE", "永久码", + "QR_LIMIT_STR_SCENE", "永久码", "QR_STR_SCENE", "临时码", "valid", "有效", "expired", "失效", )))), Actions: ice.MergeActions(ice.Actions{ mdb.CREATE: {Name: "create type=QR_STR_SCENE,QR_LIMIT_STR_SCENE name*=1 text icons expire_seconds=3600 space index* args", Hand: func(m *ice.Message, arg ...string) { h := mdb.HashCreate(m.Spawn(), arg) res := SpidePost(m, QRCODE_CREATE, "action_name", m.Option(mdb.TYPE), "action_info.scene.scene_str", h, m.OptionSimple(EXPIRE_SECONDS)) mdb.HashModify(m, mdb.HASH, h, mdb.LINK, kit.Value(res, web.URL), mdb.TIME, m.Time(kit.Format("%ss", kit.Select("60", m.Option(EXPIRE_SECONDS))))) + m.EchoQRCode(kit.Format(kit.Value(res, web.URL))) }}, }, mdb.ExportHashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,name,text,icons,space,index,args,type,link")), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { m.Cmdy(ACCESS).PushAction("").Option(ice.MSG_ACTION, "") - } else if mdb.HashSelect(m, arg[1:]...); len(arg) > 1 { + } else if mdb.HashSelect(m, arg[1:]...); len(arg) == 1 { + m.Table(func(value ice.Maps) { m.Push(mdb.STATUS, kit.Select("valid", "expired", value[mdb.TIME] < m.Time())) }) + } else { kit.If(m.Time() < m.Append(mdb.TIME), func() { m.PushQRCode(cli.QRCODE, m.Append(mdb.LINK)) }) } }}, diff --git a/misc/wx/wx.shy b/misc/wx/wx.shy index ee2d6f0a..d2551afe 100644 --- a/misc/wx/wx.shy +++ b/misc/wx/wx.shy @@ -15,18 +15,4 @@ field web.chat.wx.users chapter "数据" field web.chat.favor -field web.chat.location -return -order ` -wx.go -wx.shy -access.go -menu.go -scan.go -text.go -login.go -events.go -users.go -agent.go -agent.js -` \ No newline at end of file +field web.chat.location \ No newline at end of file