Ver código fonte

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 1 ano atrás
pai
commit
c6319c3a0e
3 arquivos alterados com 54 adições e 0 exclusões
  1. 20 0
      kernel/api/bazaar.go
  2. 1 0
      kernel/api/router.go
  3. 33 0
      kernel/model/bazzar.go

+ 20 - 0
kernel/api/bazaar.go

@@ -25,6 +25,26 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
+func getBazaarPackages(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	frontend := arg["frontend"].(string)
+	plugins, widgets, icons, themes, templates := model.BazaarPackages(frontend)
+	ret.Data = map[string]interface{}{
+		"plugins":   plugins,
+		"widgets":   widgets,
+		"icons":     icons,
+		"themes":    themes,
+		"templates": templates,
+	}
+}
+
 func getBazaarPackageREAME(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 0
kernel/api/router.go

@@ -330,6 +330,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/graph/getGraph", model.CheckAuth, getGraph)
 	ginServer.Handle("POST", "/api/graph/getLocalGraph", model.CheckAuth, getLocalGraph)
 
+	ginServer.Handle("POST", "/api/bazaar/getBazaarPackages", model.CheckAuth, getBazaarPackages)
 	ginServer.Handle("POST", "/api/bazaar/getBazaarPlugin", model.CheckAuth, getBazaarPlugin)
 	ginServer.Handle("POST", "/api/bazaar/getInstalledPlugin", model.CheckAuth, getInstalledPlugin)
 	ginServer.Handle("POST", "/api/bazaar/installBazaarPlugin", model.CheckAuth, model.CheckReadonly, installBazaarPlugin)

+ 33 - 0
kernel/model/bazzar.go

@@ -22,6 +22,7 @@ import (
 	"path"
 	"path/filepath"
 	"strings"
+	"sync"
 
 	"github.com/88250/gulu"
 	"github.com/siyuan-note/siyuan/kernel/util"
@@ -29,6 +30,38 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/bazaar"
 )
 
+func BazaarPackages(frontend string) (plugins []*bazaar.Plugin, widgets []*bazaar.Widget, icons []*bazaar.Icon, themes []*bazaar.Theme, templates []*bazaar.Template) {
+	wg := &sync.WaitGroup{}
+	wg.Add(5)
+	go func() {
+		defer wg.Done()
+		plugins = InstalledPlugins(frontend, "")
+	}()
+
+	go func() {
+		defer wg.Done()
+		widgets = InstalledWidgets("")
+	}()
+
+	go func() {
+		defer wg.Done()
+		icons = InstalledIcons("")
+	}()
+
+	go func() {
+		defer wg.Done()
+		themes = InstalledThemes("")
+	}()
+
+	go func() {
+		defer wg.Done()
+		templates = InstalledTemplates("")
+	}()
+
+	wg.Wait()
+	return
+}
+
 func GetPackageREADME(repoURL, repoHash, packageType string) (ret string) {
 	ret = bazaar.GetPackageREADME(repoURL, repoHash, packageType)
 	return