x
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ type Language struct {
|
||||
Links []string // 下载链接
|
||||
}
|
||||
|
||||
var plugin_dir = utils.ExecPath + "/plugins"
|
||||
var plugin_dir = filepath.Join(utils.ExecPath, "plugins")
|
||||
var release = "20230732"
|
||||
|
||||
var languages = []Language{
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/cdle/sillyplus/utils"
|
||||
)
|
||||
|
||||
var DataHome = utils.GetDataHome()
|
||||
var version = compiled_at
|
||||
|
||||
func GetVersion() (string, error) {
|
||||
@@ -46,10 +45,6 @@ func Init() {
|
||||
}()
|
||||
initLoc()
|
||||
sillyGirl = MakeBucket("sillyGirl")
|
||||
_, err := os.Stat(DataHome)
|
||||
if err != nil {
|
||||
os.MkdirAll(DataHome, os.ModePerm)
|
||||
}
|
||||
// utils.ReadYaml(utils.ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyplus/main/conf/demo_config.yaml")
|
||||
initToHandleMessage()
|
||||
sillyGirl.Set("compiled_at", compiled_at)
|
||||
|
||||
+23
-1
@@ -3,6 +3,7 @@ package core
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -10,7 +11,28 @@ import (
|
||||
)
|
||||
|
||||
var temp *PersistentKeyValueStore
|
||||
var tempPath = utils.GetDataHome() + "temp.json"
|
||||
var tempPath = filepath.Join(utils.GetDataHome(), "cache.json")
|
||||
|
||||
var cache = func(pre string, sec int) interface{} {
|
||||
return map[string]interface{}{
|
||||
"set": func(key string, value interface{}, num int) {
|
||||
if sec != 0 && num == 0 {
|
||||
num = sec
|
||||
}
|
||||
temp.Set(pre+"_"+key, value, num)
|
||||
},
|
||||
"get": func(key string, def interface{}) interface{} {
|
||||
v := temp.Get(pre + "_" + key)
|
||||
if v == nil {
|
||||
v = def
|
||||
}
|
||||
return v
|
||||
},
|
||||
"delete": func(key string) {
|
||||
temp.Delete(pre + "_" + key)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type PersistentKeyValueStore struct {
|
||||
sync.RWMutex
|
||||
|
||||
+6
-7
@@ -2,7 +2,6 @@ package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -372,12 +371,12 @@ func initPlugins() {
|
||||
if !apd {
|
||||
AddCommand([]*common.Function{f})
|
||||
}
|
||||
if f.UUID != "" && f.Public {
|
||||
go func() {
|
||||
os.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666)
|
||||
os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
|
||||
}()
|
||||
}
|
||||
// if f.UUID != "" && f.Public {
|
||||
// go func() {
|
||||
// os.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666)
|
||||
// os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
|
||||
// }()
|
||||
// }
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
+9
-10
@@ -3,7 +3,6 @@ package core
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -15,8 +14,8 @@ import (
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
var plugin_path = "/etc/sillyplus/public/"
|
||||
var plugin_download_file = plugin_path + "download"
|
||||
// var plugin_path = "/etc/sillyplus/public/"
|
||||
// var plugin_download_file = plugin_path + "download"
|
||||
|
||||
func CheckPluginAddress(address string) error {
|
||||
if !strings.HasSuffix(address, "list.json") {
|
||||
@@ -56,13 +55,13 @@ func initPluginPublish() {
|
||||
}
|
||||
})
|
||||
|
||||
os.MkdirAll(plugin_download_file, 0666)
|
||||
os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
|
||||
for _, f := range Functions {
|
||||
if f.UUID != "" && f.Public {
|
||||
os.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666)
|
||||
}
|
||||
}
|
||||
// os.MkdirAll(plugin_download_file, 0666)
|
||||
// os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
|
||||
// for _, f := range Functions {
|
||||
// if f.UUID != "" && f.Public {
|
||||
// os.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
func publicScript(str string) string {
|
||||
|
||||
+3
-20
@@ -317,26 +317,9 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
|
||||
}
|
||||
return Script(str)
|
||||
})
|
||||
vm.Set("Temp", func(pre string, sec int) interface{} {
|
||||
return map[string]interface{}{
|
||||
"set": func(key string, value interface{}, num int) {
|
||||
if sec != 0 && num == 0 {
|
||||
num = sec
|
||||
}
|
||||
temp.Set(pre+"_"+key, value, num)
|
||||
},
|
||||
"get": func(key string, def interface{}) interface{} {
|
||||
v := temp.Get(pre + "_" + key)
|
||||
if v == nil {
|
||||
v = def
|
||||
}
|
||||
return v
|
||||
},
|
||||
"delete": func(key string) {
|
||||
temp.Delete(pre + "_" + key)
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
vm.Set("Cache", cache)
|
||||
vm.Set("Temp", cache)
|
||||
|
||||
osjs := getJsOs(vm, running)
|
||||
vm.Set("os", osjs)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@@ -55,7 +56,9 @@ func Get(key string) string {
|
||||
var Buckets = []Bucket{}
|
||||
|
||||
func Initsillyplus() storage.Bucket {
|
||||
bd := utils.GetDataHome() + "sillyGirl.db"
|
||||
|
||||
bd := filepath.Join(utils.GetDataHome(), "sillyGirl.db")
|
||||
|
||||
_, err := os.Stat(bd)
|
||||
if err != nil {
|
||||
f, err := os.Create(bd)
|
||||
|
||||
Reference in New Issue
Block a user