mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
optimize device session signature error #257
This commit is contained in:
parent
23fe54ce0b
commit
78e290c2a4
@ -19,7 +19,6 @@ import (
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
|
||||
"github.com/tickstep/aliyunpan/cmder/cmdutil"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
"github.com/tickstep/aliyunpan/internal/waitgroup"
|
||||
"github.com/tickstep/aliyunpan/library/requester/transfer"
|
||||
"github.com/tickstep/library-go/cachepool"
|
||||
@ -385,10 +384,7 @@ func (der *Downloader) Execute() error {
|
||||
FileId: der.fileInfo.FileId,
|
||||
})
|
||||
if apierr != nil && apierr.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := der.panClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
_, e := der.panClient.CreateSession(nil)
|
||||
if e == nil {
|
||||
// retry
|
||||
durl, apierr = der.panClient.GetFileDownloadUrl(&aliyunpan.GetFileDownloadUrlParam{
|
||||
|
@ -445,18 +445,6 @@ func (dtu *DownloadTaskUnit) Run() (result *taskframework.TaskUnitRunResult) {
|
||||
// 如果是动态添加的下载任务, 是会写入文件信息的
|
||||
// 如果该任务重试过, 则应该再获取一次文件信息
|
||||
dtu.fileInfo, apierr = dtu.PanClient.FileInfoByPath(dtu.DriveId, dtu.FilePanPath)
|
||||
if apierr != nil && apierr.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := dtu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
if e == nil {
|
||||
// retry
|
||||
dtu.fileInfo, apierr = dtu.PanClient.FileInfoByPath(dtu.DriveId, dtu.FilePanPath)
|
||||
} else {
|
||||
logger.Verboseln("CreateSession failed")
|
||||
}
|
||||
}
|
||||
if apierr != nil {
|
||||
// 如果不是未登录或文件不存在, 则不重试
|
||||
result.ResultMessage = "获取下载路径信息错误"
|
||||
|
@ -16,7 +16,6 @@ package panupload
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"github.com/tickstep/aliyunpan/internal/config"
|
||||
"github.com/tickstep/library-go/logger"
|
||||
"github.com/tickstep/library-go/requester"
|
||||
"io"
|
||||
@ -240,10 +239,7 @@ func (pu *PanUpload) CommitFile() (cerr error) {
|
||||
UploadId: pu.uploadOpEntity.UploadId,
|
||||
})
|
||||
if er != nil && er.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := pu.panClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
_, e := pu.panClient.CreateSession(nil)
|
||||
if e == nil {
|
||||
// retry
|
||||
_, er = pu.panClient.CompleteUploadFile(&aliyunpan.CompleteUploadFileParam{
|
||||
|
@ -355,18 +355,6 @@ StepUploadPrepareUpload:
|
||||
utu.FolderCreateMutex.Lock()
|
||||
fmt.Printf("[%s] %s 正在检测和创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
|
||||
fe, apierr1 := utu.PanClient.FileInfoByPath(utu.DriveId, saveFilePath)
|
||||
if apierr1 != nil && apierr1.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := utu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
if e == nil {
|
||||
// retry
|
||||
fe, apierr1 = utu.PanClient.FileInfoByPath(utu.DriveId, saveFilePath)
|
||||
} else {
|
||||
logger.Verboseln("CreateSession failed")
|
||||
}
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
needToCreateFolder := false
|
||||
if apierr1 != nil && apierr1.Code == apierror.ApiCodeFileNotFoundCode {
|
||||
@ -383,10 +371,7 @@ StepUploadPrepareUpload:
|
||||
logger.Verbosef("[%s] %s 创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
|
||||
rs, apierr = utu.PanClient.Mkdir(utu.DriveId, "root", saveFilePath)
|
||||
if apierr != nil && apierr.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := utu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
_, e := utu.PanClient.CreateSession(nil)
|
||||
if e == nil {
|
||||
// retry
|
||||
rs, apierr = utu.PanClient.Mkdir(utu.DriveId, "root", saveFilePath)
|
||||
@ -437,18 +422,6 @@ StepUploadPrepareUpload:
|
||||
// 标记覆盖旧同名文件
|
||||
// 检查同名文件是否存在
|
||||
efi, apierr := utu.PanClient.FileInfoByPath(utu.DriveId, utu.SavePath)
|
||||
if apierr != nil && apierr.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := utu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
if e == nil {
|
||||
// retry
|
||||
efi, apierr = utu.PanClient.FileInfoByPath(utu.DriveId, utu.SavePath)
|
||||
} else {
|
||||
logger.Verboseln("CreateSession failed")
|
||||
}
|
||||
}
|
||||
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
|
||||
result.Err = apierr
|
||||
result.ResultMessage = "检测同名文件失败"
|
||||
@ -465,18 +438,6 @@ StepUploadPrepareUpload:
|
||||
var fileDeleteResult []*aliyunpan.FileBatchActionResult
|
||||
var err *apierror.ApiError
|
||||
fileDeleteResult, err = utu.PanClient.FileDelete([]*aliyunpan.FileBatchActionParam{{DriveId: efi.DriveId, FileId: efi.FileId}})
|
||||
if err != nil && err.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := utu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
if e == nil {
|
||||
// retry
|
||||
fileDeleteResult, err = utu.PanClient.FileDelete([]*aliyunpan.FileBatchActionParam{{DriveId: efi.DriveId, FileId: efi.FileId}})
|
||||
} else {
|
||||
logger.Verboseln("CreateSession failed")
|
||||
}
|
||||
}
|
||||
if err != nil || len(fileDeleteResult) == 0 {
|
||||
result.Err = err
|
||||
result.ResultMessage = "无法删除文件,请稍后重试"
|
||||
@ -510,10 +471,7 @@ StepUploadPrepareUpload:
|
||||
|
||||
uploadOpEntity, apierr = utu.PanClient.CreateUploadFile(appCreateUploadFileParam)
|
||||
if apierr != nil && apierr.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||
_, e := utu.PanClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||
DeviceName: config.Config.DeviceName,
|
||||
ModelName: "Windows网页版",
|
||||
})
|
||||
_, e := utu.PanClient.CreateSession(nil)
|
||||
if e == nil {
|
||||
// retry
|
||||
uploadOpEntity, apierr = utu.PanClient.CreateUploadFile(appCreateUploadFileParam)
|
||||
|
Loading…
Reference in New Issue
Block a user