forked from x/icebergs
opt keyboard
This commit is contained in:
parent
8e8470d910
commit
e2f4769e95
@ -31,6 +31,14 @@ func _cache_save(m *ice.Message, kind, name, text string, arg ...string) { // fi
|
||||
text = kit.Select(file, text)
|
||||
h := mdb.HashCreate(m, kit.SimpleKV("", kind, name, text), nfs.FILE, file, nfs.SIZE, size)
|
||||
|
||||
if kind == "application/octet-stream" {
|
||||
if kit.ExtIsImage(name) {
|
||||
kind = "image/"+kit.Ext(name)
|
||||
} else if kit.ExtIsVideo(name) {
|
||||
kind = "video/"+kit.Ext(name)
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(mdb.TYPE, kind)
|
||||
|
@ -14,13 +14,12 @@ sso.go
|
||||
|
||||
favor.go
|
||||
iframe.go
|
||||
media.go
|
||||
keyboard.go
|
||||
|
||||
div.go
|
||||
topic.go
|
||||
website.go
|
||||
template.go
|
||||
keyboard.go
|
||||
location.go
|
||||
location.shy
|
||||
trans.go
|
||||
|
@ -9,10 +9,21 @@ import (
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _favor_is_image(m *ice.Message, name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "image/") || kit.ExtIsImage(name)
|
||||
}
|
||||
func _favor_is_video(m *ice.Message, name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "video/") || kit.ExtIsVideo(name)
|
||||
}
|
||||
func _favor_is_audio(m *ice.Message, name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "audio/")
|
||||
}
|
||||
|
||||
const (
|
||||
FAVOR_INPUTS = "favor.inputs"
|
||||
FAVOR_TABLES = "favor.tables"
|
||||
@ -22,7 +33,7 @@ const FAVOR = "favor"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor hash auto create getClipboardData getLocation scanQRCode upload", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
FAVOR: {Name: "favor hash auto create getClipboardData getLocation scanQRCode record1 record2 upload", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.TYPE:
|
||||
@ -31,6 +42,7 @@ func init() {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case ctx.INDEX:
|
||||
m.Copy(m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, arg[1:], ice.OptionFields(ctx.INDEX)).RenameAppend(ctx.INDEX, arg[0]))
|
||||
return
|
||||
}
|
||||
}
|
||||
gdb.Event(m, "", arg)
|
||||
@ -38,6 +50,8 @@ func init() {
|
||||
"getClipboardData": {Name: "favor create", Help: "粘贴"},
|
||||
"getLocation": {Name: "favor create", Help: "定位"},
|
||||
"scanQRCode": {Name: "favor create", Help: "扫码"},
|
||||
"record1": {Name: "favor upload", Help: "截图"},
|
||||
"record2": {Name: "favor upload", Help: "录屏"},
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(mdb.TYPE, mdb.LINK, mdb.NAME, kit.ParseURL(m.Option(mdb.TEXT)).Host)
|
||||
mdb.HashCreate(m, m.OptionSimple())
|
||||
@ -49,7 +63,14 @@ func init() {
|
||||
ctx.ProcessOpen(m, web.MergeURL2(m, web.SHARE_LOCAL+m.Option(mdb.TEXT), "filename", m.Option(mdb.NAME)))
|
||||
}},
|
||||
web.DISPLAY: {Help: "预览", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoImages(web.SHARE_LOCAL + m.Option(mdb.TEXT)).ProcessInner()
|
||||
if link := web.SHARE_LOCAL+m.Option(mdb.TEXT); _favor_is_image(m, m.Option(mdb.NAME), m.Option(mdb.TYPE)) {
|
||||
m.EchoImages(link)
|
||||
} else if _favor_is_video(m, m.Option(mdb.NAME), m.Option(mdb.TYPE)) {
|
||||
m.EchoVideos(link)
|
||||
} else {
|
||||
m.Echo("<audio src=%s autoplay controls/>", link)
|
||||
}
|
||||
m.ProcessInner()
|
||||
}},
|
||||
ctx.INDEX: {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, m.Cmd("", m.Option(mdb.HASH)).Append(mdb.NAME), kit.Simple(kit.UnMarshal(m.Option(mdb.TEXT))), arg...)
|
||||
@ -58,44 +79,47 @@ func init() {
|
||||
m.Option(mdb.TYPE, m.Cmd("", m.Option(mdb.HASH)).Append(mdb.TYPE))
|
||||
ctx.Run(m, arg...)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text"), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text"), ctx.CmdAction(), KeyboardAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ctx.ACTION {
|
||||
m.Option(mdb.TYPE, m.Cmd("", m.Option(mdb.HASH)).Append(mdb.TYPE))
|
||||
gdb.Event(m, FAVOR_ACTION, arg)
|
||||
return
|
||||
}
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
m.Tables(func(value ice.Maps) {
|
||||
if msg := gdb.Event(m.Spawn(), FAVOR_TABLES, mdb.TYPE, value[mdb.TYPE]); msg.Append(ctx.ACTION) != "" {
|
||||
m.PushButton(msg.Append(ctx.ACTION))
|
||||
return
|
||||
}
|
||||
switch value[mdb.TYPE] {
|
||||
case ctx.INDEX:
|
||||
m.PushButton(ctx.INDEX, mdb.REMOVE)
|
||||
default:
|
||||
if strings.HasPrefix(value[mdb.TEXT], ice.VAR_FILE) {
|
||||
if kit.ExtIsImage(value[mdb.NAME]) {
|
||||
m.PushButton(web.DISPLAY, web.DOWNLOAD, mdb.REMOVE)
|
||||
} else {
|
||||
m.PushButton(web.DOWNLOAD, mdb.REMOVE)
|
||||
}
|
||||
} else {
|
||||
m.PushButton(mdb.REMOVE)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
text := m.Append(mdb.TEXT)
|
||||
if strings.HasPrefix(m.Append(mdb.TEXT), ice.VAR_FILE) {
|
||||
link := web.SHARE_LOCAL + m.Append(mdb.TEXT)
|
||||
if m.PushDownload(mdb.LINK, m.Append(mdb.NAME), link); len(arg) > 0 && kit.ExtIsImage(m.Append(mdb.NAME)) {
|
||||
m.PushImages(web.DISPLAY, link)
|
||||
text = web.SHARE_LOCAL + m.Append(mdb.TEXT)
|
||||
if m.PushDownload(mdb.LINK, m.Append(mdb.NAME), text); len(arg) > 0 && _favor_is_image(m, m.Append(mdb.NAME), m.Append(mdb.TYPE)) {
|
||||
m.PushImages(web.DISPLAY, text)
|
||||
} else if _favor_is_video(m, m.Append(mdb.NAME), m.Append(mdb.TYPE)) {
|
||||
m.PushVideos(web.DISPLAY, text)
|
||||
}
|
||||
text = web.MergeLink(m, text)
|
||||
text = tcp.ReplaceLocalhost(m, text)
|
||||
}
|
||||
m.PushScript(ssh.SCRIPT, text)
|
||||
m.PushQRCode(cli.QRCODE, text)
|
||||
}
|
||||
m.Tables(func(value ice.Maps) {
|
||||
if msg := gdb.Event(m.Spawn(), FAVOR_TABLES, mdb.TYPE, value[mdb.TYPE]); msg.Append(ctx.ACTION) != "" {
|
||||
m.PushButton(msg.Append(ctx.ACTION))
|
||||
return
|
||||
}
|
||||
switch value[mdb.TYPE] {
|
||||
case ctx.INDEX:
|
||||
m.PushButton(ctx.INDEX, mdb.REMOVE)
|
||||
default:
|
||||
if strings.HasPrefix(value[mdb.TEXT], ice.VAR_FILE) {
|
||||
if _favor_is_image(m, value[mdb.NAME], value[mdb.TYPE]) || _favor_is_video(m, value[mdb.NAME], value[mdb.TYPE]) || _favor_is_audio(m, value[mdb.NAME], value[mdb.TYPE]) {
|
||||
m.PushButton(web.DISPLAY, web.DOWNLOAD, mdb.REMOVE)
|
||||
} else {
|
||||
m.PushButton(web.DOWNLOAD, mdb.REMOVE)
|
||||
}
|
||||
} else {
|
||||
m.PushButton(mdb.REMOVE)
|
||||
}
|
||||
}
|
||||
m.PushScript(ssh.SCRIPT, m.Append(mdb.TEXT))
|
||||
m.PushQRCode(cli.QRCODE, m.Append(mdb.TEXT))
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -4,51 +4,33 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const KEYBOARD = "keyboard"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
KEYBOARD: {Name: "keyboard hash@keyboard auto", Help: "键盘", Actions: ice.MergeActions(ice.Actions{
|
||||
"_refresh": {Name: "refresh", Help: "刷新", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(web.SPACE, m.Option(web.SPACE), "refresh")
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
"input": {Name: "input", Help: "刷新", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(web.SPACE, m.Option(web.SPACE), "input", arg)
|
||||
ctx.ProcessHold(m)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, "", mdb.FIELD, "time,hash,space,index,input")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ctx.ACTION {
|
||||
m.Cmd(web.SPACE, m.Option(web.SPACE), arg)
|
||||
ctx.ProcessHold(m)
|
||||
return
|
||||
}
|
||||
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
|
||||
KEYBOARD: {Name: "keyboard hash auto", Help: "键盘", Actions: ice.MergeActions(ice.Actions{
|
||||
web.SPACE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(web.SPACE, m.Option(web.SPACE), arg) }},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,space,index,input")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
msg := m.Cmd(ctx.COMMAND, m.Append(ctx.INDEX))
|
||||
meta := kit.UnMarshal(msg.Append(mdb.META))
|
||||
list := kit.UnMarshal(msg.Append(mdb.LIST))
|
||||
keys := []string{}
|
||||
kit.Fetch(list, func(index int, value ice.Any) {
|
||||
if kit.Format(kit.Value(value, mdb.TYPE)) == "button" {
|
||||
return
|
||||
}
|
||||
keys = append(keys, kit.Format(kit.Value(value, mdb.NAME)))
|
||||
})
|
||||
kit.Fetch(meta, func(key string, value ice.Any) {
|
||||
if key == "_trans" {
|
||||
return
|
||||
}
|
||||
keys = append(keys, key)
|
||||
})
|
||||
m.PushAction(kit.Join(keys))
|
||||
m.Option(mdb.META, kit.Format(meta))
|
||||
m.Push(mdb.META, msg.Append(mdb.META))
|
||||
m.Push(mdb.LIST, msg.Append(mdb.LIST))
|
||||
ctx.DisplayLocal(m, "")
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func KeyboardAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
KEYBOARD: {Help: "远程控制", Hand: func(m *ice.Message, arg ...string) {
|
||||
hash := m.Cmdx("web.chat.keyboard", mdb.CREATE, web.SPACE, m.Option(ice.MSG_DAEMON), ctx.INDEX, m.Option(ctx.INDEX), "input", "")
|
||||
link := tcp.ReplaceLocalhost(m, web.MergePodCmd(m, "", "web.chat.keyboard", mdb.HASH, hash))
|
||||
m.Push(mdb.NAME, link).PushQRCode(mdb.TEXT, link)
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const MEDIA = "media"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MEDIA: {Name: "media path auto", Help: "媒体", Actions: ice.MergeActions(ice.Actions{
|
||||
web.UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.CACHE, web.UPLOAD_WATCH, ice.USR_LOCAL_MEDIA)
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.TRASH, path.Join(ice.USR_LOCAL_MEDIA, m.Option(nfs.PATH)))
|
||||
}},
|
||||
}, web.ApiAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_MEDIA)
|
||||
ctx.DisplayStory(m.Cmdy(nfs.DIR, nfs.PWD), "media.js")
|
||||
return
|
||||
}
|
||||
if m.R.Method == http.MethodGet {
|
||||
m.RenderDownload(kit.Path(ice.USR_LOCAL_MEDIA, path.Join(arg...)))
|
||||
} else {
|
||||
m.EchoVideos("/chat/media/"+path.Join(arg...), m.Option("height"))
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -41,6 +41,9 @@ func Render(m *Message, cmd string, args ...Any) string {
|
||||
return kit.Format(`<img src="%s" height=%d>`, arg[0], kit.Int(kit.Select(kit.Select("240", m.Option("height")), arg, 1))/2-24)
|
||||
|
||||
case RENDER_VIDEOS: // src [height]
|
||||
if m.Option("height") != "" && m.Option("width") != "" {
|
||||
return kit.Format(`<video src="%s" controls style="max-height:%spx; max-width:%spx">`, arg[0], m.Option("height"), m.Option("width"))
|
||||
}
|
||||
return kit.Format(`<video src="%s" height=%s controls>`, arg[0], kit.Select("120", arg, 1))
|
||||
|
||||
case RENDER_IFRAME: // src
|
||||
|
Loading…
x
Reference in New Issue
Block a user