Skip to content

Commit 7b8e2a3

Browse files
committed
fix: filter result if exported data is empty
1 parent d1ae09d commit 7b8e2a3

9 files changed

Lines changed: 85 additions & 11 deletions

File tree

internal/browingdata/bookmark/bookmark.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,23 @@ func getBookmarkChildren(value gjson.Result, w *ChromiumBookmark) (children gjso
7676
return children
7777
}
7878

79+
func bookmarkType(a int64) string {
80+
switch a {
81+
case 1:
82+
return "url"
83+
default:
84+
return "folder"
85+
}
86+
}
87+
7988
func (c *ChromiumBookmark) Name() string {
8089
return "bookmark"
8190
}
8291

92+
func (c *ChromiumBookmark) Length() int {
93+
return len(*c)
94+
}
95+
8396
type FirefoxBookmark []bookmark
8497

8598
const (
@@ -134,11 +147,6 @@ func (f *FirefoxBookmark) Name() string {
134147
return "bookmark"
135148
}
136149

137-
func bookmarkType(a int64) string {
138-
switch a {
139-
case 1:
140-
return "url"
141-
default:
142-
return "folder"
143-
}
150+
func (f *FirefoxBookmark) Length() int {
151+
return len(*f)
144152
}

internal/browingdata/browsingdata.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type Source interface {
2424
Parse(masterKey []byte) error
2525

2626
Name() string
27+
28+
Length() int
2729
}
2830

2931
func New(sources []item.Item) *Data {
@@ -47,6 +49,10 @@ func (d *Data) Output(dir, browserName, flag string) {
4749
output := NewOutPutter(flag)
4850

4951
for _, source := range d.sources {
52+
if source.Length() == 0 {
53+
// if the length of the export data is 0, then it is not necessary to output
54+
continue
55+
}
5056
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
5157

5258
f, err := output.CreateFile(dir, filename)

internal/browingdata/cookie/cookie.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ func (c *ChromiumCookie) Name() string {
9393
return "cookie"
9494
}
9595

96+
func (c *ChromiumCookie) Length() int {
97+
return len(*c)
98+
}
99+
96100
type FirefoxCookie []cookie
97101

98102
const (
@@ -137,3 +141,7 @@ func (f *FirefoxCookie) Parse(masterKey []byte) error {
137141
func (f *FirefoxCookie) Name() string {
138142
return "cookie"
139143
}
144+
145+
func (f *FirefoxCookie) Length() int {
146+
return len(*f)
147+
}

internal/browingdata/creditcard/creditcard.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (c *ChromiumCreditCard) Name() string {
7676
return "creditcard"
7777
}
7878

79+
func (c *ChromiumCreditCard) Length() int {
80+
return len(*c)
81+
}
82+
7983
type YandexCreditCard []card
8084

8185
func (c *YandexCreditCard) Parse(masterKey []byte) error {
@@ -127,3 +131,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
127131
func (c *YandexCreditCard) Name() string {
128132
return "creditcard"
129133
}
134+
135+
func (c *YandexCreditCard) Length() int {
136+
return len(*c)
137+
}

internal/browingdata/download/download.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func (c *ChromiumDownload) Name() string {
7070
return "download"
7171
}
7272

73+
func (c *ChromiumDownload) Length() int {
74+
return len(*c)
75+
}
76+
7377
type FirefoxDownload []download
7478

7579
const (
@@ -131,3 +135,7 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
131135
func (f *FirefoxDownload) Name() string {
132136
return "download"
133137
}
138+
139+
func (f *FirefoxDownload) Length() int {
140+
return len(*f)
141+
}

internal/browingdata/extension/extension.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (c *ChromiumExtension) Name() string {
5050
return "extension"
5151
}
5252

53+
func (c *ChromiumExtension) Length() int {
54+
return len(*c)
55+
}
56+
5357
type FirefoxExtension []*extension
5458

5559
func (f *FirefoxExtension) Parse(masterKey []byte) error {
@@ -73,3 +77,7 @@ func (f *FirefoxExtension) Parse(masterKey []byte) error {
7377
func (f *FirefoxExtension) Name() string {
7478
return "extension"
7579
}
80+
81+
func (f *FirefoxExtension) Length() int {
82+
return len(*f)
83+
}

internal/browingdata/history/history.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func (c *ChromiumHistory) Name() string {
6565
return "history"
6666
}
6767

68+
func (c *ChromiumHistory) Length() int {
69+
return len(*c)
70+
}
71+
6872
type FirefoxHistory []history
6973

7074
const (
@@ -119,3 +123,7 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
119123
func (f *FirefoxHistory) Name() string {
120124
return "history"
121125
}
126+
127+
func (f *FirefoxHistory) Length() int {
128+
return len(*f)
129+
}

internal/browingdata/localstorage/localstorage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (c *ChromiumLocalStorage) Name() string {
5858
return "localStorage"
5959
}
6060

61+
func (c *ChromiumLocalStorage) Length() int {
62+
return len(*c)
63+
}
64+
6165
func (s *storage) fillKey(b []byte) {
6266
keys := bytes.Split(b, []byte("\x00"))
6367
if len(keys) == 1 && bytes.HasPrefix(keys[0], []byte("META:")) {
@@ -142,3 +146,7 @@ func (s *storage) fillFirefox(originKey, key, value string) {
142146
func (f *FirefoxLocalStorage) Name() string {
143147
return "localStorage"
144148
}
149+
150+
func (f *FirefoxLocalStorage) Length() int {
151+
return len(*f)
152+
}

internal/browingdata/password/password.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func (c *ChromiumPassword) Name() string {
9090
return "password"
9191
}
9292

93+
func (c *ChromiumPassword) Length() int {
94+
return len(*c)
95+
}
96+
9397
type YandexPassword []loginData
9498

9599
const (
@@ -154,6 +158,10 @@ func (c *YandexPassword) Name() string {
154158
return "password"
155159
}
156160

161+
func (c *YandexPassword) Length() int {
162+
return len(*c)
163+
}
164+
157165
type FirefoxPassword []loginData
158166

159167
const (
@@ -224,10 +232,6 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
224232
return nil
225233
}
226234

227-
func (f *FirefoxPassword) Name() string {
228-
return "password"
229-
}
230-
231235
func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) {
232236
var keyDB *sql.DB
233237
keyDB, err = sql.Open("sqlite3", key4file)
@@ -278,3 +282,11 @@ func getFirefoxLoginData(loginJson string) (l []loginData, err error) {
278282
}
279283
return l, nil
280284
}
285+
286+
func (f *FirefoxPassword) Name() string {
287+
return "password"
288+
}
289+
290+
func (f *FirefoxPassword) Length() int {
291+
return len(*f)
292+
}

0 commit comments

Comments
 (0)