feat(task): enhance download progress reporting and add speed calculation

This commit is contained in:
krau
2025-02-12 11:06:25 +08:00
parent a32bf43cdc
commit a17492d4ae
3 changed files with 19 additions and 5 deletions

View File

@@ -52,7 +52,7 @@ func cleanCacheFile(destPath string) {
func calculateBarTotalCount(fileSize int64) int {
barTotalCount := 5
if fileSize > 1024*1024*1000 {
barTotalCount = 50
barTotalCount = 40
} else if fileSize > 1024*1024*500 {
barTotalCount = 20
} else if fileSize > 1024*1024*200 {
@@ -60,3 +60,12 @@ func calculateBarTotalCount(fileSize int64) int {
}
return barTotalCount
}
func getSpeed(bytesRead int64, startTime time.Time) string {
if startTime.IsZero() {
return "0MB/s"
}
elapsed := time.Since(startTime)
speed := float64(bytesRead) / 1024 / 1024 / elapsed.Seconds()
return fmt.Sprintf("%.2fMB/s", speed)
}