mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 09:34:05 +08:00
opt some
This commit is contained in:
parent
2af002441a
commit
99d94aece8
@ -100,8 +100,8 @@ func _spide_list(m *ice.Message, arg ...string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 处理异常
|
// 处理异常
|
||||||
if m.Warn(res.StatusCode != http.StatusOK, ice.ErrNotFound, uri, cli.STATUS, res.Status) {
|
if m.Warn(res.StatusCode != http.StatusOK, ice.ErrNotValid, uri, cli.STATUS, res.Status) {
|
||||||
switch m.Set(ice.MSG_RESULT); res.StatusCode {
|
switch m.SetResult(); res.StatusCode {
|
||||||
case http.StatusNotFound:
|
case http.StatusNotFound:
|
||||||
m.Warn(true, ice.ErrNotFound, uri)
|
m.Warn(true, ice.ErrNotFound, uri)
|
||||||
return
|
return
|
||||||
|
@ -22,6 +22,11 @@ func init() {
|
|||||||
LOGIN_OAUTH = "https://github.com/login/oauth/"
|
LOGIN_OAUTH = "https://github.com/login/oauth/"
|
||||||
API_GITHUB = "https://api.github.com/"
|
API_GITHUB = "https://api.github.com/"
|
||||||
)
|
)
|
||||||
|
_oauth_header := func(m *ice.Message, arg ...string) *ice.Message {
|
||||||
|
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+kit.Select(m.Option(ACCESS_TOKEN), arg, 0))
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
OAUTH: {Name: "oauth hash auto", Help: "授权", Actions: ice.MergeActions(ice.Actions{
|
OAUTH: {Name: "oauth hash auto", Help: "授权", Actions: ice.MergeActions(ice.Actions{
|
||||||
ctx.CONFIG: {Name: "config client_id client_secret redirect_uri", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
ctx.CONFIG: {Name: "config client_id client_secret redirect_uri", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||||
@ -38,42 +43,39 @@ func init() {
|
|||||||
mdb.HashCreate(m, m.OptionSimple(CODE))
|
mdb.HashCreate(m, m.OptionSimple(CODE))
|
||||||
}},
|
}},
|
||||||
ACCESS_TOKEN: {Name: "access_token", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
ACCESS_TOKEN: {Name: "access_token", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON)
|
mdb.HashModify(m, m.OptionSimple(mdb.HASH), kit.Simple(web.SpidePost(_oauth_header(m), kit.MergeURL2(LOGIN_OAUTH, ACCESS_TOKEN), m.ConfigSimple(CLIENT_ID, CLIENT_SECRET), m.OptionSimple(CODE))))
|
||||||
data := web.SpidePost(m, kit.MergeURL2(LOGIN_OAUTH, ACCESS_TOKEN), m.ConfigSimple(CLIENT_ID, CLIENT_SECRET), m.OptionSimple(CODE))
|
|
||||||
mdb.HashModify(m, m.OptionSimple(mdb.HASH), kit.Simple(data))
|
|
||||||
}},
|
|
||||||
"public": {Name: "public hash", Help: "公钥", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+m.Option(ACCESS_TOKEN))
|
|
||||||
msg := m.Cmd(aaa.RSA, m.Option(mdb.HASH))
|
|
||||||
m.PushDetail(web.SpidePost(m, API_GITHUB+"user/keys", web.SPIDE_JSON, "key", msg.Append("public"), msg.AppendSimple("title")))
|
|
||||||
m.Echo("https://github.com/settings/keys")
|
|
||||||
}},
|
}},
|
||||||
"user": {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) {
|
"user": {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+m.Option(ACCESS_TOKEN))
|
mdb.HashModify(m, m.OptionSimple(mdb.HASH), kit.Simple(web.SpideGet(_oauth_header(m), API_GITHUB+"user")))
|
||||||
mdb.HashModify(m, m.OptionSimple(mdb.HASH), kit.Simple(web.SpideGet(m, API_GITHUB+"user")))
|
|
||||||
}},
|
}},
|
||||||
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
"public": {Name: "public hash", Help: "公钥", Hand: func(m *ice.Message, arg ...string) {
|
||||||
mdb.HashSelect(m, m.Option(mdb.HASH))
|
msg := m.Cmd(aaa.RSA, m.Option(mdb.HASH))
|
||||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+m.Append(ACCESS_TOKEN))
|
m.PushDetail(web.SpidePost(_oauth_header(m), API_GITHUB+"user/keys", web.SPIDE_JSON, "key", msg.Append("public"), msg.AppendSimple("title")))
|
||||||
web.SpideDelete(m, API_GITHUB+"user/keys/"+m.Option(mdb.ID))
|
m.Echo("https://github.com/settings/keys")
|
||||||
}},
|
}},
|
||||||
}, mdb.HashAction(mdb.FIELD, "time,hash,code,access_token,scope,token_type")), Hand: func(m *ice.Message, arg ...string) {
|
"keys": {Name: "keys", Help: "用户密钥", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if mdb.HashSelect(m, arg...).PushAction("user", "public", ACCESS_TOKEN, mdb.REMOVE); len(arg) == 0 {
|
_oauth_header(m).SetAppend()
|
||||||
m.Echo(kit.MergeURL2(LOGIN_OAUTH, "authorize", m.ConfigSimple(REDIRECT_URI, CLIENT_ID), SCOPE, "read:user read:public_key write:public_key repo"))
|
|
||||||
m.Action(mdb.CREATE)
|
|
||||||
} else if len(arg) == 1 {
|
|
||||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+m.Append(ACCESS_TOKEN))
|
|
||||||
m.SetAppend()
|
|
||||||
kit.Fetch(web.SpideGet(m, API_GITHUB+"user/keys"), func(index int, value ice.Map) {
|
kit.Fetch(web.SpideGet(m, API_GITHUB+"user/keys"), func(index int, value ice.Map) {
|
||||||
m.PushRecord(value, "created_at,title,id,key")
|
m.PushRecord(value, "created_at,title,id,key")
|
||||||
})
|
})
|
||||||
m.PushAction(mdb.DELETE)
|
m.PushAction(mdb.DELETE)
|
||||||
|
}},
|
||||||
|
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
mdb.HashSelect(m, m.Option(mdb.HASH))
|
||||||
|
web.SpideDelete(_oauth_header(m), API_GITHUB+"user/keys/"+m.Option(mdb.ID))
|
||||||
|
}},
|
||||||
|
}, mdb.HashAction(mdb.FIELD, "time,hash,code,access_token,scope,token_type")), Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if mdb.HashSelect(m, arg...).PushAction("public", "user", ACCESS_TOKEN, mdb.REMOVE); len(arg) == 0 {
|
||||||
|
if m.Action(mdb.CREATE); m.Length() == 0 {
|
||||||
|
m.Echo(kit.MergeURL2(LOGIN_OAUTH, "authorize", m.ConfigSimple(REDIRECT_URI, CLIENT_ID), SCOPE, "read:user read:public_key write:public_key repo"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"/oauth": {Name: "/oauth", Help: "授权", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
"/oauth": {Name: "/oauth", Help: "授权", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||||
if m.Option(CODE) != "" {
|
if m.Warn(m.Option(CODE) == "", ice.ErrNotValid) {
|
||||||
web.RenderCmd(m, m.PrefixKey(), m.Cmdx(m.PrefixKey(), mdb.CREATE, m.OptionSimple(CODE)))
|
return
|
||||||
}
|
}
|
||||||
|
web.RenderCmd(m, m.PrefixKey(), m.Cmdx(m.PrefixKey(), mdb.CREATE, m.OptionSimple(CODE)))
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user