add illegal download file check to fix issue #61

This commit is contained in:
tickstep 2022-03-02 19:52:12 +08:00
parent 37e7bd07cf
commit 85eb4ce2c4
2 changed files with 12 additions and 10 deletions

View File

@ -50,10 +50,10 @@ type (
onDownloadStatusEvent DownloadStatusFunc //状态处理事件
monitorCancelFunc context.CancelFunc
globalSpeedsStat *speeds.Speeds // 全局速度统计
globalSpeedsStat *speeds.Speeds // 全局速度统计
fileInfo *aliyunpan.FileEntity // 下载的文件信息
driveId string
fileInfo *aliyunpan.FileEntity // 下载的文件信息
driveId string
loadBalancerCompareFunc LoadBalancerCompareFunc // 负载均衡检测函数
durlCheckFunc DURLCheckFunc // 下载url检测函数
statusCodeBodyCheckFunc StatusCodeBodyCheckFunc
@ -76,9 +76,9 @@ type (
//NewDownloader 初始化Downloader
func NewDownloader(writer io.WriterAt, config *Config, p *aliyunpan.PanClient, globalSpeedsStat *speeds.Speeds) (der *Downloader) {
der = &Downloader{
config: config,
writer: writer,
panClient: p,
config: config,
writer: writer,
panClient: p,
globalSpeedsStat: globalSpeedsStat,
}
return
@ -216,7 +216,7 @@ func (der *Downloader) checkLoadBalancers() *LoadBalancerResponseList {
}
loadBalancer := &LoadBalancerResponse{
URL: req.URL.String(),
URL: req.URL.String(),
}
loadBalancerResponses = append(loadBalancerResponses, loadBalancer)
@ -300,7 +300,7 @@ func (der *Downloader) Execute() error {
var (
isInstance = bii != nil // 是否存在断点信息
status *transfer.DownloadStatus
single = false // 默认开启多线程下载
single = false // 默认开启多线程下载
)
if !isInstance {
bii = &transfer.DownloadInstanceInfo{}
@ -374,7 +374,7 @@ func (der *Downloader) Execute() error {
var apierr *apierror.ApiError
durl, apierr := der.panClient.GetFileDownloadUrl(&aliyunpan.GetFileDownloadUrlParam{
DriveId: der.driveId,
FileId: der.fileInfo.FileId,
FileId: der.fileInfo.FileId,
})
time.Sleep(time.Duration(200) * time.Millisecond)
if apierr != nil {
@ -382,7 +382,7 @@ func (der *Downloader) Execute() error {
cmdutil.Trigger(der.onCancelEvent)
return apierr
}
if durl == nil || durl.Url == "" {
if durl == nil || durl.Url == "" || durl.Url == aliyunpan.IllegalDownloadUrl {
logger.Verbosef("无法获取有效的下载链接: %+v\n", durl)
cmdutil.Trigger(der.onCancelEvent)
der.removeInstanceState() // 移除断点续传文件

View File

@ -63,6 +63,8 @@ const (
StatusCodeCanceled
//StatusCodeDownloadUrlExpired 下载链接已过期
StatusCodeDownloadUrlExpired
//StatusCodeIllegalDownloadFile 文件非法,不允许下载
StatusCodeIllegalDownloadFile
)
//GetStatusText 根据状态码获取状态信息