refactor upload command

This commit is contained in:
tickstep 2025-01-04 10:57:21 +08:00
parent 2b283b727e
commit 6ed0e6bae0
4 changed files with 20 additions and 14 deletions

View File

@ -518,6 +518,8 @@ StepUploadPrepareUpload:
ContentHashName: contentHashName,
ProofCode: proofCode,
ProofVersion: "v1",
LocalCreatedAt: utils.UnixTime2LocalFormatStr(utu.LocalFileChecksum.ModTime),
LocalModifiedAt: utils.UnixTime2LocalFormatStr(utu.LocalFileChecksum.ModTime),
}
} else {
// 不支持秒传不计算SHA1直接上传文件
@ -528,6 +530,8 @@ StepUploadPrepareUpload:
CheckNameMode: checkNameMode,
ParentFileId: rs.FileId,
BlockSize: utu.BlockSize,
LocalCreatedAt: utils.UnixTime2LocalFormatStr(utu.LocalFileChecksum.ModTime),
LocalModifiedAt: utils.UnixTime2LocalFormatStr(utu.LocalFileChecksum.ModTime),
}
}

View File

@ -94,10 +94,3 @@ func CalcFilePreHash(filePath string) string {
hashCode := hex.EncodeToString(shaBytes)
return strings.ToUpper(hashCode)
}
// UnixTime2LocalFormatStr 时间戳转换为东8区时间字符串
func UnixTime2LocalFormatStr(unixTime int64) string {
t := time.Unix(unixTime, 0)
cz := time.FixedZone("CST", 8*3600) // 东8区
return t.In(cz).Format("2006-01-02T15:04:05.000Z")
}

View File

@ -506,6 +506,8 @@ func (f *FileActionTask) uploadFile(ctx context.Context) error {
BlockSize: f.syncItem.UploadBlockSize,
ProofCode: proofCode,
ProofVersion: "v1",
LocalCreatedAt: utils.UnixTime2LocalFormatStr(localFile.ModTime),
LocalModifiedAt: utils.UnixTime2LocalFormatStr(localFile.ModTime),
}
if uploadOpEntity, err := f.panClient.OpenapiPanClient().CreateUploadFile(appCreateUploadFileParam); err != nil {
logger.Verbosef("创建云盘上传任务失败: %s\n", targetPanFilePath)

View File

@ -281,3 +281,10 @@ func ResizeUploadBlockSize(fileSize, defaultBlockSize int64) int64 {
sizeOfMB := int64(math.Ceil(float64(fileSize) / float64(aliyunpan.MaxPartNum) / 1024.0))
return sizeOfMB * 1024
}
// UnixTime2LocalFormatStr 时间戳转换为东8区时间字符串
func UnixTime2LocalFormatStr(unixTime int64) string {
t := time.Unix(unixTime, 0)
cz := time.FixedZone("CST", 8*3600) // 东8区
return t.In(cz).Format("2006-01-02T15:04:05.000Z")
}