1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
shaoying 2022-12-03 09:38:31 +08:00
parent b9b56ace5b
commit 73580d0df5
8 changed files with 43 additions and 29 deletions

View File

@ -14,7 +14,7 @@ const OFFER = "offer"
func init() {
Index.MergeCommands(ice.Commands{
OFFER: {Name: "offer hash auto", Actions: ice.MergeActions(ice.Actions{
OFFER: {Name: "offer hash auto", Help: "邀请", Actions: ice.MergeActions(ice.Actions{
INVITE: {Name: "invite email='shylinux@163.com' content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
h := mdb.HashCreate(m, m.OptionSimple(EMAIL, "content"), "from", m.Option(ice.MSG_USERNAME))
msg := m.Cmd("web.share", mdb.CREATE, mdb.TYPE, "field", mdb.NAME, m.PrefixKey(), mdb.TEXT, kit.Format(kit.List(h)),

View File

@ -135,7 +135,6 @@ func Right(m *ice.Message, key ...ice.Any) bool {
return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key) != ice.OK,
ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(2))
}
func White(m *ice.Message, key ...string) {
for _, key := range key {
m.Cmd(ROLE, WHITE, VOID, key)

View File

@ -19,7 +19,7 @@ func _broad_addr(m *ice.Message, host, port string) *net.UDPAddr {
return nil
}
func _broad_send(m *ice.Message, host, port string, remote_host, remote_port string) {
if s, e := net.DialUDP("udp", nil, _broad_addr(m, remote_host, remote_port)); !m.Warn(e, ice.ErrNotValid) {
if s, e := net.DialUDP("udp4", nil, _broad_addr(m, remote_host, remote_port)); !m.Warn(e, ice.ErrNotValid) {
defer s.Close()
msg := m.Spawn(kit.Dict(tcp.HOST, host, tcp.PORT, port))
m.Logs(mdb.EXPORT, BROAD, msg.FormatMeta(), "to", remote_host+ice.DF+remote_port)
@ -33,11 +33,11 @@ func _broad_serve(m *ice.Message, host, port string) {
defer mdb.HashCreateDeferRemove(m, tcp.HOST, host, tcp.PORT, port, kit.Dict(mdb.TARGET, s))()
buf := make([]byte, ice.MOD_BUFS)
for {
n, addr, err := s.ReadFromUDP(buf[:])
if err != nil {
n, from, e := s.ReadFromUDP(buf[:])
if e != nil {
break
}
m.Logs(mdb.IMPORT, BROAD, string(buf[:n]), "from", addr)
m.Logs(mdb.IMPORT, BROAD, string(buf[:n]), "from", from)
msg := m.Spawn(buf[:n])
if m.Cmd(BROAD, kit.Format("%s,%s", msg.Option(tcp.HOST), msg.Option(tcp.PORT))).Length() > 0 {
continue

View File

@ -71,7 +71,6 @@ func _cache_upload(m *ice.Message, r *http.Request) (mime, name, file, size stri
return "", "", "", "0"
}
func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any) string {
defer r.Body.Close()
if f, p, e := miss.CreateFile(file); !m.Warn(e, ice.ErrNotValid, DOWNLOAD) {
defer f.Close()
last, step, bufs := 0, 10, 10*ice.MOD_BUFS

View File

@ -59,8 +59,8 @@ func _dream_show(m *ice.Message, name string) {
), cli.CMD_OUTPUT, path.Join(p, ice.BIN_BOOT_LOG))
defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "")
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE))
bin := kit.Select(os.Args[0], cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN))
m.Cmd(cli.DAEMON, bin, SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME, RIVER), cli.DAEMON, ice.OPS)
m.Cmd(cli.DAEMON, kit.Select(os.Args[0], cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN)),
SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME, RIVER), cli.DAEMON, ice.OPS)
}
func _dream_template(m *ice.Message, p string) {
nfs.MkdirAll(m, p)

View File

@ -139,7 +139,6 @@ const (
SERVE_PARSE = "serve.parse"
SERVE_LOGIN = "serve.login"
SERVE_CHECK = "serve.check"
SERVE_RENDER = "serve.render"
SERVE_STOP = "serve.stop"
WEB_LOGIN = "_login"
@ -233,7 +232,6 @@ func init() {
if sub = kit.Select(sub, PP(key), sub == ice.PS); action.Hand == nil {
action.Hand = func(m *ice.Message, arg ...string) { m.Cmdy(key, arg) }
}
// c.Commands[sub] = &ice.Command{Name: sub, Help: cmd.Help, Actions: cmd.Actions, Hand: action.Hand}
actions := ice.Actions{}
for k, v := range cmd.Actions {
switch k {
@ -247,5 +245,5 @@ func init() {
})
}
func ServeAction() ice.Actions {
return gdb.EventsAction(SERVE_START, SERVE_REWRITE, SERVE_PARSE, SERVE_LOGIN, SERVE_CHECK, SERVE_RENDER, SERVE_STOP)
return gdb.EventsAction(SERVE_START, SERVE_REWRITE, SERVE_PARSE, SERVE_LOGIN, SERVE_CHECK, SERVE_STOP)
}

View File

@ -13,6 +13,7 @@ import (
"time"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
@ -27,13 +28,13 @@ func _spide_create(m *ice.Message, name, address string) {
dir, file := path.Split(uri.EscapedPath())
value[SPIDE_CLIENT] = kit.Dict(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,
cli.TIMEOUT, "30s", LOGHEADERS, ice.FALSE,
)
})
}
}
func _spide_args(m *ice.Message, arg []string, val ...string) (string, []string) {
if kit.IndexOf(val, arg[0]) {
if kit.IndexOf(val, arg[0]) > -1 {
return arg[0], arg[1:]
}
return "", arg
@ -53,6 +54,9 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
method = kit.Select(http.MethodPost, kit.Select(msg.Append(CLIENT_METHOD), method))
uri, arg := arg[0], arg[1:]
body, head, arg := _spide_body(m, method, arg...)
if c, ok := body.(io.Closer); ok {
defer c.Close()
}
req, e := http.NewRequest(method, kit.MergeURL2(msg.Append(CLIENT_URL), uri, arg), body)
if m.Warn(e, ice.ErrNotValid, uri) {
return
@ -100,6 +104,7 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.M
head[ContentType], body = ContentJSON, bytes.NewBufferString(kit.Select("{}", arg, 1))
case SPIDE_FILE:
if f, e := nfs.OpenFile(m, arg[1]); m.Assert(e) {
m.Logs(mdb.IMPORT, nfs.FILE, arg[1])
body = f
}
case SPIDE_JSON:
@ -125,11 +130,11 @@ func _spide_part(m *ice.Message, arg ...string) (string, io.Reader) {
if arg[i] == nfs.SIZE {
size = kit.Int64(arg[i+1])
} else if arg[i] == SPIDE_CACHE {
if t, e := time.ParseInLocation(ice.MOD_TIME, arg[i+1], time.Local); e == nil {
if t, e := time.ParseInLocation(ice.MOD_TIME, arg[i+1], time.Local); !m.Warn(e, ice.ErrNotValid) {
cache = t
}
} else if strings.HasPrefix(arg[i+1], ice.AT) {
if s, e := nfs.StatFile(m, arg[i+1][1:]); e == nil {
if s, e := nfs.StatFile(m, arg[i+1][1:]); !m.Warn(e, ice.ErrNotValid) {
if s.Size() == size && s.ModTime().Before(cache) {
continue
}
@ -150,7 +155,7 @@ func _spide_part(m *ice.Message, arg ...string) (string, io.Reader) {
return mp.FormDataContentType(), buf
}
func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map) {
m.Logs(req.Method, req.URL)
m.Logs(req.Method, req.URL.String())
kit.Fetch(value[SPIDE_HEADER], func(k string, v string) {
req.Header.Set(k, v)
m.Logs("Header", k, v)
@ -195,9 +200,8 @@ func _spide_save(m *ice.Message, format, file, uri string, res *http.Response) {
case SPIDE_SAVE:
_cache_download(m, res, file, m.OptionCB(SPIDE))
case SPIDE_CACHE:
m.Optionv(RESPONSE, res)
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri)
m.Echo(m.Append(mdb.DATA))
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri, kit.Dict(RESPONSE, res))
m.Echo(m.Append(mdb.HASH))
default:
var data ice.Any
if b, e := ioutil.ReadAll(res.Body); !m.Warn(e) {
@ -213,8 +217,8 @@ func _spide_save(m *ice.Message, format, file, uri string, res *http.Response) {
const (
SPIDE_RAW = "raw"
SPIDE_MSG = "msg"
SPIDE_SAVE = "save"
SPIDE_CACHE = "cache"
SPIDE_SAVE = "save"
SPIDE_BODY = "body"
SPIDE_FORM = "form"
@ -246,7 +250,7 @@ const (
CLIENT_PROTOCOL = "client.protocol"
CLIENT_HOSTNAME = "client.hostname"
CLIENT_NAME = "client.name"
CLIENT_METHOD = "client.method"
CLIENT_TIMEOUT = "client.timeout"
@ -283,14 +287,20 @@ func init() {
m.Push(DOMAIN, msg.Append(CLIENT_PROTOCOL)+"://"+msg.Append(CLIENT_HOSTNAME)+kit.Select("", arg, 1))
m.Push(tcp.PROTOCOL, msg.Append(CLIENT_PROTOCOL)).Push(tcp.HOSTNAME, msg.Append(CLIENT_HOSTNAME))
}},
MERGE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.MergeURL2(m.CmdAppend("", arg[0], CLIENT_URL), arg[1], arg[2:])) }},
MERGE: {Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.MergeURL2(m.CmdAppend("", arg[0], CLIENT_URL), arg[1], arg[2:]))
}},
}, mdb.HashAction(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url", LOGHEADERS, ice.FALSE), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) < 2 || arg[0] == "" || (len(arg) > 3 && arg[3] == "") {
mdb.HashSelect(m, kit.Slice(arg, 0, 1)...).Sort(CLIENT_NAME)
} else {
_spide_show(m, arg...)
_spide_show(m, arg[0], arg[1:]...)
}
}},
"/spide-demo/": {Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
m.Push("hi", "hello")
m.Echo("hello world")
}},
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:]))))
}},
@ -306,10 +316,18 @@ func init() {
})
}
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 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, http.MethodGet, link, cb)
}

View File

@ -96,7 +96,7 @@ const WEB = "web"
var Index = &ice.Context{Name: WEB, Help: "网络模块"}
func init() {
ice.Index.Register(Index, &Frame{}, BROAD, SERVE, SPACE, DREAM, CACHE, SPIDE, SHARE)
ice.Index.Register(Index, &Frame{}, BROAD, SERVE, SPACE, DREAM, SHARE, CACHE, SPIDE)
}
func ApiAction(arg ...string) ice.Actions { return ice.Actions{kit.Select(ice.PS, arg, 0): {}} }