From 7379ff1e278cabd4b11d148df7f9a0c22acd96b5 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 24 May 2023 10:34:15 +0800 Subject: [PATCH 1/3] :art: Add marketplace package config item `minAppVersion` https://github.com/siyuan-note/siyuan/issues/8330 --- kernel/bazaar/icon.go | 10 +++++++++- kernel/bazaar/package.go | 20 ++++++++++++-------- kernel/bazaar/plugin.go | 10 +++++++++- kernel/bazaar/template.go | 10 +++++++++- kernel/bazaar/theme.go | 10 +++++++++- kernel/bazaar/widget.go | 10 +++++++++- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go index 88cf3d198..07115ed8e 100644 --- a/kernel/bazaar/icon.go +++ b/kernel/bazaar/icon.go @@ -29,6 +29,7 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" + "golang.org/x/mod/semver" ) type Icon struct { @@ -62,8 +63,15 @@ func Icons() (icons []*Icon) { logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode) return } - icon.URL = strings.TrimSuffix(icon.URL, "/") + if "" == icon.MinAppVersion { + icon.MinAppVersion = defaultMinAppVersion + } + if 0 < semver.Compare("v"+icon.MinAppVersion, "v"+util.Ver) { + return + } + + icon.URL = strings.TrimSuffix(icon.URL, "/") repoURLHash := strings.Split(repoURL, "@") icon.RepoURL = "https://github.com/" + repoURLHash[0] icon.RepoHash = repoURLHash[1] diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index 44f5a10cf..ed00d6a64 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -64,14 +64,14 @@ type Funding struct { } type Package struct { - Author string `json:"author"` - URL string `json:"url"` - Version string `json:"version"` - DisplayName *DisplayName `json:"displayName"` - Description *Description `json:"description"` - Readme *Readme `json:"readme"` - Funding *Funding `json:"funding"` - I18N []string `json:"i18n"` + Author string `json:"author"` + URL string `json:"url"` + Version string `json:"version"` + MinAppVersion string `json:"minAppVersion"` + DisplayName *DisplayName `json:"displayName"` + Description *Description `json:"description"` + Readme *Readme `json:"readme"` + Funding *Funding `json:"funding"` PreferredFunding string `json:"preferredFunding"` PreferredName string `json:"preferredName"` @@ -649,3 +649,7 @@ func getBazaarIndex() map[string]*bazaarPackage { bazaarIndexCacheTime = now return cachedBazaarIndex } + +// defaultMinAppVersion 如果集市包中缺失 minAppVersion 项,则使用该值作为最低支持的版本号,小于该版本号时不显示集市包 +// Add marketplace package config item `minAppVersion` https://github.com/siyuan-note/siyuan/issues/8330 +const defaultMinAppVersion = "2.9.0" diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go index b80ee6d26..61a82d71f 100644 --- a/kernel/bazaar/plugin.go +++ b/kernel/bazaar/plugin.go @@ -29,6 +29,7 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" + "golang.org/x/mod/semver" ) type Plugin struct { @@ -64,8 +65,15 @@ func Plugins() (plugins []*Plugin) { logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode) return } - plugin.URL = strings.TrimSuffix(plugin.URL, "/") + if "" == plugin.MinAppVersion { + plugin.MinAppVersion = defaultMinAppVersion + } + if 0 < semver.Compare("v"+plugin.MinAppVersion, "v"+util.Ver) { + return + } + + plugin.URL = strings.TrimSuffix(plugin.URL, "/") repoURLHash := strings.Split(repoURL, "@") plugin.RepoURL = "https://github.com/" + repoURLHash[0] plugin.RepoHash = repoURLHash[1] diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go index 17eb4c02d..420d659bf 100644 --- a/kernel/bazaar/template.go +++ b/kernel/bazaar/template.go @@ -30,6 +30,7 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" + "golang.org/x/mod/semver" ) type Template struct { @@ -63,8 +64,15 @@ func Templates() (templates []*Template) { logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode) return } - template.URL = strings.TrimSuffix(template.URL, "/") + if "" == template.MinAppVersion { + template.MinAppVersion = defaultMinAppVersion + } + if 0 < semver.Compare("v"+template.MinAppVersion, "v"+util.Ver) { + return + } + + template.URL = strings.TrimSuffix(template.URL, "/") repoURLHash := strings.Split(repoURL, "@") template.RepoURL = "https://github.com/" + repoURLHash[0] template.RepoHash = repoURLHash[1] diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go index 93635b5ad..c1768cbcb 100644 --- a/kernel/bazaar/theme.go +++ b/kernel/bazaar/theme.go @@ -29,6 +29,7 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" + "golang.org/x/mod/semver" ) type Theme struct { @@ -64,8 +65,15 @@ func Themes() (ret []*Theme) { logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode) return } - theme.URL = strings.TrimSuffix(theme.URL, "/") + if "" == theme.MinAppVersion { + theme.MinAppVersion = defaultMinAppVersion + } + if 0 < semver.Compare("v"+theme.MinAppVersion, "v"+util.Ver) { + return + } + + theme.URL = strings.TrimSuffix(theme.URL, "/") repoURLHash := strings.Split(repoURL, "@") theme.RepoURL = "https://github.com/" + repoURLHash[0] theme.RepoHash = repoURLHash[1] diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go index b78586ccd..e56ff030b 100644 --- a/kernel/bazaar/widget.go +++ b/kernel/bazaar/widget.go @@ -29,6 +29,7 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" + "golang.org/x/mod/semver" ) type Widget struct { @@ -63,8 +64,15 @@ func Widgets() (widgets []*Widget) { logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode) return } - widget.URL = strings.TrimSuffix(widget.URL, "/") + if "" == widget.MinAppVersion { + widget.MinAppVersion = defaultMinAppVersion + } + if 0 < semver.Compare("v"+widget.MinAppVersion, "v"+util.Ver) { + return + } + + widget.URL = strings.TrimSuffix(widget.URL, "/") repoURLHash := strings.Split(repoURL, "@") widget.RepoURL = "https://github.com/" + repoURLHash[0] widget.RepoHash = repoURLHash[1] From 8cbe54c2aba2caaada93a8fcb6282e9934b12040 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 24 May 2023 10:38:30 +0800 Subject: [PATCH 2/3] :art: Add marketplace package config item `minAppVersion` https://github.com/siyuan-note/siyuan/issues/8330 --- kernel/bazaar/icon.go | 6 +----- kernel/bazaar/package.go | 8 ++++++++ kernel/bazaar/plugin.go | 6 +----- kernel/bazaar/template.go | 6 +----- kernel/bazaar/theme.go | 6 +----- kernel/bazaar/widget.go | 6 +----- 6 files changed, 13 insertions(+), 25 deletions(-) diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go index 07115ed8e..d065598c4 100644 --- a/kernel/bazaar/icon.go +++ b/kernel/bazaar/icon.go @@ -29,7 +29,6 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" - "golang.org/x/mod/semver" ) type Icon struct { @@ -64,10 +63,7 @@ func Icons() (icons []*Icon) { return } - if "" == icon.MinAppVersion { - icon.MinAppVersion = defaultMinAppVersion - } - if 0 < semver.Compare("v"+icon.MinAppVersion, "v"+util.Ver) { + if disallowDisplayBazaarPackage(icon.MinAppVersion) { return } diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index ed00d6a64..037b8a053 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -19,6 +19,7 @@ package bazaar import ( "bytes" "errors" + "golang.org/x/mod/semver" "os" "path/filepath" "strings" @@ -653,3 +654,10 @@ func getBazaarIndex() map[string]*bazaarPackage { // defaultMinAppVersion 如果集市包中缺失 minAppVersion 项,则使用该值作为最低支持的版本号,小于该版本号时不显示集市包 // Add marketplace package config item `minAppVersion` https://github.com/siyuan-note/siyuan/issues/8330 const defaultMinAppVersion = "2.9.0" + +func disallowDisplayBazaarPackage(minAppVersion string) bool { + if "" == minAppVersion { + return false + } + return 0 > semver.Compare("v"+minAppVersion, "v"+util.Ver) +} diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go index 61a82d71f..c5b982647 100644 --- a/kernel/bazaar/plugin.go +++ b/kernel/bazaar/plugin.go @@ -29,7 +29,6 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" - "golang.org/x/mod/semver" ) type Plugin struct { @@ -66,10 +65,7 @@ func Plugins() (plugins []*Plugin) { return } - if "" == plugin.MinAppVersion { - plugin.MinAppVersion = defaultMinAppVersion - } - if 0 < semver.Compare("v"+plugin.MinAppVersion, "v"+util.Ver) { + if disallowDisplayBazaarPackage(plugin.MinAppVersion) { return } diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go index 420d659bf..211f0f602 100644 --- a/kernel/bazaar/template.go +++ b/kernel/bazaar/template.go @@ -30,7 +30,6 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" - "golang.org/x/mod/semver" ) type Template struct { @@ -65,10 +64,7 @@ func Templates() (templates []*Template) { return } - if "" == template.MinAppVersion { - template.MinAppVersion = defaultMinAppVersion - } - if 0 < semver.Compare("v"+template.MinAppVersion, "v"+util.Ver) { + if disallowDisplayBazaarPackage(template.MinAppVersion) { return } diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go index c1768cbcb..8ef724e88 100644 --- a/kernel/bazaar/theme.go +++ b/kernel/bazaar/theme.go @@ -29,7 +29,6 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" - "golang.org/x/mod/semver" ) type Theme struct { @@ -66,10 +65,7 @@ func Themes() (ret []*Theme) { return } - if "" == theme.MinAppVersion { - theme.MinAppVersion = defaultMinAppVersion - } - if 0 < semver.Compare("v"+theme.MinAppVersion, "v"+util.Ver) { + if disallowDisplayBazaarPackage(theme.MinAppVersion) { return } diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go index e56ff030b..c3a7f61da 100644 --- a/kernel/bazaar/widget.go +++ b/kernel/bazaar/widget.go @@ -29,7 +29,6 @@ import ( "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" - "golang.org/x/mod/semver" ) type Widget struct { @@ -65,10 +64,7 @@ func Widgets() (widgets []*Widget) { return } - if "" == widget.MinAppVersion { - widget.MinAppVersion = defaultMinAppVersion - } - if 0 < semver.Compare("v"+widget.MinAppVersion, "v"+util.Ver) { + if disallowDisplayBazaarPackage(widget.MinAppVersion) { return } From d40291fcb8d1f6aa981485d02af3a0810f5d34b4 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 24 May 2023 10:41:06 +0800 Subject: [PATCH 3/3] :art: Add marketplace package config item `minAppVersion` https://github.com/siyuan-note/siyuan/issues/8330 --- kernel/bazaar/package.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index 037b8a053..e416f1d84 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -656,7 +656,7 @@ func getBazaarIndex() map[string]*bazaarPackage { const defaultMinAppVersion = "2.9.0" func disallowDisplayBazaarPackage(minAppVersion string) bool { - if "" == minAppVersion { + if "" == minAppVersion { // 目前暂时放过所有不带 minAppVersion 的集市包,后续版本会使用 defaultMinAppVersion return false } return 0 > semver.Compare("v"+minAppVersion, "v"+util.Ver)