This commit is contained in:
Liang Ding 2022-07-09 11:22:51 +08:00
parent 2880222bc6
commit 70b8a7d8eb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
16 changed files with 89 additions and 93 deletions

View file

@ -54,17 +54,17 @@ type Icon struct {
Downloads int `json:"downloads"`
}
func Icons(proxyURL string) (icons []*Icon) {
func Icons() (icons []*Icon) {
icons = []*Icon{}
result, err := util.GetRhyResult(false, proxyURL)
result, err := util.GetRhyResult(false)
if nil != err {
return
}
bazaarIndex := getBazaarIndex(proxyURL)
bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/icons.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
@ -86,7 +86,7 @@ func Icons(proxyURL string) (icons []*Icon) {
icon := &Icon{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(icon).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(icon).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return
@ -126,9 +126,9 @@ func Icons(proxyURL string) (icons []*Icon) {
return
}
func InstallIcon(repoURL, repoHash, installPath, proxyURL string, chinaCDN bool, systemID string) error {
func InstallIcon(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash, proxyURL, chinaCDN, true, systemID)
data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
if nil != err {
return err
}

View file

@ -36,9 +36,9 @@ import (
"golang.org/x/text/transform"
)
func GetPackageREADME(repoURL, repoHash, proxyURL string, chinaCDN bool, systemID string) (ret string) {
func GetPackageREADME(repoURL, repoHash string, chinaCDN bool, systemID string) (ret string) {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash+"/README.md", proxyURL, chinaCDN, false, systemID)
data, err := downloadPackage(repoURLHash+"/README.md", chinaCDN, false, systemID)
if nil != err {
ret = "Load bazaar package's README.md failed: " + err.Error()
return
@ -74,7 +74,7 @@ func GetPackageREADME(repoURL, repoHash, proxyURL string, chinaCDN bool, systemI
return
}
func downloadPackage(repoURLHash, proxyURL string, chinaCDN, pushProgress bool, systemID string) (data []byte, err error) {
func downloadPackage(repoURLHash string, chinaCDN, pushProgress bool, systemID string) (data []byte, err error) {
// repoURLHash: https://github.com/88250/Comfortably-Numb@6286912c381ef3f83e455d06ba4d369c498238dc
pushID := repoURLHash[:strings.LastIndex(repoURLHash, "@")]
repoURLHash = strings.TrimPrefix(repoURLHash, "https://github.com/")
@ -83,14 +83,14 @@ func downloadPackage(repoURLHash, proxyURL string, chinaCDN, pushProgress bool,
u = util.BazaarOSSServer + "/package/" + repoURLHash
}
buf := &bytes.Buffer{}
resp, err := httpclient.NewBrowserDownloadRequest(proxyURL).SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
resp, err := httpclient.NewBrowserDownloadRequest().SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
if pushProgress {
util.PushDownloadProgress(pushID, float32(info.DownloadedSize)/float32(info.Response.ContentLength))
}
}).Get(u)
if nil != err {
u = util.BazaarOSSServer + "/package/" + repoURLHash
resp, err = httpclient.NewBrowserDownloadRequest(proxyURL).SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
resp, err = httpclient.NewBrowserDownloadRequest().SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
if pushProgress {
util.PushDownloadProgress(pushID, float32(info.DownloadedSize)/float32(info.Response.ContentLength))
}
@ -106,18 +106,18 @@ func downloadPackage(repoURLHash, proxyURL string, chinaCDN, pushProgress bool,
}
data = buf.Bytes()
go incPackageDownloads(repoURLHash, proxyURL, systemID)
go incPackageDownloads(repoURLHash, systemID)
return
}
func incPackageDownloads(repoURLHash, proxyURL, systemID string) {
func incPackageDownloads(repoURLHash, systemID string) {
if strings.Contains(repoURLHash, ".md") {
return
}
repo := strings.Split(repoURLHash, "@")[0]
u := util.AliyunServer + "/apis/siyuan/bazaar/addBazaarPackageDownloadCount"
httpclient.NewCloudRequest(proxyURL).SetBody(
httpclient.NewCloudRequest().SetBody(
map[string]interface{}{
"systemID": systemID,
"repo": repo,
@ -182,7 +182,7 @@ var cachedBazaarIndex = map[string]*bazaarPackage{}
var bazaarIndexCacheTime int64
var bazaarIndexLock = sync.Mutex{}
func getBazaarIndex(proxyURL string) map[string]*bazaarPackage {
func getBazaarIndex() map[string]*bazaarPackage {
bazaarIndexLock.Lock()
defer bazaarIndexLock.Unlock()
@ -191,7 +191,7 @@ func getBazaarIndex(proxyURL string) map[string]*bazaarPackage {
return cachedBazaarIndex
}
request := httpclient.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest()
u := util.BazaarStatServer + "/bazaar/index.json"
resp, reqErr := request.SetResult(&cachedBazaarIndex).Get(u)
if nil != reqErr {

View file

@ -54,17 +54,17 @@ type Template struct {
Downloads int `json:"downloads"`
}
func Templates(proxyURL string) (templates []*Template) {
func Templates() (templates []*Template) {
templates = []*Template{}
result, err := util.GetRhyResult(false, proxyURL)
result, err := util.GetRhyResult(false)
if nil != err {
return
}
bazaarIndex := getBazaarIndex(proxyURL)
bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/templates.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
@ -87,7 +87,7 @@ func Templates(proxyURL string) (templates []*Template) {
template := &Template{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(template).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(template).Get(innerU)
if nil != innerErr {
util.LogErrorf("get community template [%s] failed: %s", repoURL, innerErr)
return
@ -129,9 +129,9 @@ func Templates(proxyURL string) (templates []*Template) {
return
}
func InstallTemplate(repoURL, repoHash, installPath, proxyURL string, chinaCDN bool, systemID string) error {
func InstallTemplate(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash, proxyURL, chinaCDN, true, systemID)
data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
if nil != err {
return err
}

View file

@ -55,17 +55,17 @@ type Theme struct {
Downloads int `json:"downloads"`
}
func Themes(proxyURL string) (ret []*Theme) {
func Themes() (ret []*Theme) {
ret = []*Theme{}
result, err := util.GetRhyResult(false, proxyURL)
result, err := util.GetRhyResult(false)
if nil != err {
return
}
bazaarIndex := getBazaarIndex(proxyURL)
bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/themes.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
@ -88,7 +88,7 @@ func Themes(proxyURL string) (ret []*Theme) {
theme := &Theme{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(theme).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(theme).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", innerU, innerErr)
return
@ -128,9 +128,9 @@ func Themes(proxyURL string) (ret []*Theme) {
return
}
func InstallTheme(repoURL, repoHash, installPath, proxyURL string, chinaCDN bool, systemID string) error {
func InstallTheme(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash, proxyURL, chinaCDN, true, systemID)
data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
if nil != err {
return err
}

View file

@ -54,17 +54,17 @@ type Widget struct {
Downloads int `json:"downloads"`
}
func Widgets(proxyURL string) (widgets []*Widget) {
func Widgets() (widgets []*Widget) {
widgets = []*Widget{}
result, err := util.GetRhyResult(false, proxyURL)
result, err := util.GetRhyResult(false)
if nil != err {
return
}
bazaarIndex := getBazaarIndex(proxyURL)
bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/widgets.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
@ -87,7 +87,7 @@ func Widgets(proxyURL string) (widgets []*Widget) {
widget := &Widget{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(widget).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest().SetResult(widget).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return
@ -127,9 +127,9 @@ func Widgets(proxyURL string) (widgets []*Widget) {
return
}
func InstallWidget(repoURL, repoHash, installPath, proxyURL string, chinaCDN bool, systemID string) error {
func InstallWidget(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash, proxyURL, chinaCDN, true, systemID)
data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
if nil != err {
return err
}