x
This commit is contained in:
@@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="/admin/umi.4cb92728.js"></script>
|
||||
<script src="/admin/umi.f36f16c6.js"></script>
|
||||
|
||||
</body></html>
|
||||
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+11
-5
@@ -17,12 +17,18 @@ import (
|
||||
|
||||
func checkFilePlugin(key string, value *string) {
|
||||
if isNameUuid(key) {
|
||||
if v, ok := plugins_id.Load(key); ok {
|
||||
data, _ := os.ReadFile(v.(string))
|
||||
*value = string(data)
|
||||
} else {
|
||||
*value = "非法操作,请勿乱动。"
|
||||
for _, f := range Functions {
|
||||
if f.UUID == key {
|
||||
data, _ := os.ReadFile(f.Path)
|
||||
*value = string(data)
|
||||
return
|
||||
}
|
||||
}
|
||||
// if v, ok := plugins_id.Load(key); ok {
|
||||
|
||||
// } else {
|
||||
*value = "非法操作,请勿乱动。"
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ type Function struct {
|
||||
Messages interface{} `json:"messages"`
|
||||
Classes []string `json:"classes"`
|
||||
Debug bool `json:"debug"`
|
||||
Path string `json:"-"`
|
||||
}
|
||||
type Filter struct {
|
||||
BlackMode bool
|
||||
|
||||
+14
-1
@@ -41,6 +41,12 @@ var languages = []Language{
|
||||
Arch: "arm64",
|
||||
Links: []string{"https://gitee.com/sillybot/binary/releases/download/" + release + "/node_darwin_arm64.zip"},
|
||||
},
|
||||
{
|
||||
Name: "node",
|
||||
Version: release,
|
||||
Os: "windows",
|
||||
Arch: "amd64",
|
||||
},
|
||||
}
|
||||
|
||||
func initLanguage() {
|
||||
@@ -59,7 +65,11 @@ func initLanguage() {
|
||||
newPath = node_dir
|
||||
}
|
||||
os.Setenv("PATH", newPath)
|
||||
if len(item.Links) == 0 {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(node_dir + "/yarn"); err != nil {
|
||||
fmt.Println(err, 1)
|
||||
resp, err := http.Get("https://gitee.com/sillybot/binary/releases/download/yarn/yarn.zip")
|
||||
if err == nil {
|
||||
go func() {
|
||||
@@ -67,15 +77,18 @@ func initLanguage() {
|
||||
zipfile := node_dir + "/yarn.zip"
|
||||
f, err := os.OpenFile(zipfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
|
||||
if err != nil {
|
||||
fmt.Println(err, 2)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = io.Copy(f, resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err, 3)
|
||||
return
|
||||
}
|
||||
defer os.Remove(zipfile)
|
||||
unzip(zipfile, 0777, false)
|
||||
err = unzip(zipfile, 0777, false)
|
||||
fmt.Println(err, 4)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func RemNodePlugin(name string) error {
|
||||
pluginLock.Lock()
|
||||
defer pluginLock.Unlock()
|
||||
key := nameUuid(name)
|
||||
plugins_id.Delete(key)
|
||||
// plugins_id.Delete(key)
|
||||
// fmt.Println("rem", key, name)
|
||||
for i := range Functions {
|
||||
if Functions[i].UUID == key {
|
||||
@@ -223,7 +223,7 @@ func isNameUuid(uuid string) bool {
|
||||
return strings.Contains(uuid, "_")
|
||||
}
|
||||
|
||||
var plugins_id sync.Map
|
||||
// var plugins_id sync.Map
|
||||
|
||||
func AddNodePlugin(path, name string) error {
|
||||
if name == "" {
|
||||
@@ -246,12 +246,12 @@ func AddNodePlugin(path, name string) error {
|
||||
if script == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
plugins_id.Store(uuid, path)
|
||||
// plugins_id.Store(uuid, path)
|
||||
// fmt.Println("add,", uuid, name)
|
||||
f, cbs := pluginParse(script, uuid)
|
||||
f.Suffix = ".js"
|
||||
f.Type = "typescript"
|
||||
f.Type = "node"
|
||||
f.Path = path
|
||||
f.Handle = func(s common.Sender, f func(vm *goja.Runtime)) interface{} {
|
||||
s.SetPluginID(uuid)
|
||||
plt := s.GetImType()
|
||||
|
||||
+33
-16
@@ -111,8 +111,13 @@ func initPlugins() {
|
||||
storage.Watch(plugins, nil, func(old, new, key string) (fin *storage.Final) {
|
||||
pluginLock.Lock()
|
||||
defer pluginLock.Unlock()
|
||||
// fmt.Println("new", new, key)
|
||||
|
||||
// fmt.Println(old, new, key, "===")
|
||||
if new == "uninstall" {
|
||||
new = ""
|
||||
fin = &storage.Final{
|
||||
Now: storage.EMPTY,
|
||||
}
|
||||
}
|
||||
if isNameUuid(key) {
|
||||
if new == "install" {
|
||||
for _, p := range plugin_list {
|
||||
@@ -162,25 +167,38 @@ func initPlugins() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if vv, ok := plugins_id.Load(key); ok {
|
||||
filename := vv.(string)
|
||||
if new == "" {
|
||||
os.RemoveAll(filepath.Dir(filename))
|
||||
} else {
|
||||
err := os.WriteFile(filename, []byte(new), 0755)
|
||||
if err != nil {
|
||||
return &storage.Final{
|
||||
Error: err,
|
||||
// if vv, ok := plugins_id.Load(key); ok {
|
||||
for _, f := range Functions {
|
||||
if f.UUID == key {
|
||||
filename := f.Path
|
||||
if new == "" {
|
||||
ss := strings.Split(filename, "/")
|
||||
os.RemoveAll(filepath.Dir(filename))
|
||||
// fmt.Println(strings.Join(ss, " "))
|
||||
if len(ss) > 2 {
|
||||
go RemNodePlugin(ss[len(ss)-2])
|
||||
}
|
||||
|
||||
} else {
|
||||
err := os.WriteFile(filename, []byte(new), 0755)
|
||||
if err != nil {
|
||||
return &storage.Final{
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return &storage.Final{
|
||||
Now: "",
|
||||
}
|
||||
}
|
||||
if fin != nil {
|
||||
return fin
|
||||
}
|
||||
return &storage.Final{
|
||||
Error: errors.New("安装失败!!!"),
|
||||
Now: "",
|
||||
}
|
||||
// }
|
||||
// return &storage.Final{
|
||||
// Error: errors.New("安装失败!!!"),
|
||||
// }
|
||||
}
|
||||
|
||||
if new == "install" {
|
||||
@@ -206,7 +224,6 @@ func initPlugins() {
|
||||
Error: errors.New("订阅源异常"),
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,11 @@ func (bucket *Bucket) Set(key interface{}, value interface{}) (string, bool, err
|
||||
return msg, changed, fin.Error
|
||||
}
|
||||
if fin.Now != "" {
|
||||
new = fin.Now
|
||||
if new == storage.EMPTY {
|
||||
new = ""
|
||||
} else {
|
||||
new = fin.Now
|
||||
}
|
||||
}
|
||||
if fin.EndFunc != nil {
|
||||
endFuncs = append(endFuncs, fin.EndFunc)
|
||||
|
||||
@@ -7,6 +7,8 @@ type Listen struct {
|
||||
Handle func(old string, new string, key string) *Final
|
||||
}
|
||||
|
||||
const EMPTY = "__EMPTY__"
|
||||
|
||||
var Listens []Listen
|
||||
|
||||
var DisableHandle = func(uuid string) {
|
||||
|
||||
@@ -239,7 +239,11 @@ func (bucket *Bucket) Set(key interface{}, value interface{}) (string, bool, err
|
||||
return msg, changed, fin.Error
|
||||
}
|
||||
if fin.Now != "" {
|
||||
new = fin.Now
|
||||
if new == storage.EMPTY {
|
||||
new = ""
|
||||
} else {
|
||||
new = fin.Now
|
||||
}
|
||||
}
|
||||
if fin.EndFunc != nil {
|
||||
endFuncs = append(endFuncs, fin.EndFunc)
|
||||
|
||||
+2
-6
@@ -76,15 +76,11 @@ func initWeb() {
|
||||
for _, f := range Functions {
|
||||
if f.UUID == uuid && f.Public {
|
||||
plugin_downloads.Set(f.UUID, plugin_downloads.GetInt(f.UUID)+1)
|
||||
if f.Type == "goja" {
|
||||
if !isNameUuid(f.UUID) {
|
||||
c.String(200, publicScript(plugins.GetString(f.UUID)))
|
||||
return
|
||||
} else {
|
||||
v, ok := plugins_id.Load(f.UUID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
dir := filepath.Dir(v.(string))
|
||||
dir := filepath.Dir(f.Path)
|
||||
if _, err := os.Stat(dir); err != nil { //执行压缩
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user