add upload file record #206

This commit is contained in:
xiaoyaofenfen 2022-12-19 19:41:13 +08:00
parent 6abab46db0
commit ea9279e45e
2 changed files with 19 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
"fmt"
"github.com/tickstep/aliyunpan-api/aliyunpan/apierror"
"github.com/tickstep/aliyunpan/cmder"
"github.com/tickstep/aliyunpan/internal/log"
"github.com/tickstep/aliyunpan/internal/plugins"
"github.com/tickstep/aliyunpan/internal/utils"
"github.com/tickstep/library-go/requester/rio/speeds"
@ -333,6 +334,9 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
// 获取当前插件
plugin, _ := pluginManger.GetPlugin()
// 上传记录器
fileRecorder := log.NewFileRecorder(config.GetLogDir() + "/upload_file_records.csv")
// 遍历指定的文件并创建上传任务
for _, curPath := range localPaths {
var walkFunc localfile.MyWalkFunc
@ -420,6 +424,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
IsOverwrite: opt.IsOverwrite,
UseInternalUrl: opt.UseInternalUrl,
GlobalSpeedsStat: globalSpeedsStat,
FileRecorder: fileRecorder,
}, opt.MaxRetry)
fmt.Printf("[%s] 加入上传队列: %s\n", taskinfo.Id(), file.LogicPath)
} else {

View File

@ -15,6 +15,7 @@ package panupload
import (
"fmt"
"github.com/tickstep/aliyunpan/internal/log"
"github.com/tickstep/aliyunpan/internal/plugins"
"github.com/tickstep/library-go/logger"
"os"
@ -71,6 +72,9 @@ type (
// 全局速度统计
GlobalSpeedsStat *speeds.Speeds
// 上传文件记录器
FileRecorder *log.FileRecorder
}
)
@ -239,6 +243,16 @@ func (utu *UploadTaskUnit) OnRetry(lastRunResult *taskframework.TaskUnitRunResul
func (utu *UploadTaskUnit) OnSuccess(lastRunResult *taskframework.TaskUnitRunResult) {
// 执行插件
utu.pluginCallback("success")
// 上传文件数据记录
if config.Config.FileRecordConfig == "1" {
utu.FileRecorder.Append(&log.FileRecordItem{
Status: "成功",
TimeStr: utils.NowTimeStr(),
FileSize: utu.LocalFileChecksum.LocalFileMeta.Length,
FilePath: utu.LocalFileChecksum.Path.LogicPath,
})
}
}
func (utu *UploadTaskUnit) OnFailed(lastRunResult *taskframework.TaskUnitRunResult) {