Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Improve logging

Neeraj Guptaae1b1917658f
diff --git a/pkg/download.go b/pkg/download.go
index 2e456b92b7..05b991dccc 100644
--- a/pkg/download.go
+++ b/pkg/download.go
@@ -4,6 +4,7 @@ import (
"archive/zip"
"cli-go/internal/crypto"
"cli-go/pkg/model"
+ "cli-go/utils"
"cli-go/utils/encoding"
"context"
"fmt"
@@ -21,7 +22,7 @@ func (c *ClICtrl) downloadAndDecrypt(
) (*string, error) {
dir := c.tempFolder
downloadPath := fmt.Sprintf("%s/%d", dir, file.ID)
- log.Printf("Downloading file %d to %s", file.ID, downloadPath)
+ log.Printf("Downloading %s (%s)", file.GetTitle(), utils.ByteCountDecimal(file.Info.FileSize))
err := c.Client.DownloadFile(ctx, file.ID, downloadPath)
if err != nil {
return nil, fmt.Errorf("error downloading file %d: %w", file.ID, err)
diff --git a/utils/time.go b/utils/time.go
index fcb61f8422..a86a9fc9f3 100644
--- a/utils/time.go
+++ b/utils/time.go
@@ -1,6 +1,7 @@
package utils
import (
+ "fmt"
"log"
"time"
)
@@ -9,3 +10,16 @@ func TimeTrack(start time.Time, name string) {
elapsed := time.Since(start)
log.Printf("%s took %s", name, elapsed)
}
+
+func ByteCountDecimal(b int64) string {
+ const unit = 1000
+ if b < unit {
+ return fmt.Sprintf("%d B", b)
+ }
+ div, exp := int64(unit), 0
+ for n := b / unit; n >= unit; n /= unit {
+ div *= unit
+ exp++
+ }
+ return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
+}