feat: 单场秀内的图片进度也上报(x/y 张)

一场秀几十到几百张图,按批处理要十几分钟,只报场次会让进度十几分钟不动。
media.UploadAllProgress 每批回调一次,spider 据此把「正在抓 X(32/50 张)」报给后台。
This commit is contained in:
toom1996
2026-10-25 21:02:52 +08:00
parent fb9b6c4f6e
commit 1ead57dd22
2 changed files with 20 additions and 3 deletions

View File

@ -77,6 +77,15 @@ func New(client *ingest.Client, prefix string, concurrency int) *Uploader {
// UploadAll 并发完成「下载 → 生成 key → 预签名 → PUT」,返回与 urls 下标一一对应的结果。
// 单张失败不影响其他张:该下标 Err 非空,调用方据此对这张回退成 URL 上报。
func (u *Uploader) UploadAll(ctx context.Context, urls []string) []Result {
return u.UploadAllProgress(ctx, urls, nil)
}
// UploadAllProgress 与 UploadAll 相同,但每完成一批回调一次 onBatch(done, total)。
//
// 用途:一场秀几十到几百张图,按批处理要跑十几分钟。
// 上层靠这个回调把「传到第几张」显示到后台,否则进度只能一场一跳,
// 中间十几分钟界面上什么都看不出。
func (u *Uploader) UploadAllProgress(ctx context.Context, urls []string, onBatch func(done, total int)) []Result {
results := make([]Result, len(urls))
if len(urls) == 0 {
return results
@ -93,6 +102,9 @@ func (u *Uploader) UploadAll(ctx context.Context, urls []string) []Result {
end = len(urls)
}
u.uploadBatch(ctx, urls, results, start, end)
if onBatch != nil {
onBatch(end, len(urls))
}
}
return results
}