mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Later layers speak categories and records, and export needs nothing else. Ordering rows once in the exporter fixes Firefox history, written least visited first.
45 lines
946 B
Go
45 lines
946 B
Go
package export
|
|
|
|
import (
|
|
"sort"
|
|
"time"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
)
|
|
|
|
// Stable, so ties and keyless categories keep source order; Safari's bookmarks and downloads have no timestamp to sort by.
|
|
func sortRecords(records []record.Record) {
|
|
sort.SliceStable(records, func(i, j int) bool {
|
|
return keyOf(records[i]).before(keyOf(records[j]))
|
|
})
|
|
}
|
|
|
|
type sortKey struct {
|
|
visits int
|
|
at time.Time
|
|
}
|
|
|
|
func keyOf(r record.Record) sortKey {
|
|
switch r := r.(type) {
|
|
case *record.Login:
|
|
return sortKey{at: r.CreatedAt}
|
|
case *record.Cookie:
|
|
return sortKey{at: r.CreatedAt}
|
|
case *record.Bookmark:
|
|
return sortKey{at: r.CreatedAt}
|
|
case *record.Download:
|
|
return sortKey{at: r.StartTime}
|
|
case *record.History:
|
|
return sortKey{visits: r.VisitCount}
|
|
default:
|
|
return sortKey{}
|
|
}
|
|
}
|
|
|
|
func (k sortKey) before(o sortKey) bool {
|
|
if k.visits != o.visits {
|
|
return k.visits > o.visits
|
|
}
|
|
return k.at.After(o.at)
|
|
}
|