This commit is contained in:
1-6
2023-07-25 17:34:30 +08:00
parent 17006a989d
commit 31ae3384d0
4 changed files with 32 additions and 21 deletions
-11
View File
@@ -6,7 +6,6 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -195,16 +194,6 @@ func init() {
for bk, v := range updates { for bk, v := range updates {
ar := strings.SplitN(bk, ".", 2) ar := strings.SplitN(bk, ".", 2)
if len(ar) == 2 { if len(ar) == 2 {
if vv, ok := plugins_id.Load(ar[1]); ok {
filename := vv.(string)
vs := fmt.Sprint(v)
if vs == "" {
os.RemoveAll(filepath.Dir(filename))
} else {
os.WriteFile(filename, []byte(vs), 0755)
}
continue
}
msg, changed, err := SetBucketKeyValue(MakeBucket(ar[0]), ar[1], v) msg, changed, err := SetBucketKeyValue(MakeBucket(ar[0]), ar[1], v)
if msg != "" { if msg != "" {
messages[bk] = msg messages[bk] = msg
+13 -3
View File
@@ -129,12 +129,13 @@ func initNodePlugins() {
// RemNodePlugin(plugin_name) // RemNodePlugin(plugin_name)
AddNodePlugin(event.Name, plugin_name) AddNodePlugin(event.Name, plugin_name)
} }
case "REMOVE", "RENAME", "REMOVE|RENAME": case "REMOVE", "RENAME", "REMOVE|RENAME", "REMOVE|WRITE":
if plugin_dir { if plugin_dir {
watcher.Remove(event.Name) watcher.Remove(event.Name)
// fmt.Println("移除插件目录", event.Name) // fmt.Println("移除插件目录", event.Name)
// fmt.Println("移除插件", plugin_name) // fmt.Println("移除插件", plugin_name)
RemNodePlugin(plugin_name) RemNodePlugin(plugin_name)
} else if plugin_index { } else if plugin_index {
// fmt.Println("移除插件", plugin_name) // fmt.Println("移除插件", plugin_name)
RemNodePlugin(plugin_name) RemNodePlugin(plugin_name)
@@ -156,6 +157,9 @@ func initNodePlugins() {
} }
func RemNodePlugin(name string) error { func RemNodePlugin(name string) error {
if name == "" {
return nil
}
pluginLock.Lock() pluginLock.Lock()
defer pluginLock.Unlock() defer pluginLock.Unlock()
key := nameUuid(name) key := nameUuid(name)
@@ -163,6 +167,7 @@ func RemNodePlugin(name string) error {
// fmt.Println("rem", key, name) // fmt.Println("rem", key, name)
for i := range Functions { for i := range Functions {
if Functions[i].UUID == key { if Functions[i].UUID == key {
f := Functions[i]
// fmt.Println("pl", key) // fmt.Println("pl", key)
DestroyAdapterByUUID(key) DestroyAdapterByUUID(key)
Functions[i].Running = false Functions[i].Running = false
@@ -178,6 +183,8 @@ func RemNodePlugin(name string) error {
CancelHttpListen(key) CancelHttpListen(key)
remStatic(key) remStatic(key)
storage.DisableHandle(key) storage.DisableHandle(key)
console.Log("已移除 %s%s", f.Title, f.Suffix)
break break
} }
} }
@@ -192,6 +199,9 @@ func nameUuid(name string) string {
var plugins_id sync.Map var plugins_id sync.Map
func AddNodePlugin(path, name string) error { func AddNodePlugin(path, name string) error {
if name == "" {
return nil
}
pluginLock.Lock() pluginLock.Lock()
defer pluginLock.Unlock() defer pluginLock.Unlock()
@@ -247,7 +257,7 @@ func AddNodePlugin(path, name string) error {
scanner := bufio.NewScanner(stdout) scanner := bufio.NewScanner(stdout)
for scanner.Scan() { for scanner.Scan() {
data := scanner.Text() data := scanner.Text()
fmt.Println("log", data) fmt.Println(data)
// if _, err := file.WriteString(data + "\n"); err != nil { // if _, err := file.WriteString(data + "\n"); err != nil {
// fmt.Printf("写入文件失败:%v\n", err) // fmt.Printf("写入文件失败:%v\n", err)
// } // }
@@ -259,7 +269,7 @@ func AddNodePlugin(path, name string) error {
scanner := bufio.NewScanner(stderr) scanner := bufio.NewScanner(stderr)
for scanner.Scan() { for scanner.Scan() {
data := scanner.Text() data := scanner.Text()
fmt.Fprintln(os.Stderr, "err "+data) fmt.Println(data)
// if _, err := file.WriteString(data + "\n"); err != nil { // if _, err := file.WriteString(data + "\n"); err != nil {
// fmt.Printf("写入文件失败:%v\n", err) // fmt.Printf("写入文件失败:%v\n", err)
// } // }
+18
View File
@@ -6,6 +6,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"path/filepath"
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
@@ -110,11 +111,28 @@ func initPlugins() {
storage.Watch(plugins, nil, func(old, new, key string) (fin *storage.Final) { storage.Watch(plugins, nil, func(old, new, key string) (fin *storage.Final) {
pluginLock.Lock() pluginLock.Lock()
defer pluginLock.Unlock() defer pluginLock.Unlock()
// fmt.Println("new", new, key)
if vv, ok := plugins_id.Load(key); ok {
filename := vv.(string)
if new == "" {
os.RemoveAll(filepath.Dir(filename))
} else {
os.WriteFile(filename, []byte(new), 0755)
}
return &storage.Final{
Now: "",
}
}
if new == "install" { if new == "install" {
for _, p := range plugin_list { for _, p := range plugin_list {
// fmt.Println(p.UUID, p.UUID == key, p.Title)
if p.UUID != key { if p.UUID != key {
continue continue
} }
// fmt.Println("(p.Type", p.Type)
if p.Type != "goja" && p.Type != "" { //下载目录插件 if p.Type != "goja" && p.Type != "" { //下载目录插件
// Content-Type // Content-Type
var prefix = "?uuid=" + p.UUID var prefix = "?uuid=" + p.UUID
+1 -7
View File
@@ -1,7 +1 @@
/** ///
* @title .
* @create_at 2023-07-25 16:47:05
* @description 🐒这个人很懒什么都没有留下
* @author 佚名
* @version v1.0.0
*/