From c40ca23954bef10020b110b9f7e943c88950ed27 Mon Sep 17 00:00:00 2001 From: cdle Date: Tue, 20 Jun 2023 13:04:16 +0800 Subject: [PATCH] x --- core/api_bucket.go | 5 +-- core/function.go | 4 +-- core/node_strings.go | 75 ++++++++++++++++++++++++++++++++++++++++ core/plugin_impl.go | 5 +++ core/plugin_subscribe.go | 2 +- core/plugin_utils.go | 1 + mongodb/main.go | 26 ++++++++------ 7 files changed, 102 insertions(+), 16 deletions(-) diff --git a/core/api_bucket.go b/core/api_bucket.go index 04c6e3a..acd66f0 100644 --- a/core/api_bucket.go +++ b/core/api_bucket.go @@ -31,6 +31,7 @@ func init() { ar := strings.Split(bk, ".") if len(ar) == 2 { if ar[0] == "plugins" && false { //todo + // data[bk] = halfDeEct(MakeBucket(ar[0]).GetString(ar[1])) } else { // data[bk] = MakeBucket(ar[0]).GetString(ar[1]) @@ -133,8 +134,8 @@ func init() { for _, bk := range arr { ar := strings.Split(bk, ".") if len(ar) == 2 { - if ar[0] == "plugins" && false { //todo - data[bk] = halfDeEct(MakeBucket(ar[0]).GetString(ar[1])) + if ar[0] == "plugins" && IsCdle { //todo + data[bk] = DecryptPlugin(halfDeEct(MakeBucket(ar[0]).GetString(ar[1]))) } else { data[bk] = TransformBucketKeyValue(MakeBucket(ar[0]).GetString(ar[1])) } diff --git a/core/function.go b/core/function.go index e228902..3256fa4 100644 --- a/core/function.go +++ b/core/function.go @@ -376,7 +376,7 @@ func AddCommand(cmds []*common.Function) { } fmtRule(cmds[j]) { - if !cmds[j].Disable && !cmds[j].Module && !cmds[j].OnStart { + if !cmds[j].Disable && !cmds[j].Module { for plt, Cron := range cmds[j].Cron { plt := plt cron := strings.TrimSpace(Cron) @@ -585,7 +585,7 @@ func HandleMessage(sender common.Sender) { } } for _, function := range Functions { - if function.Disable || function.Module || function.OnStart { + if function.Disable || function.Module { continue } imType := sender.GetImType() diff --git a/core/node_strings.go b/core/node_strings.go index de7501f..546c29b 100644 --- a/core/node_strings.go +++ b/core/node_strings.go @@ -18,6 +18,81 @@ import ( type Strings struct { } +func (sender *Strings) Diff(a, b []interface{}) []interface{} { + m := make(map[interface{}]bool) + c := make([]interface{}, 0) + for _, v := range b { + m[v] = true + } + for _, v := range a { + if !m[v] { + c = append(c, v) + } + } + return c +} + +// 寻找所有共同拥有的连续最长字符串 +func (sender *Strings) Intersects(sa, sb string) []string { + var common []string + for i := 0; i < len(sa); i++ { + for j := i + 1; j <= len(sa); j++ { + substr := sa[i:j] + if len(substr) > 0 && strings.Contains(sb, substr) && !Contains(common, substr) { + common = append(common, substr) + } + } + } + return common +} + +func (sender *Strings) Intersect(a, b interface{}) interface{} { + // 判断是否为字符串类型 + if sa, ok := a.(string); ok { + if sb, ok := b.(string); ok { + // 如果是字符串类型,则寻找共同拥有的最长字符串 + var longest string + for i := 0; i < len(sa); i++ { + for j := i + 1; j <= len(sa); j++ { + substr := sa[i:j] + if strings.Contains(sb, substr) && len(substr) > len(longest) { + longest = substr + } + } + } + return longest + } + } + + // 否则,使用普通的交集算法 + m := make(map[interface{}]bool) + c := make([]interface{}, 0) + for _, v := range a.([]interface{}) { + m[v] = true + } + for _, v := range b.([]interface{}) { + if m[v] { + c = append(c, v) + } + } + return c +} + +func (sender *Strings) Union(a, b []interface{}) []interface{} { + m := make(map[interface{}]bool) + c := make([]interface{}, 0) + for _, v := range a { + m[v] = true + c = append(c, v) + } + for _, v := range b { + if !m[v] { + c = append(c, v) + } + } + return c +} + func (sender *Strings) Random(length int, substr string) string { ws := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" if substr != "" { diff --git a/core/plugin_impl.go b/core/plugin_impl.go index 5451f2e..462288a 100644 --- a/core/plugin_impl.go +++ b/core/plugin_impl.go @@ -473,12 +473,17 @@ type TimeJsImpl struct { Minute time.Duration Hour time.Duration Day time.Duration + Month int } func (t *TimeJsImpl) Now() time.Time { return time.Now() } +func (t *TimeJsImpl) Date(year int, month int, day int, hour int, min int, sec int, nsec int) time.Time { + return time.Date(year, time.Month(month), day, hour, min, sec, nsec, loc) +} + func (t *TimeJsImpl) Sleep(i int) { time.Sleep(time.Duration(i) * time.Millisecond) } diff --git a/core/plugin_subscribe.go b/core/plugin_subscribe.go index 5bc2d1d..363b151 100644 --- a/core/plugin_subscribe.go +++ b/core/plugin_subscribe.go @@ -29,7 +29,7 @@ type RequestPluginResult struct { var plugin_list = []*common.Function{} -var cdle_sublink = "link://T4EywWN46ztYBhHNdOl6TjL4plwqQWRUoqr8w0KFmMqAdblZX3/xtrZARf3VKKQmH6iQNfyWvB2bqf6P1n/CMh1KLHLbTvUzh9zBQS2u9GeYwAp0APEZvQV1O6pb5g9V/dd6TLH54ssD92DAuMa1xw==" +var cdle_sublink = "link://T4EywWN46ztYBhHNdOl6Tpz8QQsCZGj8JvdRJ5QKatJm0P+mI/G3ruO7AC04guqqKKa29VOvTGR7ATUJGYayRBpG2RFq+6ZPK3vcu6KCDGvRE3S43Gj42EXfvs04M6s4" func initPluginList() { list := []*common.Function{} diff --git a/core/plugin_utils.go b/core/plugin_utils.go index 1697cae..4de4af0 100644 --- a/core/plugin_utils.go +++ b/core/plugin_utils.go @@ -351,6 +351,7 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func( Minute: time.Minute, Hour: time.Hour, Day: time.Hour * 24, + Month: 1, }) vm.Set("Regexp", Regexp) vm.Set("Form", func(...interface{}) { diff --git a/mongodb/main.go b/mongodb/main.go index 31ba20e..f50021b 100644 --- a/mongodb/main.go +++ b/mongodb/main.go @@ -107,17 +107,21 @@ func (cl *Collection) Find(filter interface{}, params map[string]interface{}) in } if _, ok := params["count"]; ok { count = true - } else { - if v, ok := params["skip"]; ok { - opt := options.Find() - opt.SetSkip(utils.Int64(v)) - opts = append(opts, opt) - } - if v, ok := params["limit"]; ok { - opt := options.Find() - opt.SetLimit(utils.Int64(v)) - opts = append(opts, opt) - } + } + if v, ok := params["skip"]; ok { + opt := options.Find() + opt.SetSkip(utils.Int64(v)) + opts = append(opts, opt) + } + if v, ok := params["limit"]; ok { + opt := options.Find() + opt.SetLimit(utils.Int64(v)) + opts = append(opts, opt) + } + if v, ok := params["projection"]; ok { + opt := options.Find() + opt.SetProjection(v) + opts = append(opts, opt) } // opts.SetSkip((pageNumber - 1) * pageSize) // opts.SetLimit(pageSize)