x
This commit is contained in:
@@ -164,7 +164,7 @@ func RemNodePlugin(name string) error {
|
|||||||
pluginLock.Lock()
|
pluginLock.Lock()
|
||||||
defer pluginLock.Unlock()
|
defer pluginLock.Unlock()
|
||||||
key := nameUuid(name)
|
key := nameUuid(name)
|
||||||
// plugins_id.Delete(key)
|
plugins_id.Delete(key)
|
||||||
// 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 {
|
||||||
@@ -194,7 +194,11 @@ func RemNodePlugin(name string) error {
|
|||||||
|
|
||||||
func nameUuid(name string) string {
|
func nameUuid(name string) string {
|
||||||
hash := sha1.Sum([]byte(name))
|
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
|
var plugins_id sync.Map
|
||||||
|
|||||||
+31
-25
@@ -113,36 +113,12 @@ func initPlugins() {
|
|||||||
defer pluginLock.Unlock()
|
defer pluginLock.Unlock()
|
||||||
// fmt.Println("new", new, key)
|
// fmt.Println("new", new, key)
|
||||||
|
|
||||||
if new != "install" {
|
if isNameUuid(key) {
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 != "" { //下载目录插件
|
|
||||||
// Content-Type
|
|
||||||
var prefix = "?uuid=" + p.UUID
|
var prefix = "?uuid=" + p.UUID
|
||||||
address := p.Address
|
address := p.Address
|
||||||
if !strings.HasSuffix(address, "list.json") {
|
if !strings.HasSuffix(address, "list.json") {
|
||||||
@@ -185,6 +161,36 @@ func initPlugins() {
|
|||||||
Now: "",
|
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))
|
script := string(fetchScript(p.Address, key))
|
||||||
if f, _, _ := initPlugin(script, p.UUID, ""); f.CreateAt != "" {
|
if f, _, _ := initPlugin(script, p.UUID, ""); f.CreateAt != "" {
|
||||||
fin = &storage.Final{
|
fin = &storage.Final{
|
||||||
|
|||||||
+1
-1
@@ -462,7 +462,7 @@ func initWeb() {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := srvs[0].Shutdown(ctx); err == nil {
|
if err := srvs[0].Shutdown(ctx); err == nil {
|
||||||
logs.Info("Http服务(%d)关闭", old)
|
logs.Info("Http服务(%v)关闭", old)
|
||||||
}
|
}
|
||||||
srvs = srvs[1:]
|
srvs = srvs[1:]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user