From 829eb1e1eddf92d609155191b804a1cdfe962269 Mon Sep 17 00:00:00 2001 From: iikira <2571583272@qq.com> Date: Tue, 20 Nov 2018 17:51:01 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#548,=20=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BC=9A=E6=B8=85=E9=99=A4=E4=B8=8A=E4=BC=A0=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E8=BF=87=E6=9C=9F=E7=9A=84=E4=BB=BB=E5=8A=A1=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baidupcs/extends.go | 5 ++--- baidupcs/upload.go | 2 ++ internal/pcscommand/upload.go | 26 ++++++++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/baidupcs/extends.go b/baidupcs/extends.go index 9d0ce923..56330b8a 100644 --- a/baidupcs/extends.go +++ b/baidupcs/extends.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "errors" "github.com/iikira/BaiduPCS-Go/baidupcs/pcserror" - "github.com/iikira/BaiduPCS-Go/pcsutil/converter" "github.com/iikira/BaiduPCS-Go/pcsutil/escaper" "github.com/iikira/BaiduPCS-Go/requester/downloader" "io" @@ -65,7 +64,7 @@ func (pcs *BaiduPCS) getLocateDownloadLink(pcspath string) (link string, pcsErro func (pcs *BaiduPCS) ExportByFileInfo(finfo *FileDirectory) (rinfo *RapidUploadInfo, pcsError pcserror.Error) { errInfo := pcserror.NewPCSErrorInfo(OperationExportFileInfo) errInfo.ErrType = pcserror.ErrTypeOthers - if finfo.Size > 20*converter.GB { + if finfo.Size > MaxRapidUploadSize { errInfo.Err = ErrFileTooLarge return nil, errInfo } @@ -252,7 +251,7 @@ func (pcs *BaiduPCS) FixMD5ByFileInfo(finfo *FileDirectory) (pcsError pcserror.E return errInfo } - if finfo.Size > 20*converter.GB { // 文件大于20GB + if finfo.Size > MaxRapidUploadSize { // 文件大于20GB errInfo.Err = ErrFileTooLarge return errInfo } diff --git a/baidupcs/upload.go b/baidupcs/upload.go index 08fdb2c6..ad48d75f 100644 --- a/baidupcs/upload.go +++ b/baidupcs/upload.go @@ -13,6 +13,8 @@ const ( MaxUploadBlockSize = 2 * converter.GB // MinUploadBlockSize 最小的上传的文件分片大小 MinUploadBlockSize = 4 * converter.MB + // MaxRapidUploadSize 秒传文件支持的最大文件大小 + MaxRapidUploadSize = 20 * converter.GB // RecommendUploadBlockSize 推荐的上传的文件分片大小 RecommendUploadBlockSize = 1 * converter.GB // SliceMD5Size 计算 slice-md5 所需的长度 diff --git a/internal/pcscommand/upload.go b/internal/pcscommand/upload.go index b0047383..7bb7f3c7 100644 --- a/internal/pcscommand/upload.go +++ b/internal/pcscommand/upload.go @@ -243,7 +243,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) { } defer task.uploadInfo.Close() // 关闭文件 - // 步骤控制 var ( panDir, panFile = path.Split(task.savePath) ) @@ -261,7 +260,13 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) { goto stepControl } - stepControl: + if task.uploadInfo.Length > baidupcs.MaxRapidUploadSize { + fmt.Printf("[%d] 文件超过20GB, 无法使用秒传功能, 跳过秒传...\n", task.ID) + task.step = StepUploadUpload + goto stepControl + } + + stepControl: // 步骤控制 switch task.step { case StepUploadRapidUpload: goto stepUploadRapidUpload @@ -309,7 +314,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) { // do nothing } - // 经过测试, 秒传文件并非需要前256kb切片的md5值, 只需格式符合即可 task.uploadInfo.SliceMD5Sum() // 经测试, 文件的 crc32 值并非秒传文件所必需 @@ -389,11 +393,21 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) { muer.OnError(func(err error) { close(exitChan) pcsError, ok := err.(pcserror.Error) - if ok { - handleTaskErr(task, "上传文件失败", pcsError) + if !ok { + fmt.Printf("[%d] 上传文件错误: %s\n", task.ID, err) return } - fmt.Printf("[%d] 上传文件错误: %s\n", task.ID, err) + + switch pcsError.GetRemoteErrCode() { + case 31363: // block miss in superfile2, 上传状态过期 + uploadDatabase.Delete(&task.uploadInfo.LocalFileMeta) + uploadDatabase.Save() + fmt.Printf("[%d] 上传文件错误: 上传状态过期, 请重新上传\n", task.ID) + return + } + + handleTaskErr(task, "上传文件失败", pcsError) + return }) muer.Execute() }