This commit is contained in:
cdle
2023-06-10 12:33:14 +08:00
parent 10d5400f2f
commit a557523a11
11 changed files with 364 additions and 52 deletions
+3 -1
View File
@@ -31,7 +31,7 @@ func FindFile(c *gin.Context) {
statics.Range(func(_, value any) bool {
path := value.(string)
// 拼接文件路径
filepath := filepath.Join(path, filename)
filepath := strings.ReplaceAll(filepath.Join(path, filename), "\\/", "\\")
// 判断文件是否存在
_, err := os.Stat(filepath)
if err == nil {
@@ -48,6 +48,8 @@ func FindFile(c *gin.Context) {
// 返回文件内容
c.Data(http.StatusOK, contentType, file)
return false
} else {
console.Log(err)
}
return true
})
+27
View File
@@ -36,6 +36,33 @@ func (sender *Strings) JoinFilepath(elem ...string) string {
return filepath.Join(elem...)
}
func (sender *Strings) Trim(s, cutset string) string {
return strings.Trim(s, cutset)
}
func (sender *Strings) TrimLeft(s, cutset string) string {
return strings.TrimLeft(s, cutset)
}
func (sender *Strings) TrimRight(s, cutset string) string {
return strings.TrimRight(s, cutset)
}
func (sender *Strings) Filename(path string) string {
re := regexp.MustCompile(`[\\/]+`)
parts := re.Split(path, -1)
filename := parts[len(parts)-1]
return filename
}
func (sender *Strings) Dir(path string) string {
re := regexp.MustCompile(`[\\/]+`)
parts := re.Split(path, -1)
filename := parts[len(parts)-1]
dir := path[:len(path)-len(filename)]
dir = filepath.Clean(dir)
return dir
}
func (sender *Strings) Contains(s, substr string) bool {
return strings.Contains(s, substr)
}
+6 -2
View File
@@ -259,6 +259,7 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
var origin = "自定义"
var http *common.Http
var message *common.Reply
var FindAll bool
ress := regexp.MustCompile(
`\*\s?@([\d\w+-]+)\s+([^\n]+?)\n`,
).FindAllStringSubmatch(data, -1)
@@ -366,6 +367,8 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
admin = strings.TrimSpace(res[2]) == "true"
case "disable":
disable = strings.TrimSpace(res[2]) == "true"
case "findall":
FindAll = strings.TrimSpace(res[2]) == "true"
case "priority":
priority = utils.Int(strings.TrimSpace(res[2]))
case "title", "name", "show":
@@ -549,6 +552,7 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
Running: onStart,
Reply: message,
Http: http,
FindAll: FindAll,
}
running = func() bool {
return f.Running
@@ -562,13 +566,13 @@ func ChatID(p interface{}) string {
if p == 0 {
return ""
} else {
return fmt.Sprint(p)
return utils.Itoa(p)
}
case string:
return p
case nil:
return ""
default:
return fmt.Sprint(p)
return utils.Itoa(p)
}
}
+17
View File
@@ -235,6 +235,23 @@ func (sender *SenderJsIplm) Param(i interface{}) string {
return ""
}
func (sender *SenderJsIplm) GetAllMatch() [][]string {
return sender.Message.GetAllMatch()
}
func (sender *SenderJsIplm) Params(i int) []string {
if i == 0 {
i = 1
}
ss := []string{}
for _, v := range sender.Message.GetAllMatch() {
ss = append(ss, v[i-1])
}
return ss
}
// GetAllMatch
func (Sender *SenderJsIplm) Get(i interface{}) string {
return Sender.Param(i)
}
+19 -19
View File
@@ -248,25 +248,6 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
return o
})
vm.Set("Express", func() *goja.Object {
o := vm.NewObject()
methods := []string{"get", "post", "delete", "put", "fetch"}
for i := range methods {
method := methods[i]
o.Set(method, func(path string, handles ...func(*Request, *Response)) {
webs = append(webs, Web{
uuid: uuid,
method: strings.ToUpper(method),
path: path,
handles: handles,
})
})
}
o.Set("static", func(path string) {
addStatic(uuid, path)
})
return o
})
// registry.RegisterNativeModule("express", func(runtime *goja.Runtime, module *goja.Object) {
// o := module.Get("exports").(*goja.Object)
// methods := []string{"get", "post", "delete", "put", "fetch"}
@@ -331,6 +312,25 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
// }()
// }
}
vm.Set("Express", func() *goja.Object {
o := vm.NewObject()
methods := []string{"get", "post", "delete", "put", "fetch"}
for i := range methods {
method := methods[i]
o.Set(method, func(path string, handles ...func(*Request, *Response)) {
webs = append(webs, Web{
uuid: uuid,
method: strings.ToUpper(method),
path: path,
handles: handles,
})
})
}
o.Set("static", func(path string) {
addStatic(uuid, path)
})
return o
})
registry.Enable(vm)
vm.SetFieldNameMapper(myFieldNameMapper{})
// vm.Set("sleep", sleep)