Explorar o código

feat(ui): clean up Discord CDN display names

URL-encoded URLs as filenames (e.g., substack proxied images) now show
as "image.ext" instead of the garbled encoded string. UUID filenames
similarly show as "image.ext". Long filenames are truncated to 40 chars.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude hai 1 mes
pai
achega
b5ba2919d7
Modificáronse 1 ficheiros con 42 adicións e 2 borrados
  1. 42 2
      internal/ui/util.go

+ 42 - 2
internal/ui/util.go

@@ -146,10 +146,10 @@ func LinkDisplayText(raw string) string {
 	p := strings.TrimRight(parsed.EscapedPath(), "/")
 	segments := strings.Split(strings.TrimLeft(p, "/"), "/")
 
-	// Discord CDN / media — show filename
+	// Discord CDN / media — show cleaned filename
 	if host == "cdn.discordapp.com" || host == "media.discordapp.net" {
 		if base := path.Base(p); base != "" && base != "." && base != "/" {
-			return base
+			return cdnDisplayName(base)
 		}
 	}
 
@@ -206,6 +206,46 @@ func LinkDisplayText(raw string) string {
 	}
 }
 
+// cdnDisplayName cleans up Discord CDN filenames for display.
+// Handles URL-encoded URLs used as filenames and UUID filenames.
+func cdnDisplayName(name string) string {
+	ext := path.Ext(name)
+	stem := strings.TrimSuffix(name, ext)
+
+	// URL-encoded URL as filename (e.g., "https3A2F2F...512x512.png")
+	if strings.HasPrefix(stem, "http") && strings.Contains(stem, "2F") {
+		return "image" + ext
+	}
+
+	// UUID filename (e.g., "c02b97b3-813f-4c03-904a-0bd4240f2c10.jpg")
+	if isUUID(stem) {
+		return "image" + ext
+	}
+
+	// Truncate long filenames
+	if len(name) > 40 {
+		return name[:37] + "..." + ext
+	}
+
+	return name
+}
+
+func isUUID(s string) bool {
+	if len(s) != 36 {
+		return false
+	}
+	for i, c := range s {
+		if i == 8 || i == 13 || i == 18 || i == 23 {
+			if c != '-' {
+				return false
+			}
+		} else if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
+			return false
+		}
+	}
+	return true
+}
+
 func MergeStyle(base, overlay tcell.Style) tcell.Style {
 	fg := overlay.GetForeground()
 	if fg == tcell.ColorDefault {