提升桌面端自动更新安装包下载速度 Fix https://github.com/siyuan-note/siyuan/issues/5997

This commit is contained in:
Liang Ding 2022-09-28 11:29:32 +08:00
parent a7de6b8e33
commit da392ba0d2
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 122 additions and 120 deletions

View file

@ -148,18 +148,13 @@ func downloadInstallPkg(pkgURL, checksum string) {
logging.LogInfof("downloading install package [%s]", pkgURL)
client := req.C().SetTimeout(60 * time.Minute)
callback := func(info req.DownloadInfo) {
//logging.LogDebugf("downloading install package [%s %.2f%%]", pkgURL, float64(info.DownloadedSize)/float64(info.Response.ContentLength)*100.0)
}
resp, err := client.R().SetOutputFile(savePath).SetDownloadCallback(callback).Get(pkgURL)
err := client.NewParallelDownload(pkgURL).SetConcurrency(8).SetSegmentSize(1024 * 1024 * 4).
SetOutputFile(savePath).Do()
if nil != err {
logging.LogErrorf("download install package failed: %s", err)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("download install package [%s] failed [sc=%d]", pkgURL, resp.StatusCode)
return
}
localChecksum, _ := sha256Hash(savePath)
if checksum != localChecksum {
logging.LogErrorf("verify checksum failed, download install package [%s] checksum [%s] not equal to downloaded [%s] checksum [%s]", pkgURL, checksum, savePath, localChecksum)