v0.26.0 ae3a77a

fetcher.go RawHistoryFolder

1// Package favicon provides favicon fetching and caching infrastructure.
2package favicon
3
4import (
5	"context"
6	"fmt"
7	"io"
8	"net/http"
9	"net/url"
10	"time"
11
12	"github.com/bnema/dumber/internal/logging"
13)
14
15const (
16	// DuckDuckGo favicon API URL template.
17	duckduckgoFaviconURL = "https://icons.duckduckgo.com/ip3/%s.ico"
18	// HTTP client timeout for favicon fetch.
19	fetchTimeout = 5 * time.Second
20)
21
22// Fetcher retrieves favicons from external APIs.
23type Fetcher struct {
24	client *http.Client
25}
26
27// NewFetcher creates a new Fetcher with default HTTP client settings.
28func NewFetcher() *Fetcher {
29	return &Fetcher{
30		client: &http.Client{
31			Timeout: fetchTimeout,
32		},
33	}
34}
35
36// Fetch retrieves favicon bytes for a domain from DuckDuckGo's favicon API.
37// Returns nil bytes if the favicon cannot be fetched.
38func (f *Fetcher) Fetch(ctx context.Context, domain string) ([]byte, error) {
39	if domain == "" {
40		return nil, nil
41	}
42
43	log := logging.FromContext(ctx)
44	faviconURL := fmt.Sprintf(duckduckgoFaviconURL, url.QueryEscape(domain))
45
46	log.Debug().Str("url", faviconURL).Msg("fetching favicon from DuckDuckGo")
47
48	req, err := http.NewRequestWithContext(ctx, http.MethodGet, faviconURL, http.NoBody)
49	if err != nil {
50		log.Debug().Err(err).Msg("failed to create favicon request")
51		return nil, err
52	}
53
54	resp, err := f.client.Do(req)
55	if err != nil {
56		log.Debug().Err(err).Str("domain", domain).Msg("failed to fetch favicon from DuckDuckGo")
57		return nil, err
58	}
59	defer func() {
60		if closeErr := resp.Body.Close(); closeErr != nil {
61			log.Debug().Err(closeErr).Str("domain", domain).Msg("failed to close favicon response body")
62		}
63	}()
64
65	if resp.StatusCode != http.StatusOK {
66		log.Debug().Int("status", resp.StatusCode).Str("domain", domain).Msg("DuckDuckGo favicon API returned non-OK status")
67		return nil, nil
68	}
69
70	data, err := io.ReadAll(resp.Body)
71	if err != nil {
72		log.Debug().Err(err).Str("domain", domain).Msg("failed to read favicon response")
73		return nil, err
74	}
75
76	if len(data) == 0 {
77		log.Debug().Str("domain", domain).Msg("empty favicon response from DuckDuckGo")
78		return nil, nil
79	}
80
81	log.Debug().Str("domain", domain).Int("bytes", len(data)).Msg("favicon fetched from DuckDuckGo")
82	return data, nil
83}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close