Skip to content

Commit

Permalink
refactor: Optimize traversal browser data logic (#311)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
moonD4rk committed Apr 12, 2024
1 parent c31cf60 commit 536f208
Show file tree
Hide file tree
Showing 35 changed files with 449 additions and 353 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ results/

hack-browser-data
!/cmd/hack-browser-data
!/browsingdata/history
!/browsingdata/history/history.go
!/browsingdata/history/history_test.go
!/browserdata/history
!/browserdata/history/history.go
!/browserdata/history/history_test.go

# github action
!/.github/workflows/unittest.yml
Expand Down
44 changes: 24 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
run:
timeout: '5m'
skip-dirs:
- 'assets'
allow-parallel-runners: true
modules-download-mode: 'readonly'

Expand Down Expand Up @@ -96,6 +94,8 @@ issues:
- path: browser/browser\.go
linters:
- 'unused'
exclude-dirs:
- 'vendor'
max-issues-per-linter: 0
max-same-issues: 0

Expand Down Expand Up @@ -194,33 +194,33 @@ linters-settings:
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`.
# By default, list of stable checks is used.
enabled-checks:
- nestingReduce
- unnamedResult
# - nestingReduce
# - unnamedResult
- ruleguard
- captLocal
- elseif
- ifElseChain
# - captLocal
# - elseif
# - ifElseChain
- rangeExprCopy
- tooManyResultsChecker
- truncateCmp
- underef
# - tooManyResultsChecker
# - truncateCmp
# - underef
# Which checks should be disabled; can't be combined with 'enabled-checks'.
# Default: []
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# See https://github.com/go-critic/go-critic#usage -> section "Tags".
# Default: []
enabled-tags:
- diagnostic
- style
- performance
- experimental
- opinionated
disabled-tags:
- diagnostic
- style
- performance
- experimental
# - style
# - performance
# - experimental
- opinionated
# disabled-tags:
# - diagnostic
# - style
# - performance
# - experimental
# - opinionated
# Settings passed to gocritic.
# The settings key is the name of a supported gocritic checker.
# The list of supported checkers can be find in https://go-critic.github.io/overview.
Expand Down Expand Up @@ -357,4 +357,8 @@ linters-settings:
constant-kind: true
# DEPRECATED Suggest the use of syslog.Priority.
# Default: false
syslog-priority: true
syslog-priority: true
revive:
rules:
- name: unused-parameter
disabled: true
10 changes: 5 additions & 5 deletions browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/moond4rk/hackbrowserdata/browser/chromium"
"github.com/moond4rk/hackbrowserdata/browser/firefox"
"github.com/moond4rk/hackbrowserdata/browsingdata"
"github.com/moond4rk/hackbrowserdata/browserdata"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
)
Expand All @@ -17,7 +17,7 @@ type Browser interface {
// Name is browser's name
Name() string
// BrowsingData returns all browsing data in the browser.
BrowsingData(isFullExport bool) (*browsingdata.Data, error)
BrowsingData(isFullExport bool) (*browserdata.BrowserData, error)
}

// PickBrowsers returns a list of browsers that match the name and profile.
Expand Down Expand Up @@ -47,7 +47,7 @@ func pickChromium(name, profile string) []Browser {
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
continue
}
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.items)
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.dataTypes)
if err != nil {
slog.Error("new chromium error", "err", err)
continue
Expand All @@ -65,7 +65,7 @@ func pickChromium(name, profile string) []Browser {
if !fileutil.IsDirExists(filepath.Clean(profile)) {
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
}
chromiumList, err := chromium.New(c.name, c.storage, profile, c.items)
chromiumList, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
if err != nil {
slog.Error("new chromium error", "err", err)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func pickFirefox(name, profile string) []Browser {
continue
}

if multiFirefox, err := firefox.New(profile, v.items); err == nil {
if multiFirefox, err := firefox.New(profile, v.dataTypes); err == nil {
for _, b := range multiFirefox {
slog.Warn("find browser success", "browser", b.Name())
browsers = append(browsers, b)
Expand Down
30 changes: 15 additions & 15 deletions browser/browser_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,93 @@
package browser

import (
"github.com/moond4rk/hackbrowserdata/item"
"github.com/moond4rk/hackbrowserdata/types"
)

var (
chromiumList = map[string]struct {
name string
storage string
profilePath string
items []item.Item
dataTypes []types.DataType
}{
"chrome": {
name: chromeName,
storage: chromeStorageName,
profilePath: chromeProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"edge": {
name: edgeName,
storage: edgeStorageName,
profilePath: edgeProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"chromium": {
name: chromiumName,
storage: chromiumStorageName,
profilePath: chromiumProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"chrome-beta": {
name: chromeBetaName,
storage: chromeBetaStorageName,
profilePath: chromeBetaProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"opera": {
name: operaName,
profilePath: operaProfilePath,
storage: operaStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"opera-gx": {
name: operaGXName,
profilePath: operaGXProfilePath,
storage: operaStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"vivaldi": {
name: vivaldiName,
storage: vivaldiStorageName,
profilePath: vivaldiProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"coccoc": {
name: coccocName,
storage: coccocStorageName,
profilePath: coccocProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"brave": {
name: braveName,
profilePath: braveProfilePath,
storage: braveStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"yandex": {
name: yandexName,
storage: yandexStorageName,
profilePath: yandexProfilePath,
items: item.DefaultYandex,
dataTypes: types.DefaultYandexTypes,
},
"arc": {
name: arcName,
profilePath: arcProfilePath,
storage: arcStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
}
firefoxList = map[string]struct {
name string
storage string
profilePath string
items []item.Item
dataTypes []types.DataType
}{
"firefox": {
name: firefoxName,
profilePath: firefoxProfilePath,
items: item.DefaultFirefox,
dataTypes: types.DefaultFirefoxTypes,
},
}
)
Expand Down
22 changes: 11 additions & 11 deletions browser/browser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@
package browser

import (
"github.com/moond4rk/hackbrowserdata/item"
"github.com/moond4rk/hackbrowserdata/types"
)

var (
chromiumList = map[string]struct {
name string
storage string
profilePath string
items []item.Item
dataTypes []types.DataType
}{
"chrome": {
name: chromeName,
storage: chromeStorageName,
profilePath: chromeProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"edge": {
name: edgeName,
storage: edgeStorageName,
profilePath: edgeProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"chromium": {
name: chromiumName,
storage: chromiumStorageName,
profilePath: chromiumProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"chrome-beta": {
name: chromeBetaName,
storage: chromeBetaStorageName,
profilePath: chromeBetaProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"opera": {
name: operaName,
profilePath: operaProfilePath,
storage: operaStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"vivaldi": {
name: vivaldiName,
storage: vivaldiStorageName,
profilePath: vivaldiProfilePath,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
"brave": {
name: braveName,
profilePath: braveProfilePath,
storage: braveStorageName,
items: item.DefaultChromium,
dataTypes: types.DefaultChromiumTypes,
},
}
firefoxList = map[string]struct {
name string
storage string
profilePath string
items []item.Item
dataTypes []types.DataType
}{
"firefox": {
name: firefoxName,
profilePath: firefoxProfilePath,
items: item.DefaultFirefox,
dataTypes: types.DefaultFirefoxTypes,
},
}
)
Expand Down
Loading

0 comments on commit 536f208

Please sign in to comment.