-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathextract_bookmark.go
More file actions
55 lines (48 loc) · 1.37 KB
/
extract_bookmark.go
File metadata and controls
55 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package firefox
import (
"database/sql"
"sort"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
)
const (
firefoxBookmarkQuery = `SELECT id, url, type, dateAdded, COALESCE(title, '')
FROM (SELECT * FROM moz_bookmarks INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id)`
firefoxCountBookmarkQuery = `SELECT COUNT(*) FROM moz_bookmarks
INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id`
)
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
bookmarks, err := sqliteutil.QueryRows(path, true, firefoxBookmarkQuery,
func(rows *sql.Rows) (types.BookmarkEntry, error) {
var id, dateAdded int64
var url, title string
var bt int64
if err := rows.Scan(&id, &url, &bt, &dateAdded, &title); err != nil {
return types.BookmarkEntry{}, err
}
return types.BookmarkEntry{
Name: title,
URL: url,
Folder: bookmarkType(bt),
CreatedAt: firefoxMicros(dateAdded),
}, nil
})
if err != nil {
return nil, err
}
sort.Slice(bookmarks, func(i, j int) bool {
return bookmarks[i].CreatedAt.After(bookmarks[j].CreatedAt)
})
return bookmarks, nil
}
func bookmarkType(bt int64) string {
switch bt {
case 1:
return "url"
default:
return "folder"
}
}
func countBookmarks(path string) (int, error) {
return sqliteutil.CountRows(path, true, firefoxCountBookmarkQuery)
}