v0.15.0 9006957

compiler.go RawHistoryFolder

1package filtering
2
3import (
4	"bufio"
5	"context"
6	"fmt"
7	"strings"
8	"time"
9
10	"github.com/bnema/dumber/internal/filtering/converter"
11	"github.com/bnema/dumber/internal/logging"
12)
13
14// DefaultFilterCompiler implements FilterCompiler using the converter package
15type DefaultFilterCompiler struct{}
16
17// NewDefaultFilterCompiler creates a new default filter compiler
18func NewDefaultFilterCompiler() *DefaultFilterCompiler {
19	return &DefaultFilterCompiler{}
20}
21
22// CompileFromSources downloads and compiles filters from multiple URLs
23func (dfc *DefaultFilterCompiler) CompileFromSources(ctx context.Context, sources []string) (*CompiledFilters, error) {
24	compiled := NewCompiledFilters()
25
26	for _, url := range sources {
27		select {
28		case <-ctx.Done():
29			return nil, ctx.Err()
30		default:
31		}
32
33		filters, err := dfc.downloadAndCompile(ctx, url)
34		if err != nil {
35			logging.Error(fmt.Sprintf("Failed to compile from %s: %v", url, err))
36			continue
37		}
38
39		compiled.Merge(filters)
40	}
41
42	compiled.Version = fmt.Sprintf("compiled-%d", time.Now().Unix())
43	compiled.CompiledAt = time.Now()
44
45	return compiled, nil
46}
47
48// CompileFromData compiles filters from raw data bytes
49func (dfc *DefaultFilterCompiler) CompileFromData(data []byte) (*CompiledFilters, error) {
50	compiled := NewCompiledFilters()
51
52	// Use local converter for thread safety (avoid shared state)
53	conv := converter.NewFilterConverter()
54
55	// Parse line by line
56	scanner := bufio.NewScanner(strings.NewReader(string(data)))
57	lineCount := 0
58
59	for scanner.Scan() {
60		line := scanner.Text()
61		lineCount++
62
63		// Convert each line
64		if err := conv.ConvertEasyListLine(line); err != nil {
65			logging.Debug(fmt.Sprintf("Failed to convert filter line: %s, error: %v", line, err))
66			continue
67		}
68	}
69
70	if err := scanner.Err(); err != nil {
71		return nil, fmt.Errorf("error reading filter data: %w", err)
72	}
73
74	// Get compiled rules from converter
75	compiled.NetworkRules = conv.GetNetworkRules()
76	compiled.CosmeticRules = conv.GetCosmeticRules()
77	compiled.GenericHiding = conv.GetGenericHiding()
78	compiled.CompiledAt = time.Now()
79	compiled.Version = fmt.Sprintf("data-compile-%d", time.Now().Unix())
80
81	logging.Info(fmt.Sprintf("Compiled %d filter lines into %d network rules and %d cosmetic rules",
82		lineCount, len(compiled.NetworkRules), len(compiled.CosmeticRules)))
83
84	return compiled, nil
85}
86
87// downloadAndCompile downloads and compiles a single filter list
88func (dfc *DefaultFilterCompiler) downloadAndCompile(ctx context.Context, url string) (*CompiledFilters, error) {
89	// This would implement HTTP download - for now, return empty filters
90	logging.Debug(fmt.Sprintf("Would download and compile from %s", url))
91
92	compiled := NewCompiledFilters()
93	compiled.Version = fmt.Sprintf("stub-%d", time.Now().Unix())
94	compiled.CompiledAt = time.Now()
95
96	return compiled, nil
97}

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