mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-27 18:56:09 +01:00
🎨 集市支持已安装的包单独显示 https://github.com/siyuan-note/siyuan/issues/5678
This commit is contained in:
parent
29021c8d02
commit
74b73d02bc
5 changed files with 59 additions and 68 deletions
|
|
@ -57,26 +57,13 @@ type Icon struct {
|
|||
|
||||
func Icons() (icons []*Icon) {
|
||||
icons = []*Icon{}
|
||||
result, err := util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
bazaarIndex := getBazaarIndex()
|
||||
bazaarHash := result["bazaar"].(string)
|
||||
result = map[string]interface{}{}
|
||||
request := httpclient.NewBrowserRequest()
|
||||
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/icons.json"
|
||||
resp, err := request.SetResult(&result).Get(u)
|
||||
pkgIndex, err := getPkgIndex("icons")
|
||||
if nil != err {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
|
||||
return
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
|
||||
return
|
||||
}
|
||||
repos := result["repos"].([]interface{})
|
||||
bazaarIndex := getBazaarIndex()
|
||||
repos := pkgIndex["repos"].([]interface{})
|
||||
waitGroup := &sync.WaitGroup{}
|
||||
lock := &sync.Mutex{}
|
||||
p, _ := ants.NewPoolWithFunc(2, func(arg interface{}) {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,46 @@ func ThemeJSON(themeDirName string) (ret map[string]interface{}, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func getPkgIndex(pkgType string) (ret map[string]interface{}, err error) {
|
||||
ret, err = util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
bazaarHash := ret["bazaar"].(string)
|
||||
ret = map[string]interface{}{}
|
||||
request := httpclient.NewBrowserRequest()
|
||||
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/" + pkgType + ".json"
|
||||
resp, reqErr := request.SetResult(&ret).Get(u)
|
||||
if nil != reqErr {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
|
||||
return
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func isOutdatedPkg(fullURL, version string, pkgIndex map[string]interface{}) bool {
|
||||
if !strings.HasPrefix(fullURL, "https://github.com/") {
|
||||
return false
|
||||
}
|
||||
|
||||
url := strings.TrimPrefix(fullURL, "https://github.com/")
|
||||
repos := pkgIndex["repos"].([]interface{})
|
||||
for _, repo := range repos {
|
||||
r := repo.(map[string]interface{})
|
||||
repoURL := r["url"].(string)
|
||||
repoVer := r["version"].(string)
|
||||
if url == repoURL && version != repoVer {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetPackageREADME(repoURL, repoHash string, systemID string) (ret string) {
|
||||
repoURLHash := repoURL + "@" + repoHash
|
||||
data, err := downloadPackage(repoURLHash+"/README.md", false, systemID)
|
||||
|
|
|
|||
|
|
@ -59,27 +59,13 @@ type Template struct {
|
|||
|
||||
func Templates() (templates []*Template) {
|
||||
templates = []*Template{}
|
||||
result, err := util.GetRhyResult(false)
|
||||
|
||||
pkgIndex, err := getPkgIndex("templates")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
bazaarIndex := getBazaarIndex()
|
||||
bazaarHash := result["bazaar"].(string)
|
||||
result = map[string]interface{}{}
|
||||
request := httpclient.NewBrowserRequest()
|
||||
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/templates.json"
|
||||
resp, reqErr := request.SetResult(&result).Get(u)
|
||||
if nil != reqErr {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
|
||||
return
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
repos := result["repos"].([]interface{})
|
||||
repos := pkgIndex["repos"].([]interface{})
|
||||
waitGroup := &sync.WaitGroup{}
|
||||
lock := &sync.Mutex{}
|
||||
p, _ := ants.NewPoolWithFunc(2, func(arg interface{}) {
|
||||
|
|
|
|||
|
|
@ -60,27 +60,13 @@ type Theme struct {
|
|||
|
||||
func Themes() (ret []*Theme) {
|
||||
ret = []*Theme{}
|
||||
result, err := util.GetRhyResult(false)
|
||||
|
||||
pkgIndex, err := getPkgIndex("themes")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
bazaarIndex := getBazaarIndex()
|
||||
bazaarHash := result["bazaar"].(string)
|
||||
result = map[string]interface{}{}
|
||||
request := httpclient.NewBrowserRequest()
|
||||
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/themes.json"
|
||||
resp, reqErr := request.SetResult(&result).Get(u)
|
||||
if nil != reqErr {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
|
||||
return
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
repos := result["repos"].([]interface{})
|
||||
repos := pkgIndex["repos"].([]interface{})
|
||||
waitGroup := &sync.WaitGroup{}
|
||||
lock := &sync.Mutex{}
|
||||
p, _ := ants.NewPoolWithFunc(8, func(arg interface{}) {
|
||||
|
|
@ -97,7 +83,7 @@ func Themes() (ret []*Theme) {
|
|||
return
|
||||
}
|
||||
if 200 != innerResp.StatusCode {
|
||||
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, resp.StatusCode)
|
||||
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +130,11 @@ func InstalledThemes() (ret []*Theme) {
|
|||
}
|
||||
dir.Close()
|
||||
|
||||
pkgIndex, err := getPkgIndex("themes")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, themeDir := range themeDirs {
|
||||
if !themeDir.IsDir() {
|
||||
continue
|
||||
|
|
@ -177,7 +168,7 @@ func InstalledThemes() (ret []*Theme) {
|
|||
continue
|
||||
}
|
||||
theme.README = gulu.Str.FromBytes(readme)
|
||||
|
||||
theme.Outdated = isOutdatedPkg(theme.URL, theme.Version, pkgIndex)
|
||||
ret = append(ret, theme)
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -57,27 +57,14 @@ type Widget struct {
|
|||
|
||||
func Widgets() (widgets []*Widget) {
|
||||
widgets = []*Widget{}
|
||||
result, err := util.GetRhyResult(false)
|
||||
|
||||
pkgIndex, err := getPkgIndex("widgets")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
bazaarIndex := getBazaarIndex()
|
||||
bazaarHash := result["bazaar"].(string)
|
||||
result = map[string]interface{}{}
|
||||
request := httpclient.NewBrowserRequest()
|
||||
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/widgets.json"
|
||||
resp, err := request.SetResult(&result).Get(u)
|
||||
if nil != err {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
|
||||
return
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
repos := result["repos"].([]interface{})
|
||||
repos := pkgIndex["repos"].([]interface{})
|
||||
waitGroup := &sync.WaitGroup{}
|
||||
lock := &sync.Mutex{}
|
||||
p, _ := ants.NewPoolWithFunc(8, func(arg interface{}) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue