Skip to content

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

:art: Support one-click enable/disable of all downloaded plugins https://github.com/siyuan-note/siyuan/issues/8523

Daniel41cd90b771f2
diff --git a/kernel/api/petal.go b/kernel/api/petal.go
index 8f5e66806e..9f6be41472 100644
--- a/kernel/api/petal.go
+++ b/kernel/api/petal.go
@@ -61,29 +61,3 @@ func setPetalEnabled(c *gin.Context) {
ret.Data = data
}
-
-func setPetalConf(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- param, err := gulu.JSON.MarshalJSON(arg)
- if nil != err {
- ret.Code = -1
- ret.Msg = err.Error()
- return
- }
-
- conf := &model.PetalConf{}
- if err = gulu.JSON.UnmarshalJSON(param, conf); nil != err {
- ret.Code = -1
- ret.Msg = err.Error()
- return
- }
-
- conf.Save()
-}
diff --git a/kernel/api/router.go b/kernel/api/router.go
index a18a72089b..592f72e44b 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -363,5 +363,4 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/petal/loadPetals", model.CheckAuth, model.CheckReadonly, loadPetals)
ginServer.Handle("POST", "/api/petal/setPetalEnabled", model.CheckAuth, model.CheckReadonly, setPetalEnabled)
- ginServer.Handle("POST", "/api/petal/setPetalConf", model.CheckAuth, model.CheckReadonly, setPetalConf)
}
diff --git a/kernel/conf/bazaar.go b/kernel/conf/bazaar.go
index 9dbbfcfe37..41bcc6c993 100644
--- a/kernel/conf/bazaar.go
+++ b/kernel/conf/bazaar.go
@@ -18,10 +18,12 @@ package conf
type Bazaar struct {
Trust bool `json:"trust"`
+ Petal bool `json:"petal"`
}
func NewBazaar() *Bazaar {
return &Bazaar{
Trust: false,
+ Petal: true,
}
}
diff --git a/kernel/model/plugin.go b/kernel/model/plugin.go
index 85e1066f4b..510b897971 100644
--- a/kernel/model/plugin.go
+++ b/kernel/model/plugin.go
@@ -40,33 +40,6 @@ type Petal struct {
I18n map[string]interface{} `json:"i18n"` // i18n text
}
-type PetalConf struct {
- Enabled bool `json:"enabled"`
-}
-
-func (pConf *PetalConf) Save() {
- if util.ReadOnly {
- return
- }
-
- petalsStoreLock.Lock()
- defer petalsStoreLock.Unlock()
-
- data, _ := gulu.JSON.MarshalIndentJSON(pConf, "", " ")
- petalDir := filepath.Join(util.DataDir, "storage", "petal")
- if err := os.MkdirAll(petalDir, 0777); nil != err {
- logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
- return
- }
-
- confPath := filepath.Join(petalDir, "conf.json")
- if err := filelock.WriteFile(confPath, data); nil != err {
- logging.LogErrorf("write petal conf [%s] failed: %s", confPath, err)
- util.ReportFileSysFatalError(err)
- return
- }
-}
-
func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, err error) {
petals := getPetals()
@@ -99,23 +72,8 @@ func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, er
func LoadPetals(frontend string) (ret []*Petal) {
ret = []*Petal{}
- petalDir := filepath.Join(util.DataDir, "storage", "petal")
- confPath := filepath.Join(petalDir, "conf.json")
- if gulu.File.IsExist(confPath) {
- data, err := filelock.ReadFile(confPath)
- if nil != err {
- logging.LogErrorf("read petal conf [%s] failed: %s", confPath, err)
- } else {
- petalConf := &PetalConf{}
- if err = gulu.JSON.UnmarshalJSON(data, petalConf); nil != err {
- logging.LogErrorf("unmarshal petal conf [%s] failed: %s", confPath, err)
- } else {
- if !petalConf.Enabled {
- logging.LogInfof("plugin system has been disabled")
- return
- }
- }
- }
+ if !Conf.Bazaar.Petal {
+ return
}
petals := getPetals()