浏览代码

:zap: 改进非订阅用户集市包下载速度 Fix https://github.com/siyuan-note/siyuan/issues/5779

Liang Ding 2 年之前
父节点
当前提交
00e0f6b7de
共有 7 个文件被更改,包括 21 次插入25 次删除
  1. 2 2
      kernel/bazaar/icon.go
  2. 4 7
      kernel/bazaar/package.go
  3. 2 2
      kernel/bazaar/template.go
  4. 2 2
      kernel/bazaar/theme.go
  5. 2 2
      kernel/bazaar/widget.go
  6. 5 5
      kernel/model/bazzar.go
  7. 4 5
      kernel/util/path.go

+ 2 - 2
kernel/bazaar/icon.go

@@ -127,9 +127,9 @@ func Icons() (icons []*Icon) {
 	return
 	return
 }
 }
 
 
-func InstallIcon(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
+func InstallIcon(repoURL, repoHash, installPath string, systemID string) error {
 	repoURLHash := repoURL + "@" + repoHash
 	repoURLHash := repoURL + "@" + repoHash
-	data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
+	data, err := downloadPackage(repoURLHash, true, systemID)
 	if nil != err {
 	if nil != err {
 		return err
 		return err
 	}
 	}

+ 4 - 7
kernel/bazaar/package.go

@@ -37,9 +37,9 @@ import (
 	"golang.org/x/text/transform"
 	"golang.org/x/text/transform"
 )
 )
 
 
-func GetPackageREADME(repoURL, repoHash string, chinaCDN bool, systemID string) (ret string) {
+func GetPackageREADME(repoURL, repoHash string, systemID string) (ret string) {
 	repoURLHash := repoURL + "@" + repoHash
 	repoURLHash := repoURL + "@" + repoHash
-	data, err := downloadPackage(repoURLHash+"/README.md", chinaCDN, false, systemID)
+	data, err := downloadPackage(repoURLHash+"/README.md", false, systemID)
 	if nil != err {
 	if nil != err {
 		ret = "Load bazaar package's README.md failed: " + err.Error()
 		ret = "Load bazaar package's README.md failed: " + err.Error()
 		return
 		return
@@ -75,14 +75,11 @@ func GetPackageREADME(repoURL, repoHash string, chinaCDN bool, systemID string)
 	return
 	return
 }
 }
 
 
-func downloadPackage(repoURLHash string, chinaCDN, pushProgress bool, systemID string) (data []byte, err error) {
+func downloadPackage(repoURLHash string, pushProgress bool, systemID string) (data []byte, err error) {
 	// repoURLHash: https://github.com/88250/Comfortably-Numb@6286912c381ef3f83e455d06ba4d369c498238dc
 	// repoURLHash: https://github.com/88250/Comfortably-Numb@6286912c381ef3f83e455d06ba4d369c498238dc
 	pushID := repoURLHash[:strings.LastIndex(repoURLHash, "@")]
 	pushID := repoURLHash[:strings.LastIndex(repoURLHash, "@")]
 	repoURLHash = strings.TrimPrefix(repoURLHash, "https://github.com/")
 	repoURLHash = strings.TrimPrefix(repoURLHash, "https://github.com/")
-	u := util.BazaarOSSFileServer + "/package/" + repoURLHash
-	if chinaCDN {
-		u = util.BazaarOSSServer + "/package/" + repoURLHash
-	}
+	u := util.BazaarOSSServer + "/package/" + repoURLHash
 	buf := &bytes.Buffer{}
 	buf := &bytes.Buffer{}
 	resp, err := httpclient.NewBrowserDownloadRequest().SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
 	resp, err := httpclient.NewBrowserDownloadRequest().SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) {
 		if pushProgress {
 		if pushProgress {

+ 2 - 2
kernel/bazaar/template.go

@@ -130,9 +130,9 @@ func Templates() (templates []*Template) {
 	return
 	return
 }
 }
 
 
-func InstallTemplate(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
+func InstallTemplate(repoURL, repoHash, installPath string, systemID string) error {
 	repoURLHash := repoURL + "@" + repoHash
 	repoURLHash := repoURL + "@" + repoHash
-	data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
+	data, err := downloadPackage(repoURLHash, true, systemID)
 	if nil != err {
 	if nil != err {
 		return err
 		return err
 	}
 	}

+ 2 - 2
kernel/bazaar/theme.go

@@ -129,9 +129,9 @@ func Themes() (ret []*Theme) {
 	return
 	return
 }
 }
 
 
-func InstallTheme(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
+func InstallTheme(repoURL, repoHash, installPath string, systemID string) error {
 	repoURLHash := repoURL + "@" + repoHash
 	repoURLHash := repoURL + "@" + repoHash
-	data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
+	data, err := downloadPackage(repoURLHash, true, systemID)
 	if nil != err {
 	if nil != err {
 		return err
 		return err
 	}
 	}

+ 2 - 2
kernel/bazaar/widget.go

@@ -128,9 +128,9 @@ func Widgets() (widgets []*Widget) {
 	return
 	return
 }
 }
 
 
-func InstallWidget(repoURL, repoHash, installPath string, chinaCDN bool, systemID string) error {
+func InstallWidget(repoURL, repoHash, installPath string, systemID string) error {
 	repoURLHash := repoURL + "@" + repoHash
 	repoURLHash := repoURL + "@" + repoHash
-	data, err := downloadPackage(repoURLHash, chinaCDN, true, systemID)
+	data, err := downloadPackage(repoURLHash, true, systemID)
 	if nil != err {
 	if nil != err {
 		return err
 		return err
 	}
 	}

+ 5 - 5
kernel/model/bazzar.go

@@ -28,7 +28,7 @@ import (
 )
 )
 
 
 func GetPackageREADME(repoURL, repoHash string) (ret string) {
 func GetPackageREADME(repoURL, repoHash string) (ret string) {
-	ret = bazaar.GetPackageREADME(repoURL, repoHash, IsSubscriber(), Conf.System.ID)
+	ret = bazaar.GetPackageREADME(repoURL, repoHash, Conf.System.ID)
 	return
 	return
 }
 }
 
 
@@ -54,7 +54,7 @@ func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
 	defer writingDataLock.Unlock()
 	defer writingDataLock.Unlock()
 
 
 	installPath := filepath.Join(util.DataDir, "widgets", widgetName)
 	installPath := filepath.Join(util.DataDir, "widgets", widgetName)
-	err := bazaar.InstallWidget(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
+	err := bazaar.InstallWidget(repoURL, repoHash, installPath, Conf.System.ID)
 	if nil != err {
 	if nil != err {
 		return errors.New(fmt.Sprintf(Conf.Language(46), widgetName))
 		return errors.New(fmt.Sprintf(Conf.Language(46), widgetName))
 	}
 	}
@@ -96,7 +96,7 @@ func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
 	defer writingDataLock.Unlock()
 	defer writingDataLock.Unlock()
 
 
 	installPath := filepath.Join(util.IconsPath, iconName)
 	installPath := filepath.Join(util.IconsPath, iconName)
-	err := bazaar.InstallIcon(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
+	err := bazaar.InstallIcon(repoURL, repoHash, installPath, Conf.System.ID)
 	if nil != err {
 	if nil != err {
 		return errors.New(fmt.Sprintf(Conf.Language(46), iconName))
 		return errors.New(fmt.Sprintf(Conf.Language(46), iconName))
 	}
 	}
@@ -145,7 +145,7 @@ func InstallBazaarTheme(repoURL, repoHash, themeName string, mode int, update bo
 	closeThemeWatchers()
 	closeThemeWatchers()
 
 
 	installPath := filepath.Join(util.ThemesPath, themeName)
 	installPath := filepath.Join(util.ThemesPath, themeName)
-	err := bazaar.InstallTheme(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
+	err := bazaar.InstallTheme(repoURL, repoHash, installPath, Conf.System.ID)
 	if nil != err {
 	if nil != err {
 		return errors.New(fmt.Sprintf(Conf.Language(46), themeName))
 		return errors.New(fmt.Sprintf(Conf.Language(46), themeName))
 	}
 	}
@@ -202,7 +202,7 @@ func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
 	defer writingDataLock.Unlock()
 	defer writingDataLock.Unlock()
 
 
 	installPath := filepath.Join(util.DataDir, "templates", templateName)
 	installPath := filepath.Join(util.DataDir, "templates", templateName)
-	err := bazaar.InstallTemplate(repoURL, repoHash, installPath, IsSubscriber(), Conf.System.ID)
+	err := bazaar.InstallTemplate(repoURL, repoHash, installPath, Conf.System.ID)
 	if nil != err {
 	if nil != err {
 		return errors.New(fmt.Sprintf(Conf.Language(46), templateName))
 		return errors.New(fmt.Sprintf(Conf.Language(46), templateName))
 	}
 	}

+ 4 - 5
kernel/util/path.go

@@ -34,11 +34,10 @@ var (
 )
 )
 
 
 const (
 const (
-	ServerPort          = "6806"                              // HTTP/WebSocket 端口
-	AliyunServer        = "https://siyuan-sync.b3logfile.com" // 云端服务地址,阿里云负载均衡,用于接口,数据同步文件上传、下载会走七牛云 OSS http://siyuan-data.b3logfile.com
-	BazaarStatServer    = "http://bazaar.b3logfile.com"       // 集市包统计服务地址,直接对接 Bucket 没有 CDN 缓存
-	BazaarOSSServer     = "https://oss.b3logfile.com"         // 云端对象存储地址,七牛云,仅用于读取小文件(比如配置 json),不用于读取包内容(如果是订阅会员则用于读取包内容)
-	BazaarOSSFileServer = "https://oss0.b3logfile.com"        // 云端对象存储文件服务地址,Cloudflare,用于读取包内容
+	ServerPort       = "6806"                              // HTTP/WebSocket 端口
+	AliyunServer     = "https://siyuan-sync.b3logfile.com" // 云端服务地址,阿里云负载均衡,用于接口,数据同步文件上传、下载会走七牛云 OSS http://siyuan-data.b3logfile.com
+	BazaarStatServer = "http://bazaar.b3logfile.com"       // 集市包统计服务地址,直接对接 Bucket 没有 CDN 缓存
+	BazaarOSSServer  = "https://oss.b3logfile.com"         // 云端对象存储地址,七牛云,仅用于读取集市包
 )
 )
 
 
 func ShortPathForBootingDisplay(p string) string {
 func ShortPathForBootingDisplay(p string) string {