mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
410bffe643
* refactor: naming cleanup across all packages
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package chromium
|
|
|
|
import (
|
|
"os"
|
|
"sort"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/types"
|
|
)
|
|
|
|
func extractBookmarks(path string) ([]types.BookmarkEntry, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var bookmarks []types.BookmarkEntry
|
|
roots := gjson.GetBytes(data, "roots")
|
|
roots.ForEach(func(_, value gjson.Result) bool {
|
|
walkBookmarks(value, "", &bookmarks)
|
|
return true
|
|
})
|
|
|
|
sort.Slice(bookmarks, func(i, j int) bool {
|
|
return bookmarks[i].CreatedAt.After(bookmarks[j].CreatedAt)
|
|
})
|
|
return bookmarks, nil
|
|
}
|
|
|
|
// walkBookmarks recursively traverses the bookmark tree, collecting URL entries.
|
|
func walkBookmarks(node gjson.Result, folder string, out *[]types.BookmarkEntry) {
|
|
nodeType := node.Get("type").String()
|
|
if nodeType == "url" {
|
|
*out = append(*out, types.BookmarkEntry{
|
|
ID: node.Get("id").Int(),
|
|
Name: node.Get("name").String(),
|
|
Type: nodeType,
|
|
URL: node.Get("url").String(),
|
|
Folder: folder,
|
|
CreatedAt: timeEpoch(node.Get("date_added").Int()),
|
|
})
|
|
}
|
|
|
|
children := node.Get("children")
|
|
if !children.Exists() || !children.IsArray() {
|
|
return
|
|
}
|
|
currentFolder := node.Get("name").String()
|
|
for _, child := range children.Array() {
|
|
walkBookmarks(child, currentFolder, out)
|
|
}
|
|
}
|