Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Plugin uninstall

Liang Ding6eb3673b6e6e
diff --git a/kernel/go.mod b/kernel/go.mod
index c365020649..d05f3e0e19 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -6,7 +6,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/css v0.1.2
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd
- github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493
+ github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20230220142845-f237b6348b3e
diff --git a/kernel/go.sum b/kernel/go.sum
index 52e088fa33..8ab4f8d4f1 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -8,8 +8,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd h1:PgbmnoTqfVbYyhUljovnAz6l/oWPlbM1d5yrkVDHO1w=
github.com/88250/gulu v1.2.3-0.20230501031728-4d62370997cd/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
-github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493 h1:F6C9dVvQVwxCOAd88Ea4WchCzR6Ekr/Q4IiqLYWfDyw=
-github.com/88250/lute v1.7.6-0.20230427065909-d447ad8fc493/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
+github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef h1:nNRs8oFCKPRsgnz6k2m0iDXXm9ManWyvP7K4J/OMov8=
+github.com/88250/lute v1.7.6-0.20230506015935-ca8269ccf0ef/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
diff --git a/kernel/model/bazzar.go b/kernel/model/bazzar.go
index 44a743a0f4..b53ebc040f 100644
--- a/kernel/model/bazzar.go
+++ b/kernel/model/bazzar.go
@@ -78,6 +78,15 @@ func UninstallBazaarPlugin(pluginName string) error {
if nil != err {
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
}
+
+ petals := getPetals()
+ for i, petal := range petals {
+ if petal.Name == pluginName {
+ petals = append(petals[:i], petals[i+1:]...)
+ break
+ }
+ }
+ savePetals(petals)
return nil
}
diff --git a/kernel/model/plugin.go b/kernel/model/plugin.go
index 1052d8028f..8aac44ccd1 100644
--- a/kernel/model/plugin.go
+++ b/kernel/model/plugin.go
@@ -21,6 +21,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "sync"
"github.com/88250/gulu"
"github.com/siyuan-note/filelock"
@@ -41,19 +42,7 @@ type Petal struct {
}
func SetPetalEnabled(name string, enabled bool) {
- petals := []*Petal{}
- petalDir := filepath.Join(util.DataDir, "storage", "petal")
- confPath := filepath.Join(petalDir, "petals.json")
- data, err := filelock.ReadFile(confPath)
- if nil != err {
- logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
- return
- }
-
- if err = gulu.JSON.UnmarshalJSON(data, &petals); nil != err {
- logging.LogErrorf("unmarshal petals failed: %s", err)
- return
- }
+ petals := getPetals()
plugins := bazaar.InstalledPlugins()
var plugin *bazaar.Plugin
@@ -80,50 +69,7 @@ func SetPetalEnabled(name string, enabled bool) {
petal.Enabled = enabled
}
- if data, err = gulu.JSON.MarshalIndentJSON(petals, "", "\t"); nil != err {
- logging.LogErrorf("marshal petals failed: %s", err)
- return
- }
- if err = filelock.WriteFile(confPath, data); nil != err {
- logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
- return
- }
-}
-
-func getPetals() (ret []*Petal) {
- ret = []*Petal{}
-
- petalDir := filepath.Join(util.DataDir, "storage", "petal")
- if err := os.MkdirAll(petalDir, 0755); nil != err {
- logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
- return
- }
-
- confPath := filepath.Join(petalDir, "petals.json")
- if !gulu.File.IsExist(confPath) {
- data, err := gulu.JSON.MarshalIndentJSON(ret, "", "\t")
- if nil != err {
- logging.LogErrorf("marshal petals failed: %s", err)
- return
- }
- if err = filelock.WriteFile(confPath, data); nil != err {
- logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
- return
- }
- return
- }
-
- data, err := filelock.ReadFile(confPath)
- if nil != err {
- logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
- return
- }
-
- if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
- logging.LogErrorf("unmarshal petals failed: %s", err)
- return
- }
- return
+ savePetals(petals)
}
func LoadPetals() (ret []*Petal) {
@@ -172,6 +118,63 @@ func LoadPetals() (ret []*Petal) {
return
}
+var petalsStoreLock = sync.Mutex{}
+
+func savePetals(petals []*Petal) {
+ petalsStoreLock.Lock()
+ defer petalsStoreLock.Unlock()
+
+ petalDir := filepath.Join(util.DataDir, "storage", "petal")
+ confPath := filepath.Join(petalDir, "petals.json")
+ data, err := gulu.JSON.MarshalIndentJSON(petals, "", "\t")
+ if nil != err {
+ logging.LogErrorf("marshal petals failed: %s", err)
+ return
+ }
+ if err = filelock.WriteFile(confPath, data); nil != err {
+ logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
+ return
+ }
+}
+
+func getPetals() (ret []*Petal) {
+ petalsStoreLock.Lock()
+ defer petalsStoreLock.Unlock()
+
+ ret = []*Petal{}
+ petalDir := filepath.Join(util.DataDir, "storage", "petal")
+ if err := os.MkdirAll(petalDir, 0755); nil != err {
+ logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
+ return
+ }
+
+ confPath := filepath.Join(petalDir, "petals.json")
+ if !gulu.File.IsExist(confPath) {
+ data, err := gulu.JSON.MarshalIndentJSON(ret, "", "\t")
+ if nil != err {
+ logging.LogErrorf("marshal petals failed: %s", err)
+ return
+ }
+ if err = filelock.WriteFile(confPath, data); nil != err {
+ logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
+ return
+ }
+ return
+ }
+
+ data, err := filelock.ReadFile(confPath)
+ if nil != err {
+ logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
+ return
+ }
+
+ if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
+ logging.LogErrorf("unmarshal petals failed: %s", err)
+ return
+ }
+ return
+}
+
func getPetalByName(name string, petals []*Petal) (ret *Petal) {
for _, p := range petals {
if name == p.Name {