From 602c4c85466edd482f1bbf8bf18b6e7917cb56c9 Mon Sep 17 00:00:00 2001 From: YGXB_net Date: Tue, 28 Apr 2026 01:35:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(uploader):=20=E4=BF=AE=E5=A4=8D=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E8=BF=9B=E5=BA=A6=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在处理文件前先清除之前的进度记录 - 将循环变量名从 k, v 更改为 fileName, lines 提高可读性 - 移动进度初始化位置确保每个文件都有正确的进度跟踪 - 删除重复的进度清除操作避免潜在的数据丢失问题 --- .gitea/workflows/build_tool.yaml | 4 +++- internal/uploader/uploader.go | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/build_tool.yaml b/.gitea/workflows/build_tool.yaml index 89a654a..757ae74 100644 --- a/.gitea/workflows/build_tool.yaml +++ b/.gitea/workflows/build_tool.yaml @@ -52,9 +52,11 @@ jobs: - name: 构建上传工具 run: | set -x + git_hash=$(git rev-parse --short "$GITHUB_SHA") + build_date=$(TZ=Asia/Shanghai date +"%Y%m%d%H%M") wails build \ -platform windows/amd64 \ - -ldflags "-X 'main.version=$(TZ=Asia/Shanghai date +"%m%d%H%M")'" \ + -ldflags "-X 'main.version=$build_date-$git_hash'" \ -o 上传工具.exe - name: 上传构建文件 diff --git a/internal/uploader/uploader.go b/internal/uploader/uploader.go index 8d17d44..25d12c1 100644 --- a/internal/uploader/uploader.go +++ b/internal/uploader/uploader.go @@ -118,7 +118,6 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) { fileLines[filepath.Base(filePath)] = lineCount isAllEmpty = false AddLog(logChan, fmt.Sprintf("%s 文件行数:%v", filepath.Base(filePath), lineCount)) - progress.Store(filepath.Base(filePath), Progress{FileName: filepath.Base(filePath), Total: lineCount, Uploaded: 0, Percentage: 0}) } } if isAllEmpty { @@ -126,10 +125,12 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) { return } + progress.Clear() //添加文件上传任务参数(文件路径,文件行数) var tasks []Task - for k, v := range fileLines { - tasks = append(tasks, Task{FilePath: path + "/" + k, FileLines: v}) + for fileName, lines := range fileLines { + tasks = append(tasks, Task{FilePath: path + "/" + fileName, FileLines: lines}) + progress.Store(fileName, Progress{FileName: fileName, Total: lines, Uploaded: 0, Percentage: 0}) } // 使用 errgroup 控制同时处理的文件数,并开始上传文件任务 @@ -178,7 +179,6 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) { } AddLog(logChan, fmt.Sprintf("上传完成,耗时:%s", time.Since(start).String())) - progress.Clear() } }