Skip to content

Commit 2dbebaa

Browse files
authored
refactor: Optimize traversal browser data logic (#311)
* refactor: Refactor package names and imports for better code organization. * refactor: Package imports and variable types for consistency * chore: Disable unused-parameter rule in revive. * refactor: Refactor and organize data extraction and browserdata parse. * fix: rename wrong error message info
1 parent fc98b8f commit 2dbebaa

35 files changed

+449
-353
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ results/
191191

192192
hack-browser-data
193193
!/cmd/hack-browser-data
194-
!/browsingdata/history
195-
!/browsingdata/history/history.go
196-
!/browsingdata/history/history_test.go
194+
!/browserdata/history
195+
!/browserdata/history/history.go
196+
!/browserdata/history/history_test.go
197197

198198
# github action
199199
!/.github/workflows/unittest.yml

.golangci.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
run:
22
timeout: '5m'
3-
skip-dirs:
4-
- 'assets'
53
allow-parallel-runners: true
64
modules-download-mode: 'readonly'
75

@@ -96,6 +94,8 @@ issues:
9694
- path: browser/browser\.go
9795
linters:
9896
- 'unused'
97+
exclude-dirs:
98+
- 'vendor'
9999
max-issues-per-linter: 0
100100
max-same-issues: 0
101101

@@ -194,33 +194,33 @@ linters-settings:
194194
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`.
195195
# By default, list of stable checks is used.
196196
enabled-checks:
197-
- nestingReduce
198-
- unnamedResult
197+
# - nestingReduce
198+
# - unnamedResult
199199
- ruleguard
200-
- captLocal
201-
- elseif
202-
- ifElseChain
200+
# - captLocal
201+
# - elseif
202+
# - ifElseChain
203203
- rangeExprCopy
204-
- tooManyResultsChecker
205-
- truncateCmp
206-
- underef
204+
# - tooManyResultsChecker
205+
# - truncateCmp
206+
# - underef
207207
# Which checks should be disabled; can't be combined with 'enabled-checks'.
208208
# Default: []
209209
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
210210
# See https://github.com/go-critic/go-critic#usage -> section "Tags".
211211
# Default: []
212212
enabled-tags:
213213
- diagnostic
214-
- style
215-
- performance
216-
- experimental
217-
- opinionated
218-
disabled-tags:
219-
- diagnostic
220-
- style
221-
- performance
222-
- experimental
214+
# - style
215+
# - performance
216+
# - experimental
223217
- opinionated
218+
# disabled-tags:
219+
# - diagnostic
220+
# - style
221+
# - performance
222+
# - experimental
223+
# - opinionated
224224
# Settings passed to gocritic.
225225
# The settings key is the name of a supported gocritic checker.
226226
# The list of supported checkers can be find in https://go-critic.github.io/overview.
@@ -357,4 +357,8 @@ linters-settings:
357357
constant-kind: true
358358
# DEPRECATED Suggest the use of syslog.Priority.
359359
# Default: false
360-
syslog-priority: true
360+
syslog-priority: true
361+
revive:
362+
rules:
363+
- name: unused-parameter
364+
disabled: true

browser/browser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/moond4rk/hackbrowserdata/browser/chromium"
1010
"github.com/moond4rk/hackbrowserdata/browser/firefox"
11-
"github.com/moond4rk/hackbrowserdata/browsingdata"
11+
"github.com/moond4rk/hackbrowserdata/browserdata"
1212
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
1313
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
1414
)
@@ -17,7 +17,7 @@ type Browser interface {
1717
// Name is browser's name
1818
Name() string
1919
// BrowsingData returns all browsing data in the browser.
20-
BrowsingData(isFullExport bool) (*browsingdata.Data, error)
20+
BrowsingData(isFullExport bool) (*browserdata.BrowserData, error)
2121
}
2222

2323
// PickBrowsers returns a list of browsers that match the name and profile.
@@ -47,7 +47,7 @@ func pickChromium(name, profile string) []Browser {
4747
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
4848
continue
4949
}
50-
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.items)
50+
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.dataTypes)
5151
if err != nil {
5252
slog.Error("new chromium error", "err", err)
5353
continue
@@ -65,7 +65,7 @@ func pickChromium(name, profile string) []Browser {
6565
if !fileutil.IsDirExists(filepath.Clean(profile)) {
6666
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
6767
}
68-
chromiumList, err := chromium.New(c.name, c.storage, profile, c.items)
68+
chromiumList, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
6969
if err != nil {
7070
slog.Error("new chromium error", "err", err)
7171
}
@@ -93,7 +93,7 @@ func pickFirefox(name, profile string) []Browser {
9393
continue
9494
}
9595

96-
if multiFirefox, err := firefox.New(profile, v.items); err == nil {
96+
if multiFirefox, err := firefox.New(profile, v.dataTypes); err == nil {
9797
for _, b := range multiFirefox {
9898
slog.Warn("find browser success", "browser", b.Name())
9999
browsers = append(browsers, b)

browser/browser_darwin.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,93 @@
33
package browser
44

55
import (
6-
"github.com/moond4rk/hackbrowserdata/item"
6+
"github.com/moond4rk/hackbrowserdata/types"
77
)
88

99
var (
1010
chromiumList = map[string]struct {
1111
name string
1212
storage string
1313
profilePath string
14-
items []item.Item
14+
dataTypes []types.DataType
1515
}{
1616
"chrome": {
1717
name: chromeName,
1818
storage: chromeStorageName,
1919
profilePath: chromeProfilePath,
20-
items: item.DefaultChromium,
20+
dataTypes: types.DefaultChromiumTypes,
2121
},
2222
"edge": {
2323
name: edgeName,
2424
storage: edgeStorageName,
2525
profilePath: edgeProfilePath,
26-
items: item.DefaultChromium,
26+
dataTypes: types.DefaultChromiumTypes,
2727
},
2828
"chromium": {
2929
name: chromiumName,
3030
storage: chromiumStorageName,
3131
profilePath: chromiumProfilePath,
32-
items: item.DefaultChromium,
32+
dataTypes: types.DefaultChromiumTypes,
3333
},
3434
"chrome-beta": {
3535
name: chromeBetaName,
3636
storage: chromeBetaStorageName,
3737
profilePath: chromeBetaProfilePath,
38-
items: item.DefaultChromium,
38+
dataTypes: types.DefaultChromiumTypes,
3939
},
4040
"opera": {
4141
name: operaName,
4242
profilePath: operaProfilePath,
4343
storage: operaStorageName,
44-
items: item.DefaultChromium,
44+
dataTypes: types.DefaultChromiumTypes,
4545
},
4646
"opera-gx": {
4747
name: operaGXName,
4848
profilePath: operaGXProfilePath,
4949
storage: operaStorageName,
50-
items: item.DefaultChromium,
50+
dataTypes: types.DefaultChromiumTypes,
5151
},
5252
"vivaldi": {
5353
name: vivaldiName,
5454
storage: vivaldiStorageName,
5555
profilePath: vivaldiProfilePath,
56-
items: item.DefaultChromium,
56+
dataTypes: types.DefaultChromiumTypes,
5757
},
5858
"coccoc": {
5959
name: coccocName,
6060
storage: coccocStorageName,
6161
profilePath: coccocProfilePath,
62-
items: item.DefaultChromium,
62+
dataTypes: types.DefaultChromiumTypes,
6363
},
6464
"brave": {
6565
name: braveName,
6666
profilePath: braveProfilePath,
6767
storage: braveStorageName,
68-
items: item.DefaultChromium,
68+
dataTypes: types.DefaultChromiumTypes,
6969
},
7070
"yandex": {
7171
name: yandexName,
7272
storage: yandexStorageName,
7373
profilePath: yandexProfilePath,
74-
items: item.DefaultYandex,
74+
dataTypes: types.DefaultYandexTypes,
7575
},
7676
"arc": {
7777
name: arcName,
7878
profilePath: arcProfilePath,
7979
storage: arcStorageName,
80-
items: item.DefaultChromium,
80+
dataTypes: types.DefaultChromiumTypes,
8181
},
8282
}
8383
firefoxList = map[string]struct {
8484
name string
8585
storage string
8686
profilePath string
87-
items []item.Item
87+
dataTypes []types.DataType
8888
}{
8989
"firefox": {
9090
name: firefoxName,
9191
profilePath: firefoxProfilePath,
92-
items: item.DefaultFirefox,
92+
dataTypes: types.DefaultFirefoxTypes,
9393
},
9494
}
9595
)

browser/browser_linux.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,69 @@
33
package browser
44

55
import (
6-
"github.com/moond4rk/hackbrowserdata/item"
6+
"github.com/moond4rk/hackbrowserdata/types"
77
)
88

99
var (
1010
chromiumList = map[string]struct {
1111
name string
1212
storage string
1313
profilePath string
14-
items []item.Item
14+
dataTypes []types.DataType
1515
}{
1616
"chrome": {
1717
name: chromeName,
1818
storage: chromeStorageName,
1919
profilePath: chromeProfilePath,
20-
items: item.DefaultChromium,
20+
dataTypes: types.DefaultChromiumTypes,
2121
},
2222
"edge": {
2323
name: edgeName,
2424
storage: edgeStorageName,
2525
profilePath: edgeProfilePath,
26-
items: item.DefaultChromium,
26+
dataTypes: types.DefaultChromiumTypes,
2727
},
2828
"chromium": {
2929
name: chromiumName,
3030
storage: chromiumStorageName,
3131
profilePath: chromiumProfilePath,
32-
items: item.DefaultChromium,
32+
dataTypes: types.DefaultChromiumTypes,
3333
},
3434
"chrome-beta": {
3535
name: chromeBetaName,
3636
storage: chromeBetaStorageName,
3737
profilePath: chromeBetaProfilePath,
38-
items: item.DefaultChromium,
38+
dataTypes: types.DefaultChromiumTypes,
3939
},
4040
"opera": {
4141
name: operaName,
4242
profilePath: operaProfilePath,
4343
storage: operaStorageName,
44-
items: item.DefaultChromium,
44+
dataTypes: types.DefaultChromiumTypes,
4545
},
4646
"vivaldi": {
4747
name: vivaldiName,
4848
storage: vivaldiStorageName,
4949
profilePath: vivaldiProfilePath,
50-
items: item.DefaultChromium,
50+
dataTypes: types.DefaultChromiumTypes,
5151
},
5252
"brave": {
5353
name: braveName,
5454
profilePath: braveProfilePath,
5555
storage: braveStorageName,
56-
items: item.DefaultChromium,
56+
dataTypes: types.DefaultChromiumTypes,
5757
},
5858
}
5959
firefoxList = map[string]struct {
6060
name string
6161
storage string
6262
profilePath string
63-
items []item.Item
63+
dataTypes []types.DataType
6464
}{
6565
"firefox": {
6666
name: firefoxName,
6767
profilePath: firefoxProfilePath,
68-
items: item.DefaultFirefox,
68+
dataTypes: types.DefaultFirefoxTypes,
6969
},
7070
}
7171
)

0 commit comments

Comments
 (0)