diff --git a/.dockerfile b/.dockerfile index 7d10057..dcff632 100644 --- a/.dockerfile +++ b/.dockerfile @@ -73,7 +73,7 @@ WORKDIR /usr/local/sillyGirl - +ENV SILLYGIRL_DATA_PATH=/usr/local/sillyGirl/ # 指定容器启动时要运行的命令 CMD ["/usr/local/sillyGirl/sillyGirl"] \ No newline at end of file diff --git a/.gitignore b/.gitignore index 860621e..ed9f146 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ cable sillyplus.cache main sillyplus.pid +sillyGirl.pid gitee develop/wx develop/qinglong diff --git a/core/grpc_asset.go b/core/grpc_asset.go index 3d7f36c..11cd03b 100644 --- a/core/grpc_asset.go +++ b/core/grpc_asset.go @@ -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{ diff --git a/core/init.go b/core/init.go index 6a3ef62..4694776 100644 --- a/core/init.go +++ b/core/init.go @@ -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) diff --git a/core/node_temp.go b/core/node_temp.go index 0247749..0ff96d1 100644 --- a/core/node_temp.go +++ b/core/node_temp.go @@ -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 diff --git a/core/plugin_core.go b/core/plugin_core.go index a039830..671f02d 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -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 }) } diff --git a/core/plugin_publish.go b/core/plugin_publish.go index 2eee1fa..d781178 100644 --- a/core/plugin_publish.go +++ b/core/plugin_publish.go @@ -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 { diff --git a/core/plugin_utils.go b/core/plugin_utils.go index d687996..ac52734 100644 --- a/core/plugin_utils.go +++ b/core/plugin_utils.go @@ -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) diff --git a/core/storage/boltdb/init.go b/core/storage/boltdb/init.go index 006c266..644967b 100644 --- a/core/storage/boltdb/init.go +++ b/core/storage/boltdb/init.go @@ -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) diff --git a/package.json b/package.json deleted file mode 100644 index 1797372..0000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "node-fetch": "^3.3.2" - } -} diff --git a/utils/init.go b/utils/init.go index 6f55b80..256db49 100644 --- a/utils/init.go +++ b/utils/init.go @@ -8,6 +8,8 @@ import ( "fmt" "io" "io/ioutil" + "sync" + "net" "net/http" "os" @@ -88,24 +90,25 @@ func init() { } } +var once = new(sync.Once) + var GetDataHome = func() string { - if runtime.GOOS == "windows" { - if _, err := os.Stat(`C:\ProgramData\sillyplus\`); err != nil { - os.MkdirAll(`C:\ProgramData\sillyplus\`, os.ModePerm) + home := os.Getenv("SILLYGIRL_DATA_PATH") + if home == "" { + if runtime.GOOS == "windows" { + home = `C:\ProgramData\sillyplus\` + } else if runtime.GOOS == "darwin" { + home = ExecPath + "/.sillyplus/" + } else { + home = `/etc/sillyplus/` } - return `C:\ProgramData\sillyplus\` - } else if runtime.GOOS == "darwin" { - i := ExecPath + "/.sillyplus/" - if _, err := os.Stat(i); err != nil { - os.MkdirAll(i, os.ModePerm) - } - return i - } else { - if _, err := os.Stat(`/etc/sillyplus/`); err != nil { - 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 { @@ -153,7 +156,7 @@ var getProcessName = func() string { } var GetPidFile = func() string { - return GetDataHome() + "sillyplus.pid" + return filepath.Join(GetDataHome(), "sillyGirl.pid") } func GetPidFromFile(pidFile string) (int, error) { diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index eb66a12..0000000 --- a/yarn.lock +++ /dev/null @@ -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==