MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / GetFavicon

Function GetFavicon

pkg/faviconcache/faviconcache.go:58–86  ·  view source on GitHub ↗

--- GetFavicon --- GetFavicon takes a URL string and returns a base64-encoded src URL for an tag. If the favicon is already in cache and “fresh,” it returns it immediately. Otherwise it kicks off a background fetch (if one isn’t already in progress) and returns whatever is in the cache (which

(urlStr string)

Source from the content-addressed store, hash-verified

56// Otherwise it kicks off a background fetch (if one isn’t already in progress)
57// and returns whatever is in the cache (which may be empty).
58func GetFavicon(urlStr string) string {
59 // Parse the URL and extract the domain.
60 parsedURL, err := url.Parse(urlStr)
61 if err != nil {
62 log.Printf("GetFavicon: invalid URL %q: %v", urlStr, err)
63 return ""
64 }
65 domain := parsedURL.Hostname()
66 if domain == "" {
67 log.Printf("GetFavicon: no hostname found in URL %q", urlStr)
68 return ""
69 }
70
71 // Try to get from our cache.
72 item, found := GetFromCache(domain)
73 if found {
74 // If the cached entry is not stale, return it.
75 if time.Since(item.LastFetched) < cacheDuration {
76 return item.Data
77 }
78 }
79
80 // Either the item was not found or it’s stale:
81 // Launch an async fetch if one isn’t already running for this domain.
82 triggerAsyncFetch(domain)
83
84 // Return the cached value (even if stale or empty).
85 return item.Data
86}
87
88// triggerAsyncFetch starts a goroutine to update the favicon cache
89// for the given domain if one isn’t already in progress.

Callers 1

fetchBookmarkSuggestionsFunction · 0.92

Calls 3

GetFromCacheFunction · 0.85
triggerAsyncFetchFunction · 0.85
ParseMethod · 0.80

Tested by

no test coverage detected