1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

mac mod web.travel

This commit is contained in:
shaoying 2018-05-29 08:55:02 +08:00
parent 885b787b3d
commit 2b834d28e0
3 changed files with 109 additions and 41 deletions

View File

@ -46,6 +46,7 @@ type Command struct {
Formats map[string]int
Options map[string]string
Shares map[string][]string
Appends map[string]string
Hand func(m *Message, c *Context, key string, arg ...string)
}
@ -2368,18 +2369,27 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
m.Echo("ok")
}
case m.Has("command"):
if x, ok := group.Commands[item]; ok {
if len(arg) > 2 {
if len(x.Options) > 0 {
for i := 2; i < len(arg)-1; i += 2 {
if x, ok := x.Options[arg[i]]; !ok || x != arg[i+1] {
return
}
}
if len(arg) > 1 {
if _, ok := group.Commands[item]; !ok {
return
}
}
if len(arg) > 2 {
if _, ok := group.Commands[item].Shares[arg[2]]; !ok {
return
}
}
if len(arg) > 3 {
for _, v := range group.Commands[item].Shares[arg[2]] {
if arg[3] == v {
m.Echo("ok")
return
}
}
m.Echo("ok")
return
}
m.Echo("ok")
}
}
return
@ -2411,14 +2421,18 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
if group.Commands == nil {
group.Commands = map[string]*Command{}
}
// group.Commands[item] = x
options := map[string]string{}
command, ok := group.Commands[item]
if !ok {
command = &Command{Shares: map[string][]string{}}
group.Commands[item] = command
}
for i := 2; i < len(arg)-1; i += 2 {
options[arg[i]] = arg[i+1]
}
group.Commands[item] = &Command{
Options: options,
command.Shares[arg[i]] = append(command.Shares[arg[i]], arg[i+1])
}
// group.Commands[item] = x
}
}
@ -2445,7 +2459,38 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
case m.Has("config"):
delete(gs[i].Configs, item)
case m.Has("command"):
delete(gs[i].Commands, item)
if gs[i].Commands == nil {
break
}
if len(arg) == 2 {
delete(gs[i].Commands, item)
break
}
if gs[i].Commands[item] == nil {
break
}
shares := gs[i].Commands[item].Shares
if shares == nil {
break
}
if len(arg) == 3 {
delete(shares, arg[2])
break
}
m.Log("fuck", nil, "wh %v", shares)
for i := 0; i < len(shares[arg[2]]); i++ {
if shares[arg[2]][i] == arg[3] {
m.Log("fuck", nil, "====%v", arg[3])
for ; i < len(shares[arg[2]])-1; i++ {
shares[arg[2]][i] = shares[arg[2]][i+1]
}
shares[arg[2]] = shares[arg[2]][:i]
m.Log("fuck", nil, "====%v", shares)
}
}
default:
delete(index, gs[i].Name)
delete(current.Index, gs[i].Name)

View File

@ -2,6 +2,7 @@ package web // {{{
// }}}
import ( // {{{
"contexts"
"regexp"
"strconv"
"toolkit"
@ -612,29 +613,30 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}
m.Option("right", "")
if !m.Options("sessid") {
aaa := m.Find("aaa").Cmd("login", m.Option("sessid"))
if aaa.Result(0) == "error: " {
m.Option("sessid", "")
m.Option("message", "please login")
m.Option("message", "login failure")
} else {
msg := m.Find("aaa").Cmd("login", m.Option("sessid"))
if msg.Result(0) == "error: " {
m.Option("sessid", "")
m.Option("message", "login failure")
m.Option("username", aaa.Result(0))
msg := m.Spawn(m.Target())
msg.Cmd("right", "check", aaa.Cap("group"), "command", "/upload", "file", dir)
if msg.Result(0) == "ok" {
m.Option("right", aaa.Cap("group"))
} else {
m.Option("username", msg.Result(0))
msg = m.Spawn(m.Target())
msg.Cmd("right", "check", msg.Cap("group"), "command", "/upload", "file", dir)
if msg.Result(0) == "ok" {
m.Option("right", "ok")
} else {
m.Option("message", "your do not have the right of", dir)
}
m.Option("message", "your do not have the right of", dir)
}
}
if m.Option("method") == "POST" {
if m.Options("shareto") {
if m.Options("notshareto") {
msg := m.Spawn(m.Target())
msg.Cmd("right", "del", m.Option("notshareto"), "command", "/upload", "file", m.Option("sharefile"))
m.Append("link", "hello")
return
} else if m.Options("shareto") {
msg := aaa.Spawn(m.Target())
msg.Sesss("aaa", aaa)
msg.Cmd("right", "add", m.Option("shareto"), "command", "/upload", "file", m.Option("sharefile"))
m.Append("link", "hello")
return
@ -739,15 +741,24 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
msg := m.Spawn(m.Target())
for k, v := range msg.Target().Index {
for i, j := range v.Commands {
for v, n := range j.Options {
if n == dir {
msg.Add("append", "group", k)
msg.Add("append", "command", i)
msg.Add("append", "argument", v)
msg.Add("append", "value", n)
m.Log("fuck", nil, "why %v", msg.Meta)
index := msg.Target().Index
if index != nil && index[m.Option("right")] != nil {
for k, v := range index[m.Option("right")].Index {
// for k, v := range index {
for i, j := range v.Commands {
for v, n := range j.Shares {
for _, nn := range n {
match, e := regexp.MatchString(nn, dir)
m.Log("fuck", nil, "why %s %s", nn, dir)
m.Assert(e)
if match {
msg.Add("append", "group", k)
msg.Add("append", "command", i)
msg.Add("append", "argument", v)
msg.Add("append", "value", nn)
msg.Add("append", "delete", "delete")
}
}
}
}
}

View File

@ -61,7 +61,11 @@
<tr>
{{range $key := index $meta "append"}}
<td class="{{$key}}">
<code>{{index $meta $key $i}}</code>
{{if eq $key "delete"}}
<button onclick="return deleteshare(event, '{{index $meta "value" $i}}', '{{index $meta "group" $i}}')">delete</button>
{{else}}
<code>{{index $meta $key $i}}</code>
{{end}}
</td>
{{end}}
</tr>
@ -81,5 +85,13 @@
})
return false;
}
function deleteshare(event, file, group) {
ctx.POST("/upload", {
notshareto: group,
sharefile: file,
}, function(msg) {
ctx.Refresh();
})
}
</script>
{{end}}