1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-08-26 21:09:20 +08:00
parent c0a8cdc167
commit b33c98c634
3 changed files with 24 additions and 3 deletions

View File

@ -141,6 +141,9 @@ func Template(m templateMessage, p string, arg ...ice.Any) string {
func TemplateText(m templateMessage, p string) string {
return m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(p)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE))
}
func TemplatePath(m templateMessage, arg ...string) string {
return path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...))
}
func IsSourceFile(m *ice.Message, ext string) bool {
return mdb.Conf(m, Prefix(CAT), kit.Keym(SOURCE, ext)) == ice.TRUE
}

View File

@ -108,7 +108,10 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
kit.If(m.Optionv(ice.MSG_CMDS) == nil, func() {
kit.If(strings.TrimPrefix(r.URL.Path, key), func(p string) { m.Optionv(ice.MSG_CMDS, strings.Split(p, nfs.PS)) })
})
defer func() { Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...) }()
defer func() {
Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...)
m.Debug("what %v", m.FormatMeta())
}()
if cmds, ok := _serve_auth(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok {
defer func() { m.Cost(kit.Format("%s: %s %v", r.Method, m.PrefixPath()+path.Join(cmds...), m.FormatSize())) }()
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))

View File

@ -53,12 +53,23 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
return
}
defer res.Body.Close()
m.Push(mdb.TYPE, "status")
m.Push(mdb.NAME, res.StatusCode)
m.Push(mdb.VALUE, res.Status)
m.Cost(cli.STATUS, res.Status, nfs.SIZE, kit.FmtSize(kit.Int64(res.Header.Get(ContentLength))), mdb.TYPE, res.Header.Get(ContentType))
kit.For(res.Header, func(k string, v []string) { m.Logs("response", k, v) })
kit.For(res.Header, func(k string, v []string) {
m.Logs("response", k, v)
m.Push(mdb.TYPE, "header")
m.Push(mdb.NAME, k)
m.Push(mdb.VALUE, v[0])
})
mdb.HashSelectUpdate(m, name, func(value ice.Map) {
kit.For(res.Cookies(), func(v *http.Cookie) {
kit.Value(value, kit.Keys(SPIDE_COOKIE, v.Name), v.Value)
m.Logs("response", v.Name, v.Value)
m.Push(mdb.TYPE, "cookie")
m.Push(mdb.NAME, v.Name)
m.Push(mdb.VALUE, v.Value)
})
})
if m.Warn(res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated, ice.ErrNotValid, uri, cli.STATUS, res.Status) {
@ -168,9 +179,13 @@ func _spide_send(m *ice.Message, name string, req *http.Request, timeout string)
return client.Do(req)
}
func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
if action == SPIDE_RAW {
m.SetResult()
} else {
m.SetAppend().SetResult()
}
switch action {
case SPIDE_RAW:
m.SetResult()
if b, _ := ioutil.ReadAll(res.Body); strings.HasPrefix(res.Header.Get(ContentType), ApplicationJSON) {
m.Echo(kit.Formats(kit.UnMarshal(string(b))))
} else {