Skip to content

Commit

Permalink
Add size to the output
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Dec 5, 2024
1 parent 5b65537 commit 0d064f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/publicdata/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql"
"encoding/json"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -59,6 +60,23 @@ func (e *indexer) UpdateIndexFile(ctx context.Context, prefix string, recursive
sb.WriteString("\">")
sb.WriteString(name)
sb.WriteString("</a>")
if obj.Size > 0 {
size := float64(obj.Size)
unit := " B"
if size > 1024 {
size /= 1024
unit = " KB"
}
if size > 1024 {
size /= 1024
unit = " MB"
}
if size > 1024 {
size /= 1024
unit = " GB"
}
sb.WriteString(fmt.Sprintf(" (%.1f%s)", size, unit))
}
sb.WriteString("</li>\n")
if strings.HasSuffix(obj.Key, "/") && recursive {
e.UpdateIndexFile(ctx, obj.Key, recursive)
Expand Down

0 comments on commit 0d064f6

Please sign in to comment.