mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
fix download url expired issue for sync
This commit is contained in:
parent
c0da3de6c6
commit
ae81b59926
@ -146,6 +146,11 @@ func (wer *Worker) SetDownloadStatus(downloadStatus *transfer.DownloadStatus) {
|
||||
wer.downloadStatus = downloadStatus
|
||||
}
|
||||
|
||||
// SetUrl 更新新的下载路径
|
||||
func (wer *Worker) SetUrl(newUrl string) {
|
||||
wer.url = newUrl
|
||||
}
|
||||
|
||||
// GetStatus 返回下载状态
|
||||
func (wer *Worker) GetStatus() WorkerStatuser {
|
||||
// 空接口与空指针不等价
|
||||
|
@ -383,8 +383,34 @@ func (f *FileActionTask) downloadFile(ctx context.Context) error {
|
||||
|
||||
// 存储状态
|
||||
f.syncFileDb.Update(f.syncItem)
|
||||
} else if worker.GetStatus().StatusCode() == downloader.StatusCodeDownloadUrlExpired {
|
||||
logger.Verboseln("download url expired: ", f.syncItem.PanFile.Path)
|
||||
// 下载链接过期,获取新的链接
|
||||
newUrl, apierr1 := f.panClient.OpenapiPanClient().GetFileDownloadUrl(&aliyunpan.GetFileDownloadUrlParam{
|
||||
DriveId: f.syncItem.PanFile.DriveId,
|
||||
FileId: f.syncItem.PanFile.FileId,
|
||||
})
|
||||
time.Sleep(time.Duration(3) * time.Second)
|
||||
if apierr1 != nil {
|
||||
if apierr1.Code == apierror.ApiCodeFileNotFoundCode || apierr1.Code == apierror.ApiCodeForbiddenFileInTheRecycleBin {
|
||||
f.syncItem.Status = SyncFileStatusNotExisted
|
||||
f.syncItem.StatusUpdateTime = utils.NowTimeStr()
|
||||
f.syncFileDb.Update(f.syncItem)
|
||||
return fmt.Errorf("文件不存在")
|
||||
}
|
||||
logger.Verbosef("ERROR: get download url error: %s, %s\n", f.syncItem.PanFile.Path, apierr.Error())
|
||||
return apierr
|
||||
}
|
||||
if newUrl == nil || newUrl.Url == "" {
|
||||
logger.Verbosef("无法获取有效的下载链接: %+v\n", durl)
|
||||
f.syncItem.Status = SyncFileStatusFailed
|
||||
f.syncItem.StatusUpdateTime = utils.NowTimeStr()
|
||||
f.syncFileDb.Update(f.syncItem)
|
||||
return fmt.Errorf("无法获取有效的下载链接")
|
||||
}
|
||||
logger.Verboseln("query new download url: ", newUrl.Url)
|
||||
worker.SetUrl(newUrl.Url)
|
||||
}
|
||||
// TODO: 下载链接过期处理
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user