This commit is contained in:
1-6
2023-08-09 10:52:34 +08:00
parent 70bad0cc52
commit 2b19690add
12 changed files with 67 additions and 109 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ WORKDIR /usr/local/sillyGirl
ENV SILLYGIRL_DATA_PATH=/usr/local/sillyGirl/
# 指定容器启动时要运行的命令 # 指定容器启动时要运行的命令
CMD ["/usr/local/sillyGirl/sillyGirl"] CMD ["/usr/local/sillyGirl/sillyGirl"]
+1
View File
@@ -19,6 +19,7 @@ cable
sillyplus.cache sillyplus.cache
main main
sillyplus.pid sillyplus.pid
sillyGirl.pid
gitee gitee
develop/wx develop/wx
develop/qinglong develop/qinglong
+1 -1
View File
@@ -23,7 +23,7 @@ type Language struct {
Links []string // 下载链接 Links []string // 下载链接
} }
var plugin_dir = utils.ExecPath + "/plugins" var plugin_dir = filepath.Join(utils.ExecPath, "plugins")
var release = "20230732" var release = "20230732"
var languages = []Language{ var languages = []Language{
-5
View File
@@ -18,7 +18,6 @@ import (
"github.com/cdle/sillyplus/utils" "github.com/cdle/sillyplus/utils"
) )
var DataHome = utils.GetDataHome()
var version = compiled_at var version = compiled_at
func GetVersion() (string, error) { func GetVersion() (string, error) {
@@ -46,10 +45,6 @@ func Init() {
}() }()
initLoc() initLoc()
sillyGirl = MakeBucket("sillyGirl") 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") // utils.ReadYaml(utils.ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyplus/main/conf/demo_config.yaml")
initToHandleMessage() initToHandleMessage()
sillyGirl.Set("compiled_at", compiled_at) sillyGirl.Set("compiled_at", compiled_at)
+23 -1
View File
@@ -3,6 +3,7 @@ package core
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"path/filepath"
"sync" "sync"
"time" "time"
@@ -10,7 +11,28 @@ import (
) )
var temp *PersistentKeyValueStore 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 { type PersistentKeyValueStore struct {
sync.RWMutex sync.RWMutex
+6 -7
View File
@@ -2,7 +2,6 @@ package core
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
@@ -372,12 +371,12 @@ func initPlugins() {
if !apd { if !apd {
AddCommand([]*common.Function{f}) AddCommand([]*common.Function{f})
} }
if f.UUID != "" && f.Public { // if f.UUID != "" && f.Public {
go func() { // go func() {
os.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666) // 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) // os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
}() // }()
} // }
return return
}) })
} }
+9 -10
View File
@@ -3,7 +3,6 @@ package core
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@@ -15,8 +14,8 @@ import (
"github.com/goccy/go-json" "github.com/goccy/go-json"
) )
var plugin_path = "/etc/sillyplus/public/" // var plugin_path = "/etc/sillyplus/public/"
var plugin_download_file = plugin_path + "download" // var plugin_download_file = plugin_path + "download"
func CheckPluginAddress(address string) error { func CheckPluginAddress(address string) error {
if !strings.HasSuffix(address, "list.json") { if !strings.HasSuffix(address, "list.json") {
@@ -56,13 +55,13 @@ func initPluginPublish() {
} }
}) })
os.MkdirAll(plugin_download_file, 0666) // os.MkdirAll(plugin_download_file, 0666)
os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666) // os.WriteFile(plugin_path+"list.json", utils.JsonMarshal(GetPublicResponse()), 0666)
for _, f := range Functions { // for _, f := range Functions {
if f.UUID != "" && f.Public { // 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.WriteFile(fmt.Sprintf("%s/%s.js", plugin_download_file, f.UUID), []byte(publicScript(plugins.GetString(f.UUID))), 0666)
} // }
} // }
} }
func publicScript(str string) string { func publicScript(str string) string {
+3 -20
View File
@@ -317,26 +317,9 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
} }
return Script(str) return Script(str)
}) })
vm.Set("Temp", func(pre string, sec int) interface{} {
return map[string]interface{}{ vm.Set("Cache", cache)
"set": func(key string, value interface{}, num int) { vm.Set("Temp", cache)
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)
},
}
})
osjs := getJsOs(vm, running) osjs := getJsOs(vm, running)
vm.Set("os", osjs) vm.Set("os", osjs)
+4 -1
View File
@@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path/filepath"
"reflect" "reflect"
"time" "time"
@@ -55,7 +56,9 @@ func Get(key string) string {
var Buckets = []Bucket{} var Buckets = []Bucket{}
func Initsillyplus() storage.Bucket { func Initsillyplus() storage.Bucket {
bd := utils.GetDataHome() + "sillyGirl.db"
bd := filepath.Join(utils.GetDataHome(), "sillyGirl.db")
_, err := os.Stat(bd) _, err := os.Stat(bd)
if err != nil { if err != nil {
f, err := os.Create(bd) f, err := os.Create(bd)
-5
View File
@@ -1,5 +0,0 @@
{
"dependencies": {
"node-fetch": "^3.3.2"
}
}
+16 -13
View File
@@ -8,6 +8,8 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"sync"
"net" "net"
"net/http" "net/http"
"os" "os"
@@ -88,24 +90,25 @@ func init() {
} }
} }
var once = new(sync.Once)
var GetDataHome = func() string { var GetDataHome = func() string {
home := os.Getenv("SILLYGIRL_DATA_PATH")
if home == "" {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
if _, err := os.Stat(`C:\ProgramData\sillyplus\`); err != nil { home = `C:\ProgramData\sillyplus\`
os.MkdirAll(`C:\ProgramData\sillyplus\`, os.ModePerm)
}
return `C:\ProgramData\sillyplus\`
} else if runtime.GOOS == "darwin" { } else if runtime.GOOS == "darwin" {
i := ExecPath + "/.sillyplus/" home = ExecPath + "/.sillyplus/"
if _, err := os.Stat(i); err != nil {
os.MkdirAll(i, os.ModePerm)
}
return i
} else { } else {
if _, err := os.Stat(`/etc/sillyplus/`); err != nil { home = `/etc/sillyplus/`
os.MkdirAll(`/etc/sillyplus/`, os.ModePerm)
} }
return `/etc/sillyplus/`
} }
once.Do(func() {
if err := os.MkdirAll(home, os.ModePerm); err != nil {
fmt.Println(err)
}
})
return home
} }
func KillProcess(pid int) error { func KillProcess(pid int) error {
@@ -153,7 +156,7 @@ var getProcessName = func() string {
} }
var GetPidFile = func() string { var GetPidFile = func() string {
return GetDataHome() + "sillyplus.pid" return filepath.Join(GetDataHome(), "sillyGirl.pid")
} }
func GetPidFromFile(pidFile string) (int, error) { func GetPidFromFile(pidFile string) (int, error) {
-42
View File
@@ -1,42 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
data-uri-to-buffer@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==
fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.2.0"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9"
integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==
dependencies:
node-domexception "^1.0.0"
web-streams-polyfill "^3.0.3"
formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"
node-domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
node-fetch@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b"
integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"
web-streams-polyfill@^3.0.3:
version "3.2.1"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6"
integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==