From 5eeb4ccd837da38ec8af637128aa0dfd2d335910 Mon Sep 17 00:00:00 2001 From: 1-6 Date: Wed, 26 Jul 2023 15:50:24 +0800 Subject: [PATCH] x --- core/grpc_plugins.go | 8 ++++-- core/plugin_core.go | 64 ++++++++++++++++++++++++-------------------- core/web.go | 2 +- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/core/grpc_plugins.go b/core/grpc_plugins.go index 2aebec5..128a39a 100644 --- a/core/grpc_plugins.go +++ b/core/grpc_plugins.go @@ -164,7 +164,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 { @@ -194,7 +194,11 @@ func RemNodePlugin(name string) error { func nameUuid(name string) string { hash := sha1.Sum([]byte(name)) - return uuid.NewSHA1(uuid.Nil, hash[:]).String() + return strings.ReplaceAll(uuid.NewSHA1(uuid.Nil, hash[:]).String(), "-", "_") +} + +func isNameUuid(uuid string) bool { + return strings.Contains(uuid, "_") } var plugins_id sync.Map diff --git a/core/plugin_core.go b/core/plugin_core.go index f5fe431..99b0c64 100644 --- a/core/plugin_core.go +++ b/core/plugin_core.go @@ -113,36 +113,12 @@ func initPlugins() { defer pluginLock.Unlock() // fmt.Println("new", new, key) - if new != "install" { - if vv, ok := plugins_id.Load(key); ok { - filename := vv.(string) - if new == "" { - os.RemoveAll(filepath.Dir(filename)) - } else { - fmt.Println("WriteFile", []byte(new)) - err := os.WriteFile(filename, []byte(new), 0755) - if err != nil { - return &storage.Final{ - Error: err, - } + if isNameUuid(key) { + if new == "install" { + for _, p := range plugin_list { + if p.UUID != key { + continue } - } - 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 address := p.Address if !strings.HasSuffix(address, "list.json") { @@ -185,6 +161,36 @@ func initPlugins() { Now: "", } } + } + 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, + } + } + } + return &storage.Final{ + Now: "", + } + } + return &storage.Final{ + Error: errors.New("非法操作!"), + } + } + + 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) + script := string(fetchScript(p.Address, key)) if f, _, _ := initPlugin(script, p.UUID, ""); f.CreateAt != "" { fin = &storage.Final{ diff --git a/core/web.go b/core/web.go index 9db7732..86b3ecf 100644 --- a/core/web.go +++ b/core/web.go @@ -462,7 +462,7 @@ func initWeb() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := srvs[0].Shutdown(ctx); err == nil { - logs.Info("Http服务(%d)关闭", old) + logs.Info("Http服务(%v)关闭", old) } srvs = srvs[1:] }