mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🧑💻 Add field disabledInPublish
to the marketplace package metadata to indicate whether it is disabled in the publishing service https://github.com/siyuan-note/siyuan/issues/11730
This commit is contained in:
parent
9410a70a2b
commit
6ff4439be3
4 changed files with 26 additions and 22 deletions
|
@ -35,9 +35,9 @@ func loadPetals(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
frontend := arg["frontend"].(string)
|
frontend := arg["frontend"].(string)
|
||||||
|
isPublish := model.IsReadOnlyRole(model.GetGinContextRole(c))
|
||||||
|
|
||||||
petals := model.LoadPetals(frontend)
|
ret.Data = model.LoadPetals(frontend, isPublish)
|
||||||
ret.Data = petals
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setPetalEnabled(c *gin.Context) {
|
func setPetalEnabled(c *gin.Context) {
|
||||||
|
|
|
@ -99,17 +99,18 @@ type Funding struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Package struct {
|
type Package struct {
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
MinAppVersion string `json:"minAppVersion"`
|
MinAppVersion string `json:"minAppVersion"`
|
||||||
Backends []string `json:"backends"`
|
DisabledInPublish bool `json:"disabledInPublish"`
|
||||||
Frontends []string `json:"frontends"`
|
Backends []string `json:"backends"`
|
||||||
DisplayName *DisplayName `json:"displayName"`
|
Frontends []string `json:"frontends"`
|
||||||
Description *Description `json:"description"`
|
DisplayName *DisplayName `json:"displayName"`
|
||||||
Readme *Readme `json:"readme"`
|
Description *Description `json:"description"`
|
||||||
Funding *Funding `json:"funding"`
|
Readme *Readme `json:"readme"`
|
||||||
Keywords []string `json:"keywords"`
|
Funding *Funding `json:"funding"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
|
||||||
PreferredFunding string `json:"preferredFunding"`
|
PreferredFunding string `json:"preferredFunding"`
|
||||||
PreferredName string `json:"preferredName"`
|
PreferredName string `json:"preferredName"`
|
||||||
|
|
|
@ -134,7 +134,7 @@ func Plugins(frontend string) (plugins []*Plugin) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseInstalledPlugin(name, frontend string) (found bool, displayName string, incompatible bool) {
|
func ParseInstalledPlugin(name, frontend string) (found bool, displayName string, incompatible, disabledInPublish bool) {
|
||||||
pluginsPath := filepath.Join(util.DataDir, "plugins")
|
pluginsPath := filepath.Join(util.DataDir, "plugins")
|
||||||
if !util.IsPathRegularDirOrSymlinkDir(pluginsPath) {
|
if !util.IsPathRegularDirOrSymlinkDir(pluginsPath) {
|
||||||
return
|
return
|
||||||
|
@ -163,6 +163,7 @@ func ParseInstalledPlugin(name, frontend string) (found bool, displayName string
|
||||||
found = true
|
found = true
|
||||||
displayName = GetPreferredName(plugin.Package)
|
displayName = GetPreferredName(plugin.Package)
|
||||||
incompatible = isIncompatiblePlugin(plugin, frontend)
|
incompatible = isIncompatiblePlugin(plugin, frontend)
|
||||||
|
disabledInPublish = plugin.DisabledInPublish
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,11 @@ import (
|
||||||
|
|
||||||
// Petal represents a plugin's management status.
|
// Petal represents a plugin's management status.
|
||||||
type Petal struct {
|
type Petal struct {
|
||||||
Name string `json:"name"` // Plugin name
|
Name string `json:"name"` // Plugin name
|
||||||
DisplayName string `json:"displayName"` // Plugin display name
|
DisplayName string `json:"displayName"` // Plugin display name
|
||||||
Enabled bool `json:"enabled"` // Whether enabled
|
Enabled bool `json:"enabled"` // Whether enabled
|
||||||
Incompatible bool `json:"incompatible"` // Whether incompatible
|
Incompatible bool `json:"incompatible"` // Whether incompatible
|
||||||
|
DisabledInPublish bool `json:"disabledInPublish"` // Whether disabled in publish mode
|
||||||
|
|
||||||
JS string `json:"js"` // JS code
|
JS string `json:"js"` // JS code
|
||||||
CSS string `json:"css"` // CSS code
|
CSS string `json:"css"` // CSS code
|
||||||
|
@ -44,7 +45,7 @@ type Petal struct {
|
||||||
func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, err error) {
|
func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, err error) {
|
||||||
petals := getPetals()
|
petals := getPetals()
|
||||||
|
|
||||||
found, displayName, incompatible := bazaar.ParseInstalledPlugin(name, frontend)
|
found, displayName, incompatible, disabledInPublish := bazaar.ParseInstalledPlugin(name, frontend)
|
||||||
if !found {
|
if !found {
|
||||||
logging.LogErrorf("plugin [%s] not found", name)
|
logging.LogErrorf("plugin [%s] not found", name)
|
||||||
return
|
return
|
||||||
|
@ -60,6 +61,7 @@ func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, er
|
||||||
ret.DisplayName = displayName
|
ret.DisplayName = displayName
|
||||||
ret.Enabled = enabled
|
ret.Enabled = enabled
|
||||||
ret.Incompatible = incompatible
|
ret.Incompatible = incompatible
|
||||||
|
ret.DisabledInPublish = disabledInPublish
|
||||||
|
|
||||||
if incompatible {
|
if incompatible {
|
||||||
err = fmt.Errorf(Conf.Language(205))
|
err = fmt.Errorf(Conf.Language(205))
|
||||||
|
@ -72,7 +74,7 @@ func SetPetalEnabled(name string, enabled bool, frontend string) (ret *Petal, er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadPetals(frontend string) (ret []*Petal) {
|
func LoadPetals(frontend string, isPublish bool) (ret []*Petal) {
|
||||||
ret = []*Petal{}
|
ret = []*Petal{}
|
||||||
|
|
||||||
if Conf.Bazaar.PetalDisabled {
|
if Conf.Bazaar.PetalDisabled {
|
||||||
|
@ -93,8 +95,8 @@ func LoadPetals(frontend string) (ret []*Petal) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, petal.DisplayName, petal.Incompatible = bazaar.ParseInstalledPlugin(petal.Name, frontend)
|
_, petal.DisplayName, petal.Incompatible, petal.DisabledInPublish = bazaar.ParseInstalledPlugin(petal.Name, frontend)
|
||||||
if !petal.Enabled || petal.Incompatible {
|
if !petal.Enabled || petal.Incompatible || (isPublish && petal.DisabledInPublish) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue