diff --git a/core/api_bucket.go b/core/api_bucket.go index 429e875..033de1a 100644 --- a/core/api_bucket.go +++ b/core/api_bucket.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "net/http" "os" - "path/filepath" "strconv" "strings" "time" @@ -195,16 +194,6 @@ func init() { for bk, v := range updates { ar := strings.SplitN(bk, ".", 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) if msg != "" { messages[bk] = msg diff --git a/core/grpc_plugins.go b/core/grpc_plugins.go index 182e5ea..4c739d9 100644 --- a/core/grpc_plugins.go +++ b/core/grpc_plugins.go @@ -129,12 +129,13 @@ func initNodePlugins() { // RemNodePlugin(plugin_name) AddNodePlugin(event.Name, plugin_name) } - case "REMOVE", "RENAME", "REMOVE|RENAME": + case "REMOVE", "RENAME", "REMOVE|RENAME", "REMOVE|WRITE": if plugin_dir { watcher.Remove(event.Name) // fmt.Println("移除插件目录", event.Name) // fmt.Println("移除插件", plugin_name) RemNodePlugin(plugin_name) + } else if plugin_index { // fmt.Println("移除插件", plugin_name) RemNodePlugin(plugin_name) @@ -156,6 +157,9 @@ func initNodePlugins() { } func RemNodePlugin(name string) error { + if name == "" { + return nil + } pluginLock.Lock() defer pluginLock.Unlock() key := nameUuid(name) @@ -163,6 +167,7 @@ func RemNodePlugin(name string) error { // fmt.Println("rem", key, name) for i := range Functions { if Functions[i].UUID == key { + f := Functions[i] // fmt.Println("pl", key) DestroyAdapterByUUID(key) Functions[i].Running = false @@ -178,6 +183,8 @@ func RemNodePlugin(name string) error { CancelHttpListen(key) remStatic(key) storage.DisableHandle(key) + + console.Log("已移除 %s%s", f.Title, f.Suffix) break } } @@ -192,6 +199,9 @@ func nameUuid(name string) string { var plugins_id sync.Map func AddNodePlugin(path, name string) error { + if name == "" { + return nil + } pluginLock.Lock() defer pluginLock.Unlock() @@ -247,7 +257,7 @@ func AddNodePlugin(path, name string) error { scanner := bufio.NewScanner(stdout) for scanner.Scan() { data := scanner.Text() - fmt.Println("log", data) + fmt.Println(data) // if _, err := file.WriteString(data + "\n"); err != nil { // fmt.Printf("写入文件失败:%v\n", err) // } @@ -259,7 +269,7 @@ func AddNodePlugin(path, name string) error { scanner := bufio.NewScanner(stderr) for scanner.Scan() { data := scanner.Text() - fmt.Fprintln(os.Stderr, "err "+data) + fmt.Println(data) // if _, err := file.WriteString(data + "\n"); err != nil { // fmt.Printf("写入文件失败:%v\n", err) // } diff --git a/core/plugin_core.go b/core/plugin_core.go index 80396c6..cd24c75 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "os" + "path/filepath" "reflect" "regexp" "strings" @@ -110,11 +111,28 @@ func initPlugins() { storage.Watch(plugins, nil, func(old, new, key string) (fin *storage.Final) { pluginLock.Lock() 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" { for _, p := range plugin_list { + // fmt.Println(p.UUID, p.UUID == key, p.Title) if p.UUID != key { continue } + // fmt.Println("(p.Type", p.Type) + if p.Type != "goja" && p.Type != "" { //下载目录插件 // Content-Type var prefix = "?uuid=" + p.UUID diff --git a/main.js b/main.js index 96fc701..4894ddf 100755 --- a/main.js +++ b/main.js @@ -1,7 +1 @@ -/** - * @title . - * @create_at 2023-07-25 16:47:05 - * @description 🐒这个人很懒什么都没有留下 - * @author 佚名 - * @version v1.0.0 - */ \ No newline at end of file +/// \ No newline at end of file