x
This commit is contained in:
@@ -136,12 +136,12 @@ func init() {
|
|||||||
if ar[0] == "plugins" && false { //todo
|
if ar[0] == "plugins" && false { //todo
|
||||||
data[bk] = halfDeEct(MakeBucket(ar[0]).GetString(ar[1]))
|
data[bk] = halfDeEct(MakeBucket(ar[0]).GetString(ar[1]))
|
||||||
} else {
|
} else {
|
||||||
data[bk] = MakeBucket(ar[0]).GetString(ar[1])
|
data[bk] = TransformBucketKeyValue(MakeBucket(ar[0]).GetString(ar[1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(ar) == 1 {
|
if len(ar) == 1 {
|
||||||
MakeBucket(ar[0]).Foreach(func(b1, b2 []byte) error {
|
MakeBucket(ar[0]).Foreach(func(b1, b2 []byte) error {
|
||||||
data[bk+"."+string(b1)] = string(b2)
|
data[bk+"."+string(b1)] = TransformBucketKeyValue(string(b2))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ func init() {
|
|||||||
for bk, v := range updates {
|
for bk, v := range updates {
|
||||||
ar := strings.Split(bk, ".")
|
ar := strings.Split(bk, ".")
|
||||||
if len(ar) == 2 {
|
if len(ar) == 2 {
|
||||||
msg, err := MakeBucket(ar[0]).Set(ar[1], v)
|
msg, err := SetBucketKeyValue(MakeBucket(ar[0]), ar[1], v)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
messages[bk] = msg
|
messages[bk] = msg
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/dop251/goja"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getJsOs(vm *goja.Runtime, running func() bool) *goja.Object {
|
||||||
|
var jsos = vm.NewObject()
|
||||||
|
jsos.Set("readFile", func(name string) []byte {
|
||||||
|
data, err := os.ReadFile(name)
|
||||||
|
if err != nil {
|
||||||
|
panic(Error(vm, err))
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
})
|
||||||
|
jsos.Set("walkFilePath", func(root string, callback func(path string, info os.FileInfo) bool) {
|
||||||
|
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if !running() {
|
||||||
|
return errors.New("over")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
panic(Error(vm, err))
|
||||||
|
}
|
||||||
|
if callback(path, info) {
|
||||||
|
return errors.New("over")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil && err.Error() != "over" {
|
||||||
|
panic(Error(vm, err))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
jsos.Set("userHomeDir", func() string {
|
||||||
|
dir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
panic(Error(vm, err))
|
||||||
|
}
|
||||||
|
return dir
|
||||||
|
})
|
||||||
|
return jsos
|
||||||
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -50,3 +54,39 @@ func FindFile(c *gin.Context) {
|
|||||||
// 如果文件不存在,返回404错误
|
// 如果文件不存在,返回404错误
|
||||||
c.AbortWithStatus(http.StatusNotFound)
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server.GET("/api/file/:filename", FindFile)
|
||||||
|
// Server.GET("/api/decode/:random", Base642Binary)
|
||||||
|
|
||||||
|
func Base642Binary(c *gin.Context) {
|
||||||
|
random := c.Param("random")
|
||||||
|
s, ok := temp.Get("base64_" + random).(string)
|
||||||
|
if !ok {
|
||||||
|
c.String(http.StatusBadRequest, "Invalid input")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
input := strings.TrimPrefix(s, "base64://")
|
||||||
|
data, err := base64.StdEncoding.DecodeString(input)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusBadRequest, "Invalid input")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 解析图片格式
|
||||||
|
_, format, err := image.DecodeConfig(strings.NewReader(string(data)))
|
||||||
|
fmt.Println(format, err)
|
||||||
|
if err != nil {
|
||||||
|
c.Header("Content-Type", "application/octet-stream")
|
||||||
|
} else {
|
||||||
|
// 根据图片格式设置响应头
|
||||||
|
switch format {
|
||||||
|
case "jpeg":
|
||||||
|
c.Header("Content-Type", "image/jpeg")
|
||||||
|
case "png":
|
||||||
|
c.Header("Content-Type", "image/png")
|
||||||
|
default:
|
||||||
|
c.Header("Content-Type", "application/octet-stream")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Data(http.StatusOK, "application/octet-stream", data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ package core
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/cdle/sillyplus/emoji"
|
"github.com/cdle/sillyplus/emoji"
|
||||||
"github.com/cdle/sillyplus/utils"
|
"github.com/cdle/sillyplus/utils"
|
||||||
@@ -15,9 +18,33 @@ import (
|
|||||||
type Strings struct {
|
type Strings struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sender *Strings) Random(length int, substr string) string {
|
||||||
|
ws := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
if substr != "" {
|
||||||
|
ws = substr
|
||||||
|
}
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
letters := []rune(ws)
|
||||||
|
b := make([]rune, length)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = letters[rand.Intn(len(letters))]
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sender *Strings) JoinFilepath(elem ...string) string {
|
||||||
|
return filepath.Join(elem...)
|
||||||
|
}
|
||||||
|
|
||||||
func (sender *Strings) Contains(s, substr string) bool {
|
func (sender *Strings) Contains(s, substr string) bool {
|
||||||
return strings.Contains(s, substr)
|
return strings.Contains(s, substr)
|
||||||
}
|
}
|
||||||
|
func (sender *Strings) HasPrefix(s, substr string) bool {
|
||||||
|
return strings.HasPrefix(s, substr)
|
||||||
|
}
|
||||||
|
func (sender *Strings) HasSuffix(s, substr string) bool {
|
||||||
|
return strings.HasSuffix(s, substr)
|
||||||
|
}
|
||||||
|
|
||||||
func (sender *Strings) Replace(s string, old string, new string, n int) string {
|
func (sender *Strings) Replace(s string, old string, new string, n int) string {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
|||||||
+1
-1
@@ -459,7 +459,7 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
|
|||||||
}
|
}
|
||||||
loop := eventloop.NewEventLoop()
|
loop := eventloop.NewEventLoop()
|
||||||
loop.Run(func(vm *goja.Runtime) {
|
loop.Run(func(vm *goja.Runtime) {
|
||||||
SetPluginMethod(vm, uuid, onStart)
|
SetPluginMethod(vm, uuid, onStart, running)
|
||||||
ss := &SenderJsIplm{
|
ss := &SenderJsIplm{
|
||||||
Message: s,
|
Message: s,
|
||||||
Vm: vm,
|
Vm: vm,
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func CancelPluginCrons(uuid string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool) {
|
func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func() bool) {
|
||||||
vm.Set("Bucket", func(name string) interface{} {
|
vm.Set("Bucket", func(name string) interface{} {
|
||||||
return vm.NewProxy(MakeBucketObject(vm, uuid, on_start, MakeBucket(name)), &goja.ProxyTrapConfig{
|
return vm.NewProxy(MakeBucketObject(vm, uuid, on_start, MakeBucket(name)), &goja.ProxyTrapConfig{
|
||||||
Get: func(target *goja.Object, property string, receiver goja.Value) (value goja.Value) {
|
Get: func(target *goja.Object, property string, receiver goja.Value) (value goja.Value) {
|
||||||
@@ -433,6 +433,9 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
osjs := getJsOs(vm, running)
|
||||||
|
vm.Set("os", osjs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncryptPlugin(script string) string {
|
func EncryptPlugin(script string) string {
|
||||||
|
|||||||
+4
-1
@@ -49,6 +49,7 @@ func init() {
|
|||||||
Server.Use(Cors())
|
Server.Use(Cors())
|
||||||
Server.Use(gzip.Gzip(gzip.DefaultCompression))
|
Server.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||||
Server.GET("/api/file/:filename", FindFile)
|
Server.GET("/api/file/:filename", FindFile)
|
||||||
|
Server.GET("/api/decode/:random", Base642Binary)
|
||||||
Server.NoRoute(func(c *gin.Context) {
|
Server.NoRoute(func(c *gin.Context) {
|
||||||
if c.Request.URL.Path != "/api/web_chat" {
|
if c.Request.URL.Path != "/api/web_chat" {
|
||||||
logs.Debug(c.Request.URL.Path)
|
logs.Debug(c.Request.URL.Path)
|
||||||
@@ -317,7 +318,9 @@ func init() {
|
|||||||
// logs.Info("Http服务(%s)开始运行", port)
|
// logs.Info("Http服务(%s)开始运行", port)
|
||||||
logs.Info("管理员面板:")
|
logs.Info("管理员面板:")
|
||||||
logs.Info(" > 本机: http://localhost:%s", port)
|
logs.Info(" > 本机: http://localhost:%s", port)
|
||||||
logs.Info(" > 局域网: http://%s:%s", getLocalIP(), port)
|
local_ip := getLocalIP()
|
||||||
|
sillyGirl.Set("local_ip", local_ip)
|
||||||
|
logs.Info(" > 局域网: http://%s:%s", local_ip, port)
|
||||||
if err := srvs[0].ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
if err := srvs[0].ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
logs.Error("Http服务运行失败:%s", err.Error())
|
logs.Error("Http服务运行失败:%s", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user