summaryrefslogtreecommitdiffstats
path: root/internal/formatter/buckets.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/formatter/buckets.go')
-rw-r--r--internal/formatter/buckets.go98
1 files changed, 76 insertions, 22 deletions
diff --git a/internal/formatter/buckets.go b/internal/formatter/buckets.go
index 9672b9d..2cc6b78 100644
--- a/internal/formatter/buckets.go
+++ b/internal/formatter/buckets.go
@@ -5,6 +5,7 @@ import (
"fmt"
"sort"
"strings"
+ "time"
"git.db.org.ai/dborg/internal/models"
"git.db.org.ai/dborg/internal/utils"
@@ -346,23 +347,51 @@ func formatSingleFile(file map[string]any, index int) {
if name, ok := file["file"].(string); ok && name != "" {
fileName = name
- } else if u, ok := file["url"].(string); ok && u != "" {
+ } else if name, ok := file["filename"].(string); ok && name != "" {
+ fileName = name
+ }
+
+ if u, ok := file["url"].(string); ok && u != "" {
url = u
- fileName = extractFileNameFromURL(u)
+ if fileName == "unknown" {
+ fileName = extractFileNameFromURL(u)
+ }
}
fmt.Printf(" %s %s\n", Gray(fmt.Sprintf("%d.", index)), formatFileName(fileName))
if url != "" {
- fmt.Printf(" %s: %s\n", Cyan("URL"), Dim(url))
+ fmt.Printf(" %s: %s\n", Cyan("URL"), Blue(url))
}
if size, ok := file["size"].(float64); ok && size > 0 {
fmt.Printf(" %s: %s\n", Cyan("Size"), formatFileSize(int64(size)))
}
- if modified, ok := file["lastModified"].(string); ok && modified != "" {
- fmt.Printf(" %s: %s\n", Cyan("Modified"), Dim(modified))
+ if modified, ok := file["lastModified"].(float64); ok && modified > 0 {
+ fmt.Printf(" %s: %s\n", Cyan("Modified"), formatLastModified(int64(modified)))
+ }
+
+ var metadata []string
+
+ if bucketType, ok := file["type"].(string); ok && bucketType != "" {
+ metadata = append(metadata, strings.ToUpper(bucketType))
+ }
+
+ if container, ok := file["container"].(string); ok && container != "" {
+ metadata = append(metadata, fmt.Sprintf("Container: %s", container))
+ }
+
+ if bucketId, ok := file["bucketId"].(float64); ok && bucketId > 0 {
+ metadata = append(metadata, fmt.Sprintf("Bucket ID: %d", int64(bucketId)))
+ }
+
+ if fileId, ok := file["id"].(string); ok && fileId != "" {
+ metadata = append(metadata, fmt.Sprintf("File ID: %s", fileId))
+ }
+
+ if len(metadata) > 0 {
+ fmt.Printf(" %s: %s\n", Cyan("Info"), Gray(strings.Join(metadata, " • ")))
}
}
@@ -393,23 +422,6 @@ func formatFileName(name string) string {
return Gray("(unnamed file)")
}
- parts := strings.Split(name, "/")
- if len(parts) > 1 {
- path := strings.Join(parts[:len(parts)-1], "/")
- file := parts[len(parts)-1]
-
- if file == "" {
- file = "(directory)"
- }
-
- file = decodeURLEncoding(file)
-
- ext := getFileExtension(file)
- color := getExtensionColor(ext)
-
- return Gray(path+"/") + Colorize(file, color)
- }
-
name = decodeURLEncoding(name)
ext := getFileExtension(name)
color := getExtensionColor(ext)
@@ -468,3 +480,45 @@ func formatFileSize(bytes int64) string {
return Colorize(FormatBytes(bytes), color)
}
+
+func formatLastModified(timestamp int64) string {
+ t := time.Unix(timestamp, 0)
+ now := time.Now()
+
+ duration := now.Sub(t)
+ days := int(duration.Hours() / 24)
+
+ var timeStr string
+ var color string
+
+ switch {
+ case days == 0:
+ timeStr = "Today"
+ color = ColorGreen
+ case days == 1:
+ timeStr = "Yesterday"
+ color = ColorGreen
+ case days < 7:
+ timeStr = fmt.Sprintf("%d days ago", days)
+ color = ColorGreen
+ case days < 30:
+ weeks := days / 7
+ timeStr = fmt.Sprintf("%d weeks ago", weeks)
+ color = ColorCyan
+ case days < 365:
+ months := days / 30
+ timeStr = fmt.Sprintf("%d months ago", months)
+ color = ColorYellow
+ default:
+ years := days / 365
+ if years == 1 {
+ timeStr = "1 year ago"
+ } else {
+ timeStr = fmt.Sprintf("%d years ago", years)
+ }
+ color = ColorRed
+ }
+
+ dateStr := t.Format("2006-01-02 15:04:05")
+ return Colorize(timeStr, color) + Gray(fmt.Sprintf(" (%s)", dateStr))
+}