x
This commit is contained in:
+61
-36
@@ -157,15 +157,14 @@ func initNodePlugins() {
|
|||||||
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)
|
AddNodePlugin(event.Name, plugin_name)
|
||||||
|
|
||||||
} else if plugin_index {
|
} else if plugin_index {
|
||||||
// fmt.Println("移除插件", plugin_name)
|
// fmt.Println("移除插件", plugin_name)
|
||||||
RemNodePlugin(plugin_name)
|
AddNodePlugin(event.Name, plugin_name)
|
||||||
}
|
}
|
||||||
case "WRITE": //, "CHMOD"
|
case "WRITE": //, "CHMOD"
|
||||||
if plugin_index {
|
if plugin_index {
|
||||||
RemNodePlugin(plugin_name)
|
|
||||||
AddNodePlugin(event.Name, plugin_name)
|
AddNodePlugin(event.Name, plugin_name)
|
||||||
// fmt.Println("变更插件", event.Name, plugin_name)
|
// fmt.Println("变更插件", event.Name, plugin_name)
|
||||||
}
|
}
|
||||||
@@ -179,37 +178,36 @@ func initNodePlugins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemNodePlugin(name string) bool {
|
// func RemNodePlugin2(name string) bool {
|
||||||
if name == "" {
|
// if name == "" {
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
pluginLock.Lock()
|
// pluginLock.Lock()
|
||||||
defer pluginLock.Unlock()
|
// defer pluginLock.Unlock()
|
||||||
key := nameUuid(name)
|
// key := nameUuid(name)
|
||||||
for i := range Functions {
|
// for i := range Functions {
|
||||||
if Functions[i].UUID == key {
|
// if Functions[i].UUID == key {
|
||||||
f := Functions[i]
|
// f := Functions[i]
|
||||||
// fmt.Println("pl", key)
|
// DestroyAdapterByUUID(key)
|
||||||
DestroyAdapterByUUID(key)
|
// Functions[i].Running = false
|
||||||
Functions[i].Running = false
|
// if len(Functions[i].CronIds) != 0 {
|
||||||
if len(Functions[i].CronIds) != 0 {
|
// for _, id := range Functions[i].CronIds {
|
||||||
for _, id := range Functions[i].CronIds {
|
// CRON.Remove(cron.EntryID(id))
|
||||||
CRON.Remove(cron.EntryID(id))
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// Functions = append(Functions[:i], Functions[i+1:]...)
|
||||||
Functions = append(Functions[:i], Functions[i+1:]...)
|
// CancelPluginCrons(key)
|
||||||
CancelPluginCrons(key)
|
// CancelPluginWebs(key)
|
||||||
CancelPluginWebs(key)
|
// CancelPluginlistening(key)
|
||||||
CancelPluginlistening(key)
|
// CancelHttpListen(key)
|
||||||
CancelHttpListen(key)
|
// remStatic(key)
|
||||||
remStatic(key)
|
// storage.DisableHandle(key)
|
||||||
storage.DisableHandle(key)
|
// console.Log("已移除 %s%s", f.Title, f.Suffix)
|
||||||
console.Log("已移除 %s%s", f.Title, f.Suffix)
|
// return true
|
||||||
return true
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// return false
|
||||||
return false
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
func nameUuid(name string) string {
|
func nameUuid(name string) string {
|
||||||
hash := sha1.Sum([]byte(name))
|
hash := sha1.Sum([]byte(name))
|
||||||
@@ -227,11 +225,35 @@ func AddNodePlugin(path, name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
uuid := nameUuid(name)
|
uuid := nameUuid(name)
|
||||||
plugins.Set(uuid, "")
|
|
||||||
pluginLock.Lock()
|
pluginLock.Lock()
|
||||||
defer pluginLock.Unlock()
|
defer pluginLock.Unlock()
|
||||||
|
//移除
|
||||||
|
var rf *common.Function
|
||||||
|
for i := range Functions {
|
||||||
|
if Functions[i].UUID == uuid {
|
||||||
|
rf = Functions[i]
|
||||||
|
DestroyAdapterByUUID(uuid)
|
||||||
|
Functions[i].Running = false
|
||||||
|
if len(Functions[i].CronIds) != 0 {
|
||||||
|
for _, id := range Functions[i].CronIds {
|
||||||
|
CRON.Remove(cron.EntryID(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Functions = append(Functions[:i], Functions[i+1:]...)
|
||||||
|
CancelPluginCrons(uuid)
|
||||||
|
CancelPluginWebs(uuid)
|
||||||
|
CancelPluginlistening(uuid)
|
||||||
|
CancelHttpListen(uuid)
|
||||||
|
remStatic(uuid)
|
||||||
|
storage.DisableHandle(uuid)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if rf != nil {
|
||||||
|
console.Log("已卸载 %s%s", rf.Title, rf.Suffix)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
@@ -247,7 +269,6 @@ func AddNodePlugin(path, name string) error {
|
|||||||
// fmt.Println("add,", uuid, name)
|
// fmt.Println("add,", uuid, name)
|
||||||
f, cbs := pluginParse(script, uuid)
|
f, cbs := pluginParse(script, uuid)
|
||||||
f.Reload = func() { //重载
|
f.Reload = func() { //重载
|
||||||
RemNodePlugin(path)
|
|
||||||
AddNodePlugin(path, name)
|
AddNodePlugin(path, name)
|
||||||
}
|
}
|
||||||
f.Suffix = ".js"
|
f.Suffix = ".js"
|
||||||
@@ -355,7 +376,11 @@ func AddNodePlugin(path, name string) error {
|
|||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
if !f.OnStart {
|
if !f.OnStart {
|
||||||
|
if rf == nil {
|
||||||
console.Log("已加载 %s%s", f.Title, f.Suffix)
|
console.Log("已加载 %s%s", f.Title, f.Suffix)
|
||||||
|
} else {
|
||||||
|
console.Log("已重载 %s%s", f.Title, f.Suffix)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AddCommand([]*common.Function{f})
|
AddCommand([]*common.Function{f})
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+4
-3
@@ -116,7 +116,6 @@ 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(old, new, key, "===")
|
|
||||||
if new == "uninstall" {
|
if new == "uninstall" {
|
||||||
new = ""
|
new = ""
|
||||||
fin = &storage.Final{
|
fin = &storage.Final{
|
||||||
@@ -179,6 +178,7 @@ func initPlugins() {
|
|||||||
if new == "reload" { //重载
|
if new == "reload" { //重载
|
||||||
go f.Reload()
|
go f.Reload()
|
||||||
} else if new == "" {
|
} else if new == "" {
|
||||||
|
// fmt.Println("new", new)
|
||||||
ss := strings.Split(filename, "/")
|
ss := strings.Split(filename, "/")
|
||||||
processes.Range(func(key, value any) bool { //先停止脚本,避免windows锁定文件
|
processes.Range(func(key, value any) bool { //先停止脚本,避免windows锁定文件
|
||||||
p := key.(*exec.Cmd)
|
p := key.(*exec.Cmd)
|
||||||
@@ -198,8 +198,9 @@ func initPlugins() {
|
|||||||
})
|
})
|
||||||
os.RemoveAll(filepath.Dir(filename))
|
os.RemoveAll(filepath.Dir(filename))
|
||||||
// fmt.Println(strings.Join(ss, " "))
|
// fmt.Println(strings.Join(ss, " "))
|
||||||
if len(ss) > 2 {
|
l := len(ss)
|
||||||
go RemNodePlugin(ss[len(ss)-2])
|
if l > 2 {
|
||||||
|
go AddNodePlugin(filename, ss[l-1])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := os.WriteFile(filename, []byte(new), 0755)
|
err := os.WriteFile(filename, []byte(new), 0755)
|
||||||
|
|||||||
Reference in New Issue
Block a user