1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-12-02 13:53:54 +08:00
parent c9e6fb5a50
commit 79792837a5
8 changed files with 33 additions and 35 deletions

View File

@ -114,7 +114,7 @@ func _serve_domain(m *ice.Message) string {
return kit.GetValid(
func() string { return ice.Info.Domain },
func() string { return m.R.Header.Get("X-Host") },
func() string { return kit.Select("", m.R.Header.Get(Referer), m.R.Method == SPIDE_POST) },
func() string { return kit.Select("", m.R.Header.Get(Referer), m.R.Method == http.MethodPost) },
func() string { return kit.Format("%s://%s", kit.Select("https", ice.HTTP, m.R.TLS == nil), m.R.Host) },
)
}

View File

@ -23,11 +23,10 @@ import (
func _spide_create(m *ice.Message, name, address string) {
if uri, e := url.Parse(address); !m.Warn(e != nil || address == "", ice.ErrNotValid, address) {
m.Logs(mdb.CREATE, SPIDE, name, ADDRESS, address)
mdb.HashSelectUpdate(m, mdb.HashCreate(m, CLIENT_NAME, name), func(value ice.Map) {
dir, file := path.Split(uri.EscapedPath())
mdb.HashCreate(m, CLIENT_NAME, name)
mdb.HashSelectUpdate(m, name, func(value ice.Map) {
value[SPIDE_CLIENT] = kit.Dict(
mdb.NAME, name, SPIDE_METHOD, SPIDE_POST, "url", address,
mdb.NAME, name, SPIDE_METHOD, http.MethodPost, "url", address,
tcp.PROTOCOL, uri.Scheme, tcp.HOSTNAME, uri.Host,
nfs.PATH, dir, nfs.FILE, file, "query", uri.RawQuery,
cli.TIMEOUT, "600s", LOGHEADERS, ice.FALSE,
@ -92,7 +91,7 @@ func _spide_show(m *ice.Message, arg ...string) {
func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.Maps, []string) {
head := ice.Maps{}
body, ok := m.Optionv(SPIDE_BODY).(io.Reader)
if !ok && len(arg) > 0 && method != SPIDE_GET {
if !ok && len(arg) > 0 && method != http.MethodGet {
if len(arg) == 1 {
arg = []string{SPIDE_DATA, arg[0]}
}
@ -177,7 +176,7 @@ func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map
req.Header.Set(k, v)
m.Logs("Header", k, v)
})
if req.Method == SPIDE_POST {
if req.Method == http.MethodPost {
m.Logs(kit.Select(ice.AUTO, req.Header.Get(ContentLength)), req.Header.Get(ContentType))
}
}
@ -222,11 +221,6 @@ const (
SPIDE_SAVE = "save"
SPIDE_CACHE = "cache"
SPIDE_GET = http.MethodGet
SPIDE_PUT = http.MethodPut
SPIDE_POST = http.MethodPost
SPIDE_DELETE = http.MethodDelete
SPIDE_BODY = "body"
SPIDE_FORM = "form"
SPIDE_PART = "part"
@ -302,25 +296,25 @@ func init() {
_spide_show(m, arg...)
}
}},
SPIDE_GET: {Name: "GET url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, SPIDE_GET, arg[0], arg[1:]))))
http.MethodGet: {Name: "GET url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, arg[0], arg[1:]))))
}},
SPIDE_PUT: {Name: "PUT url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, SPIDE_PUT, arg[0], arg[1:]))))
http.MethodPut: {Name: "PUT url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodPut, arg[0], arg[1:]))))
}},
SPIDE_POST: {Name: "POST url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, SPIDE_POST, arg[0], arg[1:]))))
http.MethodPost: {Name: "POST url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodPost, arg[0], arg[1:]))))
}},
SPIDE_DELETE: {Name: "DELETE url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, SPIDE_DELETE, arg[0], arg[1:]))))
http.MethodDelete: {Name: "DELETE url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodDelete, arg[0], arg[1:]))))
}},
})
}
func SpideGet(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(SPIDE_GET, arg)) }
func SpidePut(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(SPIDE_PUT, arg)) }
func SpidePost(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(SPIDE_POST, arg)) }
func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(SPIDE_DELETE, arg)) }
func SpideGet(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodGet, arg)) }
func SpidePut(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodPut, arg)) }
func SpidePost(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodPost, arg)) }
func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any { return kit.UnMarshal(m.Cmdx(http.MethodDelete, arg)) }
func SpideSave(m *ice.Message, file, link string, cb func(int, int, int)) *ice.Message {
return m.Cmd("web.spide", ice.DEV, SPIDE_SAVE, file, SPIDE_GET, link, cb)
return m.Cmd("web.spide", ice.DEV, SPIDE_SAVE, file, http.MethodGet, link, cb)
}

View File

