♻️ 内核中的 HTTP 客户端拆分项目 https://github.com/siyuan-note/siyuan/issues/5269

This commit is contained in:
Liang Ding 2022-06-23 01:22:28 +08:00
parent 25ddad5957
commit 779e4fc4ae
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
13 changed files with 59 additions and 150 deletions

View file

@ -25,6 +25,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -63,7 +64,7 @@ func Icons(proxyURL string) (icons []*Icon) {
bazaarIndex := getBazaarIndex(proxyURL)
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := util.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest(proxyURL)
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/icons.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
@ -85,7 +86,7 @@ func Icons(proxyURL string) (icons []*Icon) {
icon := &Icon{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
innerResp, innerErr := util.NewBrowserRequest(proxyURL).SetResult(icon).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(icon).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return

View file

@ -30,6 +30,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/araddon/dateparse"
"github.com/imroc/req/v3"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/siyuan/kernel/util"
textUnicode "golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
@ -82,14 +83,14 @@ func downloadPackage(repoURLHash, proxyURL string, chinaCDN, pushProgress bool,
u = util.BazaarOSSServer + "/package/" + repoURLHash
}
buf := &bytes.Buffer{}
resp, err := util.NewBrowserDownloadRequest(proxyURL).SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
resp, err := httpclient.NewBrowserDownloadRequest(proxyURL).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 = util.NewBrowserDownloadRequest(proxyURL).SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
resp, err = httpclient.NewBrowserDownloadRequest(proxyURL).SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
if pushProgress {
util.PushDownloadProgress(pushID, float32(info.DownloadedSize)/float32(info.Response.ContentLength))
}
@ -116,7 +117,7 @@ func incPackageDownloads(repoURLHash, proxyURL, systemID string) {
repo := strings.Split(repoURLHash, "@")[0]
u := util.AliyunServer + "/apis/siyuan/bazaar/addBazaarPackageDownloadCount"
util.NewCloudRequest(proxyURL).SetBody(
httpclient.NewCloudRequest(proxyURL).SetBody(
map[string]interface{}{
"systemID": systemID,
"repo": repo,
@ -190,7 +191,7 @@ func getBazaarIndex(proxyURL string) map[string]*bazaarPackage {
return cachedBazaarIndex
}
request := util.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest(proxyURL)
u := util.BazaarStatServer + "/bazaar/index.json"
resp, reqErr := request.SetResult(&cachedBazaarIndex).Get(u)
if nil != reqErr {

View file

@ -26,6 +26,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -63,7 +64,7 @@ func Templates(proxyURL string) (templates []*Template) {
bazaarIndex := getBazaarIndex(proxyURL)
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := util.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest(proxyURL)
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/templates.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
@ -86,7 +87,7 @@ func Templates(proxyURL string) (templates []*Template) {
template := &Template{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/template.json"
innerResp, innerErr := util.NewBrowserRequest(proxyURL).SetResult(template).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(template).Get(innerU)
if nil != innerErr {
util.LogErrorf("get community template [%s] failed: %s", repoURL, innerErr)
return

View file

@ -25,6 +25,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -64,7 +65,7 @@ func Themes(proxyURL string) (ret []*Theme) {
bazaarIndex := getBazaarIndex(proxyURL)
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := util.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest(proxyURL)
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/themes.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
@ -87,7 +88,7 @@ func Themes(proxyURL string) (ret []*Theme) {
theme := &Theme{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/theme.json"
innerResp, innerErr := util.NewBrowserRequest(proxyURL).SetResult(theme).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(theme).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", innerU, innerErr)
return

View file

@ -25,6 +25,7 @@ import (
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -63,7 +64,7 @@ func Widgets(proxyURL string) (widgets []*Widget) {
bazaarIndex := getBazaarIndex(proxyURL)
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := util.NewBrowserRequest(proxyURL)
request := httpclient.NewBrowserRequest(proxyURL)
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/widgets.json"
resp, err := request.SetResult(&result).Get(u)
if nil != err {
@ -86,7 +87,7 @@ func Widgets(proxyURL string) (widgets []*Widget) {
widget := &Widget{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/widget.json"
innerResp, innerErr := util.NewBrowserRequest(proxyURL).SetResult(widget).Get(innerU)
innerResp, innerErr := httpclient.NewBrowserRequest(proxyURL).SetResult(widget).Get(innerU)
if nil != innerErr {
util.LogErrorf("get bazaar package [%s] failed: %s", repoURL, innerErr)
return