mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 22:42:15 +08:00
fix device session signature error for upload #257
This commit is contained in:
parent
ab215736a9
commit
3be79d1181
@ -16,6 +16,7 @@ package panupload
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"github.com/tickstep/aliyunpan/internal/config"
|
||||||
"github.com/tickstep/library-go/logger"
|
"github.com/tickstep/library-go/logger"
|
||||||
"github.com/tickstep/library-go/requester"
|
"github.com/tickstep/library-go/requester"
|
||||||
"io"
|
"io"
|
||||||
@ -238,6 +239,22 @@ func (pu *PanUpload) CommitFile() (cerr error) {
|
|||||||
FileId: pu.uploadOpEntity.FileId,
|
FileId: pu.uploadOpEntity.FileId,
|
||||||
UploadId: pu.uploadOpEntity.UploadId,
|
UploadId: pu.uploadOpEntity.UploadId,
|
||||||
})
|
})
|
||||||
|
if er != nil && er.Code == apierror.ApiCodeDeviceSessionSignatureInvalid {
|
||||||
|
_, e := pu.panClient.CreateSession(&aliyunpan.CreateSessionParam{
|
||||||
|
DeviceName: config.Config.DeviceName,
|
||||||
|
ModelName: "Windows网页版",
|
||||||
|
})
|
||||||
|
if e == nil {
|
||||||
|
// retry
|
||||||
|
_, er = pu.panClient.CompleteUploadFile(&aliyunpan.CompleteUploadFileParam{
|
||||||
|
DriveId: pu.driveId,
|
||||||
|
FileId: pu.uploadOpEntity.FileId,
|
||||||
|
UploadId: pu.uploadOpEntity.UploadId,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
logger.Verboseln("CreateSession failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
if er != nil {
|
if er != nil {
|
||||||
return er
|
return er
|
||||||
}
|
}
|
||||||
|
@ -355,6 +355,18 @@ StepUploadPrepareUpload:
|
|||||||
utu.FolderCreateMutex.Lock()
|
utu.FolderCreateMutex.Lock()
|
||||||
fmt.Printf("[%s] %s 正在检测和创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
|
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)
|
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)
|
time.Sleep(1 * time.Second)
|
||||||
needToCreateFolder := false
|
needToCreateFolder := false
|
||||||
if apierr1 != nil && apierr1.Code == apierror.ApiCodeFileNotFoundCode {
|
if apierr1 != nil && apierr1.Code == apierror.ApiCodeFileNotFoundCode {
|
||||||
@ -369,9 +381,19 @@ StepUploadPrepareUpload:
|
|||||||
}
|
}
|
||||||
if needToCreateFolder {
|
if needToCreateFolder {
|
||||||
logger.Verbosef("[%s] %s 创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
|
logger.Verbosef("[%s] %s 创建云盘文件夹: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), saveFilePath)
|
||||||
// rs, apierr = utu.PanClient.MkdirRecursive(utu.DriveId, "", "", 0, strings.Split(path.Clean(saveFilePath), "/"))
|
|
||||||
// 可以直接创建的,不用循环创建
|
|
||||||
rs, apierr = utu.PanClient.Mkdir(utu.DriveId, "root", 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网页版",
|
||||||
|
})
|
||||||
|
if e == nil {
|
||||||
|
// retry
|
||||||
|
rs, apierr = utu.PanClient.Mkdir(utu.DriveId, "root", saveFilePath)
|
||||||
|
} else {
|
||||||
|
logger.Verboseln("CreateSession failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
if apierr != nil || rs.FileId == "" {
|
if apierr != nil || rs.FileId == "" {
|
||||||
result.Err = apierr
|
result.Err = apierr
|
||||||
result.ResultMessage = "创建云盘文件夹失败"
|
result.ResultMessage = "创建云盘文件夹失败"
|
||||||
@ -415,6 +437,18 @@ StepUploadPrepareUpload:
|
|||||||
// 标记覆盖旧同名文件
|
// 标记覆盖旧同名文件
|
||||||
// 检查同名文件是否存在
|
// 检查同名文件是否存在
|
||||||
efi, apierr := utu.PanClient.FileInfoByPath(utu.DriveId, utu.SavePath)
|
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 {
|
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
|
||||||
result.Err = apierr
|
result.Err = apierr
|
||||||
result.ResultMessage = "检测同名文件失败"
|
result.ResultMessage = "检测同名文件失败"
|
||||||
@ -431,6 +465,18 @@ StepUploadPrepareUpload:
|
|||||||
var fileDeleteResult []*aliyunpan.FileBatchActionResult
|
var fileDeleteResult []*aliyunpan.FileBatchActionResult
|
||||||
var err *apierror.ApiError
|
var err *apierror.ApiError
|
||||||
fileDeleteResult, err = utu.PanClient.FileDelete([]*aliyunpan.FileBatchActionParam{{DriveId: efi.DriveId, FileId: efi.FileId}})
|
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 {
|
if err != nil || len(fileDeleteResult) == 0 {
|
||||||
result.Err = err
|
result.Err = err
|
||||||
result.ResultMessage = "无法删除文件,请稍后重试"
|
result.ResultMessage = "无法删除文件,请稍后重试"
|
||||||
@ -463,6 +509,18 @@ StepUploadPrepareUpload:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadOpEntity, apierr = utu.PanClient.CreateUploadFile(appCreateUploadFileParam)
|
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网页版",
|
||||||
|
})
|
||||||
|
if e == nil {
|
||||||
|
// retry
|
||||||
|
uploadOpEntity, apierr = utu.PanClient.CreateUploadFile(appCreateUploadFileParam)
|
||||||
|
} else {
|
||||||
|
logger.Verboseln("CreateSession failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
if apierr != nil {
|
if apierr != nil {
|
||||||
result.Err = apierr
|
result.Err = apierr
|
||||||
result.ResultMessage = "创建上传任务失败:" + apierr.Error()
|
result.ResultMessage = "创建上传任务失败:" + apierr.Error()
|
||||||
|
Loading…
Reference in New Issue
Block a user