@ -2,12 +2,12 @@ package chat
import (
"sync"
"net/http"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
@ -32,7 +32,7 @@ func init() {
}
get := func(m *ice.Message, api string, arg ...ice.Any) string {
return kit.Format(cache(m, kit.Join(kit.Simple(api, arg)), func() string {
return m.Cmdx(web.SPIDE_GET, "https://apis.map.qq.com/ws/"+api, mdb.KEY, m.Config(aaa.TOKEN), arg)
return m.Cmdx(http.MethodGet, "https://apis.map.qq.com/ws/"+api, mdb.KEY, m.Config(aaa.TOKEN), arg)
}))
}

View File

@ -2,6 +2,7 @@ package oauth
import (
"path"
"net/http"
"strings"
"time"
@ -73,7 +74,7 @@ var Index = &ice.Context{Name: OAUTH, Help: "认证授权", Commands: ice.Comman
m.Cmd(REPLY, mdb.CREATE, aaa.USERNAME, m.Option(ice.MSG_USERNAME), m.OptionSimple(SCOPE, OFFER))
m.Option(web.SPIDE_HEADER, web.UserAgent, m.PrefixKey())
m.Cmd(ssh.SOURCE, m.Option(SCOPE), kit.Dict(nfs.CAT_CONTENT, m.Cmdx(web.SPIDE, ice.DEV, web.SPIDE_GET, m.Option(OFFER))))
m.Cmd(ssh.SOURCE, m.Option(SCOPE), kit.Dict(nfs.CAT_CONTENT, m.Cmdx(web.SPIDE, ice.DEV, http.MethodGet, m.Option(OFFER))))
m.ProcessHistory()
}},
})},

View File

@ -44,7 +44,7 @@ func init() {
mdb.CREATE: {Name: "create zone=some binnary=bin/ice.bin service='http://localhost:9020/debug/pprof/profile' seconds=3", Help: "创建"},
ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option(SERVICE), SECONDS, m.Option(SECONDS))
msg := m.Cmd(web.SPIDE, ice.DEV, web.SPIDE_CACHE, http.MethodGet, m.Option(SERVICE), SECONDS, m.Option(SECONDS))
cmd := kit.Simple(m.Configv(PPROF), "-text", m.Option(BINNARY), msg.Append(nfs.FILE))
m.Option(mdb.TEXT, strings.Join(kit.Slice(strings.Split(m.Cmdx(cli.SYSTEM, cmd), ice.NL), 0, 20), ice.NL))
m.Option(nfs.FILE, msg.Append(nfs.FILE))

View File

@ -2,6 +2,7 @@ package chrome
import (
"path"
"net/http"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/mdb"
@ -26,7 +27,7 @@ func (c cache) Create(m *ice.Message, arg ...string) *ice.Message {
}
// h = c.Hash.Create(m.Spawn(), m.OptionSimple("show,type,name,link")...).Result()
// m.Option(mdb.HASH, h)
msg := m.Cmd("web.spide", ice.DEV, web.SPIDE_CACHE, web.SPIDE_GET, m.Option(mdb.LINK), func(count, total, value int) {
msg := m.Cmd("web.spide", ice.DEV, web.SPIDE_CACHE, http.MethodGet, m.Option(mdb.LINK), func(count, total, value int) {
c.Hash.Modify(m, kit.Simple(mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, kit.Format(value))...)
})
m.Cmdy(nfs.LINK, path.Join(m.Config(nfs.PATH), m.Option(mdb.NAME)), msg.Append(nfs.FILE))

View File

@ -1,6 +1,7 @@
package mp
import (
"net/http"
"encoding/base64"
"time"
@ -39,7 +40,7 @@ func init() {
m.Cmd(web.SPIDE, mdb.CREATE, MP, m.Config(tcp.SERVER))
}},
aaa.SESS: {Name: "sess code", Help: "会话", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, MP, web.SPIDE_GET, "/sns/jscode2session?grant_type=authorization_code",
msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/sns/jscode2session?grant_type=authorization_code",
"js_code", m.Option(cli.CODE), APPID, m.Config(APPID), "secret", m.Config(APPMM))
// 用户登录
@ -71,7 +72,7 @@ func init() {
}},
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
msg := m.Cmd(web.SPIDE, MP, web.SPIDE_GET, "/cgi-bin/token?grant_type=client_credential",
msg := m.Cmd(web.SPIDE, MP, http.MethodGet, "/cgi-bin/token?grant_type=client_credential",
APPID, m.Config(APPID), "secret", m.Config(APPMM))
if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
return
@ -83,7 +84,7 @@ func init() {
m.Echo(m.Config(TOKENS))
}},
QRCODE: {Name: "qrcode path scene", Help: "扫码", Hand: func(m *ice.Message, arg ...string) {
msg := m.Cmd(web.SPIDE, MP, web.SPIDE_POST, "/wxa/getwxacodeunlimit?access_token="+m.Cmdx(LOGIN, TOKENS),
msg := m.Cmd(web.SPIDE, MP, http.MethodPost, "/wxa/getwxacodeunlimit?access_token="+m.Cmdx(LOGIN, TOKENS),
m.OptionSimple("path,scene"))
m.Echo(kit.Format(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString([]byte(msg.Result())), "some"))
m.ProcessInner()

View File

@ -1,6 +1,7 @@
package wx
import (
"net/http"
"crypto/sha1"
"strings"
"time"
@ -76,7 +77,7 @@ func init() {
}},
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM))
msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM))
if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
return
}
@ -87,7 +88,7 @@ func init() {
}},
TICKET: {Name: "ticket", Help: "票据", Hand: func(m *ice.Message, arg ...string) {
if now := time.Now().Unix(); m.Config(TICKET) == "" || now > kit.Int64(m.Config(EXPIRE)) {
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx("", TOKENS))
msg := m.Cmd(web.SPIDE, WX, http.MethodGet, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx("", TOKENS))
if m.Warn(msg.Append(ERRCODE) != "0", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
return
}