diff --git a/etc/init.shy b/etc/init.shy index d532bfcd..f2fafafe 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,7 +1,7 @@ ~stdio config load history.json history ~web - # config load web.json + config load web.json ~aaa login root root diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index 97be2c26..a1f8ce70 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -3057,7 +3057,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", arg, all = arg[1:], true } - action, which := "", "-1" + action, which, chain := "", "-1", "" have := map[string]bool{} if len(arg) > 0 { switch arg[0] { @@ -3073,6 +3073,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心", } case "create", "delete": action, arg = arg[0], arg[1:] + case "parse": + chain, arg = arg[1], arg[2:] } } @@ -3156,7 +3158,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", msg := m.Spawn() msg.Put("option", "_cache", value) - msg.Cmd("trans", "_cache", "") + msg.Cmd("trans", "_cache", chain) m.Copy(msg, "append").Copy(msg, "result") }}, "cache": &Command{Name: "cache [all] |key [value]|key = value|key name value help|delete key]", diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 49ea9824..75ac9233 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -434,9 +434,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if m.Has("method") { method = m.Option("method") } - m.Log("fuck", "what %s", method) - m.Log("fuck", "what %s", m.Option("method")) - m.Log("fuck", "what %s", m.Conf("method")) uri := Merge(m, arg[0], arg[1:]...) body, _ := m.Optionv("body").(io.Reader) @@ -446,7 +443,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } } - m.Log("fuck", "what %s", method) req, e := http.NewRequest(method, uri, body) m.Assert(e) @@ -515,6 +511,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } ct := res.Header.Get("Content-Type") + m.Log("info", "content: %s", ct) switch { case strings.HasPrefix(ct, "application/json"): json.NewDecoder(res.Body).Decode(&result) @@ -558,6 +555,19 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", m.Add("append", "html", html) } }) + case strings.HasPrefix(ct, "text"): + buf, e := ioutil.ReadAll(res.Body) + m.Assert(e) + if m.Has("parse") { + json.Unmarshal(buf, &result) + m.Log("fuck", "%v ", result) + msg := m.Spawn() + msg.Put("option", "response", result) + msg.Cmd("trans", "response", m.Option("parse")) + m.Copy(msg, "append").Copy(msg, "result") + return + } + result = string(buf) default: if w, ok := m.Optionv("response").(http.ResponseWriter); ok { header := w.Header()