Pārlūkot izejas kodu

:art: Init plugin system https://github.com/siyuan-note/siyuan/issues/8041

Liang Ding 2 gadi atpakaļ
vecāks
revīzija
b7ae8295a5

+ 3 - 0
kernel/bazaar/icon.go

@@ -71,6 +71,8 @@ func Icons() (icons []*Icon) {
 		icon.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		icon.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		icon.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		icon.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
 		icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
+		icon.Funding = parseFunding(repo["package"].(map[string]interface{}))
+		icon.PreferredFunding = getPreferredFunding(icon.Funding)
 		icon.Updated = repo["updated"].(string)
 		icon.Updated = repo["updated"].(string)
 		icon.Stars = int(repo["stars"].(float64))
 		icon.Stars = int(repo["stars"].(float64))
 		icon.OpenIssues = int(repo["openIssues"].(float64))
 		icon.OpenIssues = int(repo["openIssues"].(float64))
@@ -134,6 +136,7 @@ func InstalledIcons() (ret []*Icon) {
 		icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
 		icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
 		icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
 		icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
 		icon.Funding = parseFunding(iconConf)
 		icon.Funding = parseFunding(iconConf)
+		icon.PreferredFunding = getPreferredFunding(icon.Funding)
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		if nil != statErr {
 		if nil != statErr {
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)

+ 50 - 7
kernel/bazaar/package.go

@@ -38,6 +38,18 @@ import (
 	"golang.org/x/text/transform"
 	"golang.org/x/text/transform"
 )
 )
 
 
+type Description struct {
+	Default string `json:"default"`
+	ZhCN    string `json:"zh_CN"`
+	EnUS    string `json:"en_US"`
+}
+
+type Readme struct {
+	Default string `json:"default"`
+	ZhCN    string `json:"zh_CN"`
+	EnUS    string `json:"en_US"`
+}
+
 type Funding struct {
 type Funding struct {
 	OpenCollective string   `json:"openCollective"`
 	OpenCollective string   `json:"openCollective"`
 	Patreon        string   `json:"patreon"`
 	Patreon        string   `json:"patreon"`
@@ -46,10 +58,15 @@ type Funding struct {
 }
 }
 
 
 type Package struct {
 type Package struct {
-	Author  string   `json:"author"`
-	URL     string   `json:"url"`
-	Version string   `json:"version"`
-	Funding *Funding `json:"funding"`
+	Author      string       `json:"author"`
+	URL         string       `json:"url"`
+	Version     string       `json:"version"`
+	Description *Description `json:"description"`
+	Readme      *Readme      `json:"readme"`
+	Funding     *Funding     `json:"funding"`
+
+	PreferredFunding string `json:"preferredFunding"`
+	PreferredDesc    string `json:"preferredDesc"`
 
 
 	Name            string `json:"name"`
 	Name            string `json:"name"`
 	RepoURL         string `json:"repoURL"`
 	RepoURL         string `json:"repoURL"`
@@ -75,16 +92,42 @@ type Package struct {
 	Downloads    int    `json:"downloads"`
 	Downloads    int    `json:"downloads"`
 }
 }
 
 
-func parseFunding(conf map[string]interface{}) (ret *Funding) {
+func parseFunding(pkg map[string]interface{}) (ret *Funding) {
+	if nil == pkg["funding"] {
+		return
+	}
+
 	ret = &Funding{}
 	ret = &Funding{}
-	funding := conf["funding"].(map[string]interface{})
+	funding := pkg["funding"].(map[string]interface{})
 	ret.OpenCollective = funding["openCollective"].(string)
 	ret.OpenCollective = funding["openCollective"].(string)
 	ret.Patreon = funding["patreon"].(string)
 	ret.Patreon = funding["patreon"].(string)
 	ret.GitHub = funding["github"].(string)
 	ret.GitHub = funding["github"].(string)
-	ret.Custom = funding["custom"].([]string)
+
+	customURLs := funding["custom"].([]interface{})
+	var custom []string
+	for _, customURL := range customURLs {
+		custom = append(custom, customURL.(string))
+	}
+	ret.Custom = custom
 	return
 	return
 }
 }
 
 
+func getPreferredFunding(funding *Funding) string {
+	if "" != funding.OpenCollective {
+		return funding.OpenCollective
+	}
+	if "" != funding.Patreon {
+		return funding.Patreon
+	}
+	if "" != funding.GitHub {
+		return funding.GitHub
+	}
+	if 0 < len(funding.Custom) {
+		return funding.Custom[0]
+	}
+	return ""
+}
+
 func PluginJSON(pluginDirName string) (ret map[string]interface{}, err error) {
 func PluginJSON(pluginDirName string) (ret map[string]interface{}, err error) {
 	p := filepath.Join(util.DataDir, "plugins", pluginDirName, "plugin.json")
 	p := filepath.Join(util.DataDir, "plugins", pluginDirName, "plugin.json")
 	if !gulu.File.IsExist(p) {
 	if !gulu.File.IsExist(p) {

+ 4 - 1
kernel/bazaar/plugin.go

@@ -54,7 +54,7 @@ func Plugins() (plugins []*Plugin) {
 		repo := arg.(map[string]interface{})
 		repo := arg.(map[string]interface{})
 		repoURL := repo["url"].(string)
 		repoURL := repo["url"].(string)
 
 
-		plugin := &Plugin{}
+		plugin := &Plugin{Package{Funding: &Funding{}, Description: &Description{}}}
 		innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
 		innerU := util.BazaarOSSServer + "/package/" + repoURL + "/plugin.json"
 		innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
 		innerResp, innerErr := httpclient.NewBrowserRequest().SetSuccessResult(plugin).Get(innerU)
 		if nil != innerErr {
 		if nil != innerErr {
@@ -73,6 +73,8 @@ func Plugins() (plugins []*Plugin) {
 		plugin.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		plugin.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		plugin.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		plugin.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		plugin.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
 		plugin.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
+		plugin.Funding = parseFunding(repo["package"].(map[string]interface{}))
+		plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
 		plugin.Updated = repo["updated"].(string)
 		plugin.Updated = repo["updated"].(string)
 		plugin.Stars = int(repo["stars"].(float64))
 		plugin.Stars = int(repo["stars"].(float64))
 		plugin.OpenIssues = int(repo["openIssues"].(float64))
 		plugin.OpenIssues = int(repo["openIssues"].(float64))
@@ -139,6 +141,7 @@ func InstalledPlugins() (ret []*Plugin) {
 		plugin.PreviewURLThumb = "/plugins/" + dirName + "/preview.png"
 		plugin.PreviewURLThumb = "/plugins/" + dirName + "/preview.png"
 		plugin.IconURL = "/plugins/" + dirName + "/icon.png"
 		plugin.IconURL = "/plugins/" + dirName + "/icon.png"
 		plugin.Funding = parseFunding(pluginConf)
 		plugin.Funding = parseFunding(pluginConf)
+		plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		if nil != statErr {
 		if nil != statErr {
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)

+ 3 - 0
kernel/bazaar/template.go

@@ -73,6 +73,8 @@ func Templates() (templates []*Template) {
 		template.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		template.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		template.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		template.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		template.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
 		template.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
+		template.Funding = parseFunding(repo["package"].(map[string]interface{}))
+		template.PreferredFunding = getPreferredFunding(template.Funding)
 		template.Updated = repo["updated"].(string)
 		template.Updated = repo["updated"].(string)
 		template.Stars = int(repo["stars"].(float64))
 		template.Stars = int(repo["stars"].(float64))
 		template.OpenIssues = int(repo["openIssues"].(float64))
 		template.OpenIssues = int(repo["openIssues"].(float64))
@@ -141,6 +143,7 @@ func InstalledTemplates() (ret []*Template) {
 		template.PreviewURLThumb = "/templates/" + dirName + "/preview.png"
 		template.PreviewURLThumb = "/templates/" + dirName + "/preview.png"
 		template.IconURL = "/templates/" + dirName + "/icon.png"
 		template.IconURL = "/templates/" + dirName + "/icon.png"
 		template.Funding = parseFunding(templateConf)
 		template.Funding = parseFunding(templateConf)
+		template.PreferredFunding = getPreferredFunding(template.Funding)
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		if nil != statErr {
 		if nil != statErr {
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)

+ 3 - 0
kernel/bazaar/theme.go

@@ -74,6 +74,8 @@ func Themes() (ret []*Theme) {
 		theme.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		theme.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		theme.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		theme.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		theme.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
 		theme.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
+		theme.Funding = parseFunding(repo["package"].(map[string]interface{}))
+		theme.PreferredFunding = getPreferredFunding(theme.Funding)
 		theme.Updated = repo["updated"].(string)
 		theme.Updated = repo["updated"].(string)
 		theme.Stars = int(repo["stars"].(float64))
 		theme.Stars = int(repo["stars"].(float64))
 		theme.OpenIssues = int(repo["openIssues"].(float64))
 		theme.OpenIssues = int(repo["openIssues"].(float64))
@@ -145,6 +147,7 @@ func InstalledThemes() (ret []*Theme) {
 		theme.PreviewURLThumb = "/appearance/themes/" + dirName + "/preview.png"
 		theme.PreviewURLThumb = "/appearance/themes/" + dirName + "/preview.png"
 		theme.IconURL = "/appearance/themes/" + dirName + "/icon.png"
 		theme.IconURL = "/appearance/themes/" + dirName + "/icon.png"
 		theme.Funding = parseFunding(themeConf)
 		theme.Funding = parseFunding(themeConf)
+		theme.PreferredFunding = getPreferredFunding(theme.Funding)
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		if nil != statErr {
 		if nil != statErr {
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)

+ 3 - 0
kernel/bazaar/widget.go

@@ -73,6 +73,8 @@ func Widgets() (widgets []*Widget) {
 		widget.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		widget.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
 		widget.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		widget.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
 		widget.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
 		widget.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
+		widget.Funding = parseFunding(repo["package"].(map[string]interface{}))
+		widget.PreferredFunding = getPreferredFunding(widget.Funding)
 		widget.Updated = repo["updated"].(string)
 		widget.Updated = repo["updated"].(string)
 		widget.Stars = int(repo["stars"].(float64))
 		widget.Stars = int(repo["stars"].(float64))
 		widget.OpenIssues = int(repo["openIssues"].(float64))
 		widget.OpenIssues = int(repo["openIssues"].(float64))
@@ -139,6 +141,7 @@ func InstalledWidgets() (ret []*Widget) {
 		widget.PreviewURLThumb = "/widgets/" + dirName + "/preview.png"
 		widget.PreviewURLThumb = "/widgets/" + dirName + "/preview.png"
 		widget.IconURL = "/widgets/" + dirName + "/icon.png"
 		widget.IconURL = "/widgets/" + dirName + "/icon.png"
 		widget.Funding = parseFunding(widgetConf)
 		widget.Funding = parseFunding(widgetConf)
+		widget.PreferredFunding = getPreferredFunding(widget.Funding)
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
 		if nil != statErr {
 		if nil != statErr {
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)
 			logging.LogWarnf("stat install theme README.md failed: %s", statErr)