1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
package formatter
import (
"fmt"
"strings"
"git.db.org.ai/dborg/internal/models"
"git.db.org.ai/dborg/internal/utils"
)
func FormatUsernameSiteResult(result *models.SiteResult) error {
if result.Status == "found" {
fmt.Printf("%s | %s",
Green("✓ FOUND"),
result.SiteName)
if result.URL != "" {
fmt.Printf(" | %s", Blue(result.URL))
}
fmt.Println()
if len(result.Metadata) > 0 {
fmt.Print(formatMetadata(result.Metadata))
}
}
return nil
}
func FormatUsernameResults(response *models.USRSXResponse, asJSON bool) error {
if asJSON {
return utils.PrintJSON(response)
}
if response.Error != "" {
return fmt.Errorf("%s", response.Error)
}
if response.Message != "" {
return nil
}
if len(response.Results) == 0 {
return nil
}
for _, result := range response.Results {
if result.Status == "found" {
fmt.Printf("%s | %s",
Green("✓ FOUND"),
result.SiteName)
if result.URL != "" {
fmt.Printf(" | %s", Blue(result.URL))
}
fmt.Println()
if len(result.Metadata) > 0 {
fmt.Print(formatMetadata(result.Metadata))
}
}
}
return nil
}
func formatMetadata(metadata map[string]interface{}) string {
var lines []string
boxStyle := Dim(" ├─ ")
labelStyle := Dim
if displayName, ok := metadata["display_name"].(string); ok && displayName != "" {
lines = append(lines, boxStyle+labelStyle("Name: ")+displayName)
}
if bio, ok := metadata["bio"].(string); ok && bio != "" {
bioPreview := bio
if len(bioPreview) > 100 {
bioPreview = bioPreview[:97] + "..."
}
lines = append(lines, boxStyle+labelStyle("Bio: ")+bioPreview)
}
if avatar, ok := metadata["avatar_url"].(string); ok && avatar != "" {
lines = append(lines, boxStyle+labelStyle("Avatar: ")+avatar)
}
if location, ok := metadata["location"].(string); ok && location != "" {
lines = append(lines, boxStyle+labelStyle("Location: ")+location)
}
if website, ok := metadata["website"].(string); ok && website != "" {
lines = append(lines, boxStyle+labelStyle("Website: ")+website)
}
if joinDate, ok := metadata["join_date"].(string); ok && joinDate != "" {
lines = append(lines, boxStyle+labelStyle("Joined: ")+joinDate)
}
if followers, ok := metadata["follower_count"].(float64); ok && followers > 0 {
lines = append(lines, boxStyle+labelStyle("Followers: ")+fmt.Sprintf("%d", int(followers)))
}
if following, ok := metadata["following_count"].(float64); ok && following > 0 {
lines = append(lines, boxStyle+labelStyle("Following: ")+fmt.Sprintf("%d", int(following)))
}
if verified, ok := metadata["is_verified"].(bool); ok && verified {
lines = append(lines, boxStyle+labelStyle("Verified: ")+Green("✓ Yes"))
}
if additionalLinks, ok := metadata["additional_links"].(map[string]interface{}); ok && len(additionalLinks) > 0 {
linkCount := 0
linkLines := []string{}
for key, value := range additionalLinks {
if strVal, ok := value.(string); ok {
linkLines = append(linkLines, Dim(" ├─ ")+labelStyle(key+": ")+strVal)
linkCount++
}
}
if linkCount > 0 {
lastBoxStyle := Dim(" └─ ")
lines = append(lines, lastBoxStyle+labelStyle("Links:"))
for i, linkLine := range linkLines {
if i == linkCount-1 {
linkLine = strings.Replace(linkLine, "├─", "└─", 1)
}
lines = append(lines, linkLine)
}
}
} else {
if len(lines) > 0 {
lastIdx := len(lines) - 1
lines[lastIdx] = strings.Replace(lines[lastIdx], "├─", "└─", 1)
}
}
if len(lines) > 0 {
return strings.Join(lines, "\n") + "\n"
}
return ""
}
|