mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt location.go
This commit is contained in:
parent
18d9f9f3e4
commit
adcbdb8365
@ -97,6 +97,9 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
kit.For(u.Query(), func(k string, v []string) { _log(ctx.ARGS, k, v).Optionv(k, v) })
|
||||
}
|
||||
kit.For(kit.ParseQuery(r.URL.RawQuery), func(k string, v []string) { m.Optionv(k, v) })
|
||||
if r.Method == http.MethodGet && m.Option(ice.MSG_CMDS) != "" {
|
||||
_log(ctx.ARGS, ice.MSG_CMDS, m.Optionv(ice.MSG_CMDS))
|
||||
}
|
||||
switch r.Header.Get(ContentType) {
|
||||
case ApplicationJSON:
|
||||
kit.For(kit.UnMarshal(r.Body), func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
@ -115,7 +118,7 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
defer func() { Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...) }()
|
||||
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/%s %v", r.Method, m.PrefixKey(), path.Join(cmds...), m.FormatSize()))
|
||||
m.Cost(kit.Format("%s: /chat/cmd/%s/%s %v %s", r.Method, m.Option(ice.MSG_INDEX), path.Join(cmds...), m.FormatSize(), kit.FmtSize(len(m.Result()))))
|
||||
}()
|
||||
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION {
|
||||
|
@ -8,6 +8,7 @@ action.go
|
||||
search.go
|
||||
portal.go
|
||||
iframe.go
|
||||
trans.go
|
||||
icons.go
|
||||
|
||||
pod.go
|
||||
@ -17,7 +18,6 @@ grant.go
|
||||
oauth
|
||||
|
||||
macos
|
||||
trans.go
|
||||
favor.go
|
||||
flows.go
|
||||
flows.js
|
||||
|
@ -2,7 +2,6 @@ package chat
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
@ -20,62 +19,43 @@ const (
|
||||
const LOCATION = "location"
|
||||
|
||||
func init() {
|
||||
location := sync.Map{}
|
||||
cache := func(m *ice.Message, key string, load func() string) ice.Any {
|
||||
if current, ok := location.Load(key); ok {
|
||||
m.Debug("read cache %v", key)
|
||||
return current
|
||||
}
|
||||
current := load()
|
||||
location.Store(key, current)
|
||||
m.Debug("load cache %v %v", key, current)
|
||||
return current
|
||||
}
|
||||
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(http.MethodGet, "https://apis.map.qq.com/ws/"+api, mdb.KEY, mdb.Config(m, aaa.TOKEN), arg)
|
||||
return kit.Format(mdb.Cache(m, kit.Join(kit.Simple(api, arg)), func() ice.Any {
|
||||
res := kit.UnMarshal(m.Cmdx(http.MethodGet, "https://apis.map.qq.com/ws/"+api, mdb.KEY, mdb.Config(m, aaa.TOKEN), arg))
|
||||
m.Warn(kit.Format(kit.Value(res, "status")) != "0", kit.Format(res))
|
||||
m.Debug("what %v %v", api, kit.Format(res))
|
||||
return kit.Format(res)
|
||||
}))
|
||||
}
|
||||
|
||||
Index.MergeCommands(ice.Commands{
|
||||
LOCATION: {Name: "location hash auto", Help: "地理位置", Actions: ice.MergeActions(ice.Actions{
|
||||
FAVOR_INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case mdb.TYPE:
|
||||
m.Push(arg[0], LOCATION)
|
||||
}
|
||||
LOCATION: {Name: "location hash auto", Help: "地图", Icon: "Maps.png", Actions: ice.MergeActions(ice.Actions{
|
||||
"explore": {Help: "周边", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "place/v1/explore", m.OptionSimple("keyword,boundary,page_index")))
|
||||
}},
|
||||
FAVOR_ACTION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.TYPE) != LOCATION {
|
||||
return
|
||||
}
|
||||
ctx.ProcessField(m, m.PrefixKey(), []string{m.Option(mdb.TEXT)}, arg...)
|
||||
}},
|
||||
FAVOR_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[1] {
|
||||
case LOCATION:
|
||||
m.PushButton(LOCATION, mdb.REMOVE)
|
||||
}
|
||||
}},
|
||||
"explore": {Name: "explore", Help: "周边", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "place/v1/explore", m.OptionSimple("boundary,page_index")))
|
||||
}},
|
||||
"search": {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == "*" {
|
||||
return
|
||||
}
|
||||
"search": {Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "place/v1/search", m.OptionSimple("keyword,boundary,page_index")))
|
||||
}},
|
||||
"direction": {Name: "direction", Help: "导航", Hand: func(m *ice.Message, arg ...string) {
|
||||
"direction": {Help: "导航", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "direction/v1/"+m.Option(mdb.TYPE)+nfs.PS, m.OptionSimple("from,to")))
|
||||
}},
|
||||
"district": {Name: "district", Help: "地区", Hand: func(m *ice.Message, arg ...string) {
|
||||
"district": {Help: "地区", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(get(m, "district/v1/getchildren", m.OptionSimple(mdb.ID)))
|
||||
}},
|
||||
}, FavorAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,latitude,longitude,extra")), Hand: func(m *ice.Message, arg ...string) {
|
||||
FAVOR_INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(arg[0] == mdb.TYPE, func() { m.Push(arg[0], LOCATION) })
|
||||
}},
|
||||
FAVOR_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(arg[1] == LOCATION, func() { m.PushButton(LOCATION, mdb.REMOVE) })
|
||||
}},
|
||||
FAVOR_ACTION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.TYPE) == LOCATION, func() { ctx.ProcessField(m, m.PrefixKey(), []string{m.Option(mdb.TEXT)}, arg...) })
|
||||
}},
|
||||
}, FavorAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,latitude,longitude,extra", nfs.SCRIPT, "https://map.qq.com/api/gljs?v=1.exp")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, kit.Slice(arg, 0, 1)...)
|
||||
ctx.DisplayLocal(m, "", ctx.ConfigSimple(m, aaa.TOKEN))
|
||||
// m.Option(LOCATION, m.Cmdx(web.SERVE, tcp.HOST))
|
||||
m.Option(LOCATION, get(m, "location/v1/ip", aaa.IP, m.Option(ice.MSG_USERIP)))
|
||||
m.Option(nfs.SCRIPT, kit.MergeURL(mdb.Config(m, nfs.SCRIPT), "key", mdb.Config(m, aaa.TOKEN)))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -24,7 +24,14 @@ const (
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BUFFER: {Name: "buffer name value auto", Help: "缓存", Actions: ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.IsSearchPreview(m, arg, func() []string {
|
||||
if text := _tmux_cmds(m, SHOW_BUFFER); text != "" {
|
||||
return []string{mdb.TEXT, "", text}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create value*", Hand: func(m *ice.Message, arg ...string) { _tmux_cmd(m, SET_BUFFER, m.Option(mdb.VALUE)) }},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { _tmux_cmd(m, DELETE_BUFFER, "-b", m.Option(mdb.NAME)) }},
|
||||
mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user