This commit is contained in:
Liang Ding 2022-07-17 12:22:32 +08:00
parent c8ea858976
commit 505b973c2d
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
70 changed files with 671 additions and 942 deletions

View file

@ -26,6 +26,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -68,11 +69,11 @@ func Icons() (icons []*Icon) {
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/icons.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
util.LogErrorf("get community stage index [%s] failed: %s", u, err)
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
return
}
if 200 != resp.StatusCode {
util.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
repos := result["repos"].([]interface{})
@ -88,11 +89,11 @@ func Icons() (icons []*Icon) {
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(icon).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
logging.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return
}
if 200 != innerResp.StatusCode {
util.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
return
}
@ -137,9 +138,9 @@ func InstallIcon(repoURL, repoHash, installPath string, chinaCDN bool, systemID
func UninstallIcon(installPath string) error {
if err := os.RemoveAll(installPath); nil != err {
util.LogErrorf("remove icon [%s] failed: %s", installPath, err)
logging.LogErrorf("remove icon [%s] failed: %s", installPath, err)
return errors.New("remove community icon failed")
}
//util.Logger.Infof("uninstalled icon [%s]", installPath)
//logging.Logger.Infof("uninstalled icon [%s]", installPath)
return nil
}

View file

@ -31,6 +31,7 @@ import (
"github.com/araddon/dateparse"
"github.com/imroc/req/v3"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
textUnicode "golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
@ -60,7 +61,7 @@ func GetPackageREADME(repoURL, repoHash string, chinaCDN bool, systemID string)
ret = luteEngine.Md2HTML(string(data))
doc, err := goquery.NewDocumentFromReader(strings.NewReader(ret))
if nil != err {
util.LogErrorf("parse HTML failed: %s", err)
logging.LogErrorf("parse HTML failed: %s", err)
return ret
}
@ -96,12 +97,12 @@ func downloadPackage(repoURLHash string, chinaCDN, pushProgress bool, systemID s
}
}).Get(u)
if nil != err {
util.LogErrorf("get bazaar package [%s] failed: %s", u, err)
logging.LogErrorf("get bazaar package [%s] failed: %s", u, err)
return nil, errors.New("get bazaar package failed")
}
}
if 200 != resp.StatusCode {
util.LogErrorf("get bazaar package [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", u, resp.StatusCode)
return nil, errors.New("get bazaar package failed")
}
data = buf.Bytes()
@ -137,7 +138,7 @@ func installPackage(data []byte, installPath string) (err error) {
unzipPath := filepath.Join(dir, name)
if err = gulu.Zip.Unzip(tmp, unzipPath); nil != err {
util.LogErrorf("write file [%s] failed: %s", installPath, err)
logging.LogErrorf("write file [%s] failed: %s", installPath, err)
err = errors.New("write file failed")
return
}
@ -195,11 +196,11 @@ func getBazaarIndex() map[string]*bazaarPackage {
u := util.BazaarStatServer + "/bazaar/index.json"
resp, reqErr := request.SetResult(&cachedBazaarIndex).Get(u)
if nil != reqErr {
util.LogErrorf("get bazaar index [%s] failed: %s", u, reqErr)
logging.LogErrorf("get bazaar index [%s] failed: %s", u, reqErr)
return cachedBazaarIndex
}
if 200 != resp.StatusCode {
util.LogErrorf("get bazaar index [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get bazaar index [%s] failed: %d", u, resp.StatusCode)
return cachedBazaarIndex
}
bazaarIndexCacheTime = now

View file

@ -27,6 +27,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -68,11 +69,11 @@ func Templates() (templates []*Template) {
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/templates.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
util.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
return
}
if 200 != resp.StatusCode {
util.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
@ -89,11 +90,11 @@ func Templates() (templates []*Template) {
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(template).Get(innerU)
if nil != innerErr {
util.LogErrorf("get community template [%s] failed: %s", repoURL, innerErr)
logging.LogErrorf("get community template [%s] failed: %s", repoURL, innerErr)
return
}
if 200 != innerResp.StatusCode {
util.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
return
}
@ -140,7 +141,7 @@ func InstallTemplate(repoURL, repoHash, installPath string, chinaCDN bool, syste
func UninstallTemplate(installPath string) error {
if err := os.RemoveAll(installPath); nil != err {
util.LogErrorf("remove template [%s] failed: %s", installPath, err)
logging.LogErrorf("remove template [%s] failed: %s", installPath, err)
return errors.New("remove community template failed")
}
return nil
@ -153,7 +154,7 @@ func filterLegacyTemplates(templates []*Template) (ret []*Template) {
updated := theme.Updated[:len("2006-01-02T15:04:05")]
t, err := time.Parse("2006-01-02T15:04:05", updated)
if nil != err {
util.LogErrorf("convert update time [%s] failed: %s", updated, err)
logging.LogErrorf("convert update time [%s] failed: %s", updated, err)
continue
}
if t.After(verTime) {

View file

@ -26,6 +26,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -69,11 +70,11 @@ func Themes() (ret []*Theme) {
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/themes.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
util.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
return
}
if 200 != resp.StatusCode {
util.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
@ -90,11 +91,11 @@ func Themes() (ret []*Theme) {
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(theme).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", innerU, innerErr)
logging.LogErrorf("get bazaar package [%s] failed: %s", innerU, innerErr)
return
}
if 200 != innerResp.StatusCode {
util.LogErrorf("get bazaar package [%s] failed: %d", innerU, resp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, resp.StatusCode)
return
}
@ -139,9 +140,9 @@ func InstallTheme(repoURL, repoHash, installPath string, chinaCDN bool, systemID
func UninstallTheme(installPath string) error {
if err := os.RemoveAll(installPath); nil != err {
util.LogErrorf("remove theme [%s] failed: %s", installPath, err)
logging.LogErrorf("remove theme [%s] failed: %s", installPath, err)
return errors.New("remove community theme failed")
}
//util.Logger.Infof("uninstalled theme [%s]", installPath)
//logging.Logger.Infof("uninstalled theme [%s]", installPath)
return nil
}

View file

@ -26,6 +26,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -68,11 +69,11 @@ func Widgets() (widgets []*Widget) {
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/widgets.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
util.LogErrorf("get community stage index [%s] failed: %s", u, err)
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
return
}
if 200 != resp.StatusCode {
util.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
@ -89,11 +90,11 @@ func Widgets() (widgets []*Widget) {
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(widget).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
logging.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return
}
if 200 != innerResp.StatusCode {
util.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
return
}
@ -138,9 +139,9 @@ func InstallWidget(repoURL, repoHash, installPath string, chinaCDN bool, systemI
func UninstallWidget(installPath string) error {
if err := os.RemoveAll(installPath); nil != err {
util.LogErrorf("remove widget [%s] failed: %s", installPath, err)
logging.LogErrorf("remove widget [%s] failed: %s", installPath, err)
return errors.New("remove community widget failed")
}
//util.Logger.Infof("uninstalled widget [%s]", installPath)
//logging.Logger.Infof("uninstalled widget [%s]", installPath)
return nil
}