x
This commit is contained in:
@@ -2,10 +2,12 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -47,6 +49,36 @@ func initLanguage() {
|
|||||||
if !(item.Os == runtime.GOOS && item.Arch == runtime.GOARCH) {
|
if !(item.Os == runtime.GOOS && item.Arch == runtime.GOARCH) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
node_dir := utils.ExecPath + "/language/" + item.Name
|
||||||
|
os.MkdirAll(node_dir, 0755)
|
||||||
|
path := os.Getenv("PATH")
|
||||||
|
newPath := ""
|
||||||
|
if path != "" {
|
||||||
|
newPath = fmt.Sprintf("%s:%s", node_dir, path)
|
||||||
|
} else {
|
||||||
|
newPath = node_dir
|
||||||
|
}
|
||||||
|
os.Setenv("PATH", newPath)
|
||||||
|
if _, err := os.Stat(node_dir + "/yarn"); err != nil {
|
||||||
|
resp, err := http.Get("https://gitee.com/sillybot/binary/releases/download/yarn/yarn.zip")
|
||||||
|
if err == nil {
|
||||||
|
go func() {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
zipfile := node_dir + "/yarn.zip"
|
||||||
|
f, err := os.OpenFile(zipfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
_, err = io.Copy(f, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Remove(zipfile)
|
||||||
|
unzip(zipfile, 0777, false)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
func() {
|
func() {
|
||||||
dir := utils.ExecPath + "/language/" + item.Name
|
dir := utils.ExecPath + "/language/" + item.Name
|
||||||
data, _ := os.ReadFile(dir + "/version")
|
data, _ := os.ReadFile(dir + "/version")
|
||||||
@@ -54,7 +86,6 @@ func initLanguage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.Log("正在安装", item.Name, "执行环境....")
|
console.Log("正在安装", item.Name, "执行环境....")
|
||||||
os.MkdirAll(utils.ExecPath+"/language/"+item.Name, 0755)
|
|
||||||
resp, err := http.Get(item.Links[0])
|
resp, err := http.Get(item.Links[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -72,7 +103,7 @@ func initLanguage() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer os.Remove(zipfile)
|
defer os.Remove(zipfile)
|
||||||
if err := unzip(zipfile, 0755); err == nil {
|
if err := unzip(zipfile, 0755, false); err == nil {
|
||||||
os.WriteFile(dir+"/version", []byte(item.Version), 0755)
|
os.WriteFile(dir+"/version", []byte(item.Version), 0755)
|
||||||
} else {
|
} else {
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
@@ -80,22 +111,23 @@ func initLanguage() {
|
|||||||
console.Log("安装", item.Name, "执行环境成功")
|
console.Log("安装", item.Name, "执行环境成功")
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
// }()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unzip(filename string, perm fs.FileMode) error {
|
func unzip(filename string, perm fs.FileMode, pkg bool) error {
|
||||||
zipFile, err := zip.OpenReader(filename)
|
zipFile, err := zip.OpenReader(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer zipFile.Close()
|
defer zipFile.Close()
|
||||||
|
top := ""
|
||||||
for _, file := range zipFile.File {
|
for _, file := range zipFile.File {
|
||||||
|
if top == "" {
|
||||||
|
top = strings.Split(file.Name, "/")[0]
|
||||||
|
}
|
||||||
// 忽略以 "__MACOSX/" 开头的文件
|
// 忽略以 "__MACOSX/" 开头的文件
|
||||||
if strings.HasPrefix(file.Name, "__MACOSX/") {
|
if strings.HasPrefix(file.Name, "__MACOSX/") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(filepath.Dir(filename), file.Name)
|
path := filepath.Join(filepath.Dir(filename), file.Name)
|
||||||
if file.FileInfo().IsDir() {
|
if file.FileInfo().IsDir() {
|
||||||
// 如果是目录则创建目录
|
// 如果是目录则创建目录
|
||||||
@@ -109,26 +141,41 @@ func unzip(filename string, perm fs.FileMode) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var de = func() error {
|
||||||
|
// 创建文件并解压缩数据
|
||||||
|
zipFile, err := file.Open()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer zipFile.Close()
|
||||||
|
|
||||||
// 创建文件并解压缩数据
|
localFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||||
zipFile, err := file.Open()
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
|
defer localFile.Close()
|
||||||
|
_, err = io.Copy(localFile, zipFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
defer zipFile.Close()
|
if file.Name != top+"/main.js" {
|
||||||
|
de()
|
||||||
|
} else {
|
||||||
|
if pkg {
|
||||||
|
defer func() { //安装依赖
|
||||||
|
cmd := exec.Command(utils.ExecPath+"/language/node/yarn/bin/yarn", "install")
|
||||||
|
cmd.Dir = utils.ExecPath + "/plugins/" + top
|
||||||
|
console.Log(cmd.Output())
|
||||||
|
de()
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
de()
|
||||||
|
}
|
||||||
|
|
||||||
localFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer localFile.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(localFile, zipFile)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -203,6 +203,8 @@ func AddNodePlugin(path, name string) error {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
uuid := nameUuid(name)
|
||||||
|
plugins.Set(uuid, "")
|
||||||
pluginLock.Lock()
|
pluginLock.Lock()
|
||||||
defer pluginLock.Unlock()
|
defer pluginLock.Unlock()
|
||||||
|
|
||||||
@@ -218,7 +220,7 @@ func AddNodePlugin(path, name string) error {
|
|||||||
if script == "" {
|
if script == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
uuid := nameUuid(name)
|
|
||||||
plugins_id.Store(uuid, path)
|
plugins_id.Store(uuid, path)
|
||||||
// fmt.Println("add,", uuid, name)
|
// fmt.Println("add,", uuid, name)
|
||||||
f, cbs := pluginParse(script, uuid)
|
f, cbs := pluginParse(script, uuid)
|
||||||
|
|||||||
+24
-1
@@ -2,12 +2,15 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/axgle/mahonia"
|
"github.com/axgle/mahonia"
|
||||||
|
"github.com/cdle/sillyplus/utils"
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +23,27 @@ func getJsOs(vm *goja.Runtime, running func() bool) *goja.Object {
|
|||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
})
|
})
|
||||||
|
type ExecRequest struct {
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Command []string `json:"command"`
|
||||||
|
Env []string `json:"env"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
jsos.Set("path", utils.ExecPath)
|
||||||
|
jsos.Set("exec", func(er ExecRequest) string {
|
||||||
|
cmd := exec.Command(er.Command[0], er.Command[1:]...)
|
||||||
|
cmd.Dir = er.Dir
|
||||||
|
cmd.Env = er.Env
|
||||||
|
if er.Path != "" {
|
||||||
|
cmd.Path = er.Path
|
||||||
|
}
|
||||||
|
fmt.Println("==", cmd.Path)
|
||||||
|
data, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
panic(Error(vm, err))
|
||||||
|
}
|
||||||
|
return string(data)
|
||||||
|
})
|
||||||
jsos.Set("readFileSync", func(path string, decode string) string {
|
jsos.Set("readFileSync", func(path string, decode string) string {
|
||||||
// 读取文件内容
|
// 读取文件内容
|
||||||
content, err := ioutil.ReadFile(path)
|
content, err := ioutil.ReadFile(path)
|
||||||
|
|||||||
+1
-1
@@ -168,7 +168,7 @@ func initPlugins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer os.Remove(zipfile)
|
defer os.Remove(zipfile)
|
||||||
if err := unzip(zipfile, 0755); err != nil {
|
if err := unzip(zipfile, 0755, true); err != nil {
|
||||||
return &storage.Final{
|
return &storage.Final{
|
||||||
Error: errors.New("安装异常!" + err.Error()),
|
Error: errors.New("安装异常!" + err.Error()),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func CheckPluginAddress(address string) error {
|
|||||||
|
|
||||||
func initPluginPublish() {
|
func initPluginPublish() {
|
||||||
storage.Watch(sillyGirl, "plugin_sublink", func(old, address, key string) *storage.Final {
|
storage.Watch(sillyGirl, "plugin_sublink", func(old, address, key string) *storage.Final {
|
||||||
if strings.HasPrefix(address, "sub://") {
|
if strings.HasPrefix(address, "link://") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := CheckPluginAddress(address); err != nil {
|
if err := CheckPluginAddress(address); err != nil {
|
||||||
|
|||||||
+8
-2
@@ -75,8 +75,8 @@ func initWeb() {
|
|||||||
uuid := c.Query("uuid")
|
uuid := c.Query("uuid")
|
||||||
for _, f := range Functions {
|
for _, f := range Functions {
|
||||||
if f.UUID == uuid && f.Public {
|
if f.UUID == uuid && f.Public {
|
||||||
|
plugin_downloads.Set(f.UUID, plugin_downloads.GetInt(f.UUID)+1)
|
||||||
if f.Type == "goja" {
|
if f.Type == "goja" {
|
||||||
plugin_downloads.Set(f.UUID, plugin_downloads.GetInt(f.UUID)+1)
|
|
||||||
c.String(200, publicScript(plugins.GetString(f.UUID)))
|
c.String(200, publicScript(plugins.GetString(f.UUID)))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -97,13 +97,19 @@ func initWeb() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if info.IsDir() && info.Name() == "node_modules" {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// 将路径转换为相对路径
|
|
||||||
|
|
||||||
|
// 将路径转换为相对路径
|
||||||
relPath, err := filepath.Rel(dir, path)
|
relPath, err := filepath.Rel(dir, path)
|
||||||
is_index := relPath == "main.js"
|
is_index := relPath == "main.js"
|
||||||
|
|
||||||
relPath = name + "/" + relPath
|
relPath = name + "/" + relPath
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1 +1,9 @@
|
|||||||
///
|
/**
|
||||||
|
* @title .
|
||||||
|
* @create_at 2023-07-26 11:07:19
|
||||||
|
* @description 🐒这个人很懒什么都没有留下
|
||||||
|
* @author 佚名
|
||||||
|
* @version v1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { sender: s, Bucket, Adapter, sleep } = require("sillygirl");
|
||||||
+4
-1
@@ -25,4 +25,7 @@ cp /Users/a1-6/Code/sillyplus/proto3/dist/sillygirl.js /Users/a1-6/Code/node/nod
|
|||||||
|
|
||||||
#压缩
|
#压缩
|
||||||
cd /Users/a1-6/Code/nodes/node_darwin_arm64 && zip node_darwin_arm64.zip node
|
cd /Users/a1-6/Code/nodes/node_darwin_arm64 && zip node_darwin_arm64.zip node
|
||||||
cd /Users/a1-6/Code/nodes/node_linux_amd64 && zip node_linux_amd64.zip node
|
cd /Users/a1-6/Code/nodes/node_linux_amd64 && zip node_linux_amd64.zip node
|
||||||
|
|
||||||
|
##
|
||||||
|
git add . && git commit -m "x" && git push
|
||||||
Reference in New Issue
Block a user