This commit is contained in:
1-6
2023-07-26 15:50:24 +08:00
parent 859133c0a2
commit 5eeb4ccd83
3 changed files with 42 additions and 32 deletions
+6 -2
View File
@@ -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
+35 -29
View File
@@ -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{
+1 -1
View File
@@ -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:]
